Project tutorial
Mozilla IoT WoT Gateway and ESP8266

Mozilla IoT WoT Gateway and ESP8266 © CC BY-SA

Internet of Things for all! Mozilla WoT gateway based on Raspberry Pi and ESP8266 powered. Try to create your own gateway and device!

  • 833 views
  • 0 comments
  • 5 respects

Components and supplies

Apps and online services

About this project

Power to the Peoples! Mozilla wants do free the IoT protocol

The scope of this project is to “ensure the Internet is a global public resource, open and accessible to all.” The Internet of Things (IoT) is a new era of the Internet. And like the Internet, Mozilla imagines a free protocol for all. Cross-platform, cross country, cross brand.

The Hardware

For this project you must have:

1 X Raspberry Pi 3 (https://amzn.to/2DmQ8eB)

2 X ESP8266 (https://amzn.to/2AUvC3c)

Optional

1 X Z-Wave dongle adapter (https://amzn.to/2HxZokm)

ESP8266-01 Relay board (https://amzn.to/2Ufx7Ao)

Optional for Raspberry Pi setup

Mouse

Keyboard

HDMI Monitor

The Software

For this project you must have:

Arduino IDE or Arduino Create (https://create.arduino.cc)

Mozilla Gateway for Raspberry 3

All the Mozilla Gateway libraries

How IoT works today

Today we have a lot of components inside the iot communication. You should have, for example, an Amazon Alexa gateway and a lot of devices connected with that. But with Mozilla Gateway you can use the same gateway to use Alexa, Google home kit, simple ESP8266 or anything devices you want to "smartifing" your home.

How Mozilla imagine the future

The Mozilla Project is an experimental framework with 3 components:

Things GatewayAn implementation of a Web of Things gateway.

Things CloudA collection of IoT cloud services.

Things FrameworkA collection of re-usable software components for building Web Things.

The Raspberry Pi Gateway

The core of all the project is a Raspberry Pi 3 Gateway by Mozilla.

It's a really simple step. Mozilla has prepared a Linux distro that install the system on the Raspberry Pi. You can setup the gateway by using your smartphone.

1. Flash SD Card

Download the pre-built Raspberry Pi OS image from Mozilla and flash it onto an SD card. Download from THIS LINK the Mozilla Gateway distro.

You can use the Raspberry Pi official guide to install the Mozilla Gateway on the SD.

Another possibility is Balena Etcher (https://www.balena.io/etcher/).

Balena Ethcer is a program for Windows Mac and Linux that copy an ISO image on the SD.

2. Start you Gateway

Now you can start your Mozilla Gateway. After that, you can connect your phone with the gateway by using the Wifi from Raspberry Pi.

Connect your gateway to your wifi network

After that you must create a tunnel to the Mozilla cloud system. After that you can see your gateway even out from your Local Area Network.

After this step you receive an email with your Mozilla credential. You must compile the module and...that's it!

3. Add devices

Now you can add some devices. You can use Zigbee dongle to connect Zigbee devices, or z-wave dongle for z-wave devices.

4. Arduino devices

My solution is able to use Arduino compatible devices. I use 2 NODE ESP8266. One of that is used as a receiver. You can connect the board to a relay and command a light for example. The other is an ESP8266 that collect the data from a sensor and send the value to the Gateway. In this, code (https://github.com/masteruan/webthing-arduino/tree/master/examples/esp8266Sensor) I've created a debug test. The ESP8266 send a random number every 3 seconds to the Gateway dashboard.

NodeESP8266 led

This is the link on Github code (https://github.com/masteruan/webthing-arduino/tree/master/examples/LED).

Download the code and put on the Node ESP8266 board.

ESP8266 + Relay shield

I've used also this kind of board. A ESP8266 + relay. You can see my code on Github. You must only charge the firmware on the ESP8266 board and also you can command a relay that works clearly with Mozilla WoT Gateway.

When you add the device you can use like a led device. If you send from Mozilla Gateway "on" command the ESP send by the serial port command to the relay shield a serial command to switch on the relay, otherwise the ESP8266 send to the board a switch off command for the relay.

This is the link on Github code (https://github.com/masteruan/webthing-arduino/tree/master/examples/relayEsp8266)

NodeESP8266 sensor

You can see the code for the Node ESP8266 sensor.

This is the link on Github code (https://github.com/masteruan/webthing-arduino/tree/master/examples/sensorNodeMCU)

You must include some libraries for ESP LED and ESP sensor.

#include <Arduino.h>
#include <stdio.h>
#include "Thing.h"
#include "WebThingAdapter.h"

Also for ESP8266-01 Relay you must include

#include <ESP8266WiFi.h>
#include "SoftwareSerial.h" 

With this code you setup your local network SSID and password. After you create a new ThigDevice instance.

const char* ssid = "xxx";
const char* password = "";
WebThingAdapter* adapter;
const char* deviceTypes[] = {"MultiLevelSensor", "Sensor", nullptr};
ThingDevice device("SensDevice", "Analog Sensor pluged in single pin", deviceTypes);
ThingProperty property("level", "Analog Input pin", NUMBER, "LevelProperty");

With this code you connect the board to the wifi network.

#if defined(ESP8266) || defined(ESP32)
 WiFi.mode(WIFI_STA);
#endif
 WiFi.begin(ssid, password);
 Serial.println("");
 // Wait for connection
 bool blink = true;
 while (WiFi.status() != WL_CONNECTED) {
   delay(500);
   Serial.print(".");
   digitalWrite(ledPin, blink ? LOW : HIGH); // active low led
   blink = !blink;
 }
 /*IPAddress ip = Ethernet.localIP();
 Serial.print("log: IP=");
 Serial.println(ip);
 delay(3000);*/
 Serial.println("");
 Serial.print("Connected to ");
 Serial.println(ssid);
 Serial.print("IP address: ");
 Serial.println(WiFi.localIP());
 adapter = new WebThingAdapter("w25", WiFi.localIP());
 adapter = new WebThingAdapter("analog-sensor", WiFi.localIP());
 device.addProperty(&property);
 adapter->addDevice(&device);
 Serial.println("Starting HTTP server");
 adapter->begin();
 Serial.print("http://");
 Serial.print(WiFi.localIP());
 Serial.print("/things/");
 Serial.println(device.id);
}

With this code you send a random number to the gateway every 3 seconds

countator++;
 if (countator >= 3000){
   countator = 0;  
   ThingPropertyValue levelValue;
   levelValue.number = random(0,100);
   property.setValue(levelValue);
   adapter->update();
 }

Test the gateway

Now you can test your gateway. Try to connect to the dashboard and switch on/off the Node ESP8266.

Code

IoT Mozilla Gateway for ESP8266 Arduino IDE

Comments

Similar projects you might like

How To Use TheAmplituhedron.com To Improve IoT Projects

Project tutorial by Kutluhan Aktar

  • 1,343 views
  • 0 comments
  • 9 respects

IoT Blink - Getting started with IoT

Project showcase by AppShed Support

  • 2,463 views
  • 1 comment
  • 16 respects

KatLight - The Coolest IoT Wonderlamp

Project tutorial by remnis

  • 2,772 views
  • 4 comments
  • 11 respects

IoT Thermometer Using Python

Project tutorial by Luigi Francesco Cerfeda

  • 7,976 views
  • 4 comments
  • 22 respects

OH HAI! on Windows 10 IoT Core

Project in progress by BuddyC

  • 12,976 views
  • 3 comments
  • 48 respects

IoT arduino ESP Garage Door opener (UD)

Project in progress by David Smerkous

  • 11,593 views
  • 6 comments
  • 17 respects
Add projectSign up / Login