IoT-Bus Mozilla IoT Examples¶
These examples are designed to run on IoT-Bus boards by oddWires. In each case, they demonstrate how to create a mozilla-iot “thing” and expose it through the mozilla-iot gateway running on a raspberry pi on the same Wi-Fi network. We will refer to a mozilla-iot thing as a Thing in this document. To setup a gateway see this link. You can find the examples on GitHub at IoT-Bus. There are two repositories:
- Examples in PlatformIo format. A platformio.ini file is included with library dependencies.
- Examples in ino format. You will need to install required libraries separately.
In each example you will have to enter your ssid and password within the main cpp file otherwise you will not reach the gateway. You can find the code for all the examples on github here.
//TODO: Hardcode your wifi credentials here (and keep it private) const char* ssid = "........"; const char* password = "........";
The typical platformio.ini for mozilla-iot contains:
[env:iotbusio] platform = espressif32 board = iotbusio framework = arduino ; Serial Monitor options monitor_speed = 115200 ; Library dependencies lib_deps = ArduinoJson https://github.com/me-no-dev/ESPAsyncWebServer https://github.com/mozilla-iot/webthing-arduino
If you are using a display, this would be the platformio.ini required:
[env:iotbusio] platform = espressif32 board = iotbusio framework = arduino ; Serial Monitor options monitor_speed = 115200 ; Library dependencies inclduing tft and touchscreen lib_deps = ArduinoJson https://github.com/me-no-dev/ESPAsyncWebServer https://github.com/mozilla-iot/webthing-arduino https://github.com/iot-bus/XPT2046_Touchscreen https://github.com/iot-bus/TFT_eSPI
Of course if you are using other libraries for sensors or your own, you can include them here and PlatformIO will locate and install them.
- LED Thing
- This example creates a Thing that enables the built-in LED on GPIO5 to be set through the mozilla-iot domain.
- LED Lamp Thing
- This example creates a Thing that enables the status and brightness of the built-in LED on GPIO5 to be set through the mozilla-iot domain.
- DHT11 Thing
This example creates a Thing that exposes temperature and humidity properties and also displays the temperature locally.
Connect a DHT11 Temperature Sensor and run:
DATA -> GPIO4 VCC -> VUSB (VIN is OK if using battery(3.7-42V) but not 3V3 as not high enough) GND -> GND
- HC-SR04 Thing
This example creates a Thing that exposes the current distance reading or the HC-SR04 ultrasonic distance sensor and also displays the distance locally.
Connect an HC-SR04 Ultrasonic Distance Sensor and run:
TRIG -> GPIO2 ECHO -> GPIO4 VCC -> VUSB GND -> GND (VIN is OK if using battery(3.7-42V) but not 3V3 as not high enough)
- HC-SR501 PIR Thing
This example creates a motion sensor Thing that triggers on movement. It sets the on-board LED on triggering and updates the mozilla-iot interface appropriately. Connect an HC-SR501 Passive Infrared Sensor or any similar device and run:
OUT -> GPIO4 VCC -> VUSB (Typically VIN is OK if using battery(3.7-42V) but not 3V3 as not high enough) GND -> GND
- Touch Thing
This example creates a touch switch Thing that triggers when one of the capacitive touch pins on the ESP32 are touched. It sets the on-board LED on triggering and updates the mozilla-iot interface appropriately.
Connect a wire to GPIO4 and run.
- Calculator Thing
- This example is a simple integer calculator that creates a Thing that exposes the two numbers, the last function and the result. It requires the IoT-Bus display.
- Door Sensor Thing
- This example shows how to use a typical magnetic door sensor. Just connect one side of the contacts to GPIO4 and the other to GND. When the contacts are open the door sensor will show open in the mozilla interface and when they are shut the door will show shut.
- Relay Thing
- This example uses an IoT-Bus relay board together with an IoT-Bus Io processor to expose the relay status and to enable the user to change through your mozilla-iot domain.
- Relay Display & Touch Switch Thing
- In this second relay example the current status of the relay is also shown on the display. The touchscreen is enabled so it can be switched on and off locally. The status will be reflected by mozilla-iot.