ESP8266 Thing Dev Board Tutorial
In this tutorial, you will set up an ESP8266 Thing Dev Board to act as a connected lightbulb. You will then create a development dashboard within Murano, where you can see temperature and humidity data from the device and have the ability to remotely turn the lightbulb on and off.
This example is based on the Murano HTTP Device API and we invite you to have a look to the reference page along with this guide.
Table of Contents
- Getting Started
- Next Step
To complete this tutorial, you will need the following hardware:
10K ohm resistor (for digital pin pull-up)
330 ohm resistor
LED (suggest green or yellow)
Micro-USB B cable
To begin, connect the components as shown in the image below.
To complete this tutorial, you will need to set up the Arduino IDE as well as the board support for the ESP8266.
New to Arduino? Below are a few links to get an understanding of Arduino since this tutorial does not cover every concept of the Arduino IDE and hardware (in this case, the SparkFun ESP8266 Thing Dev Board). Note that Arduino supports a number of hardware platforms, not just Arduino-branded boards themselves, like the ESP8266 Thing Dev Board.
Install tools and libraries:
1. Arduino IDE
First download and install the Arduino IDE from the Arduino website.
2. ESP8266 Board Support
Open the Arduino IDE, then install the ESP8266 Thing Dev Board support:
1. Select *Arduino* > *Preferences...*. 2. In the *Preferences* popup that appears, paste this link into the *Additional Boards Manager URLs* field: `http://arduino.esp8266.com/stable/package_esp8266com_index.json` ![image alt text](thingdev_1.png) 3. Click "OK."
3. Exosite Library
Install the Arduino library and DHT Sensor library:
1. Select *Sketch* > *Include Library* > *Manage Libraries...* ![image alt text](thingdev_2.png) 2. In the *Library Manager* popup that appears, search for "Exosite." 3. Select version **2.6.1** and click "Install." _(other versions are not designed to work with this Tutorial)_ ![image alt text](thingdev_3.png) 4. Search for "DHT". Install the DHT sensor library. ![image alt text](thingdev_4.png) 5. Search for "Adafruit Unified Sensor". When the list populates, scroll to the very bottom and find the library named **Adafruit Unified Sensor** and install version **1.0.2**. ![image alt text](thingdev_31.png) 6. When complete, click "Close."
Configure Murano IoT-Connector
We assume here you already have a Murano Iot-Connector created (if not, please go back and check the Cloud Setup).
In your web-browser, navigate to your IoT-Connector on the Murano 'Home' solution list page and click on it.
Navigate to the Resources tab and add following resources. From the Resources tab, add your new resources as specified below.
* alias: _temperature_, format: _number_ * alias: _humidity_, format: _number_ * alias: _uptime_, format: _number_ * alias: _state_, format: _number_
These are the resources your device will interact with. The device will write data to the temperature, humidity, and uptime aliases, while watching the state alias for changes.
For the state resource, enable the "Modifiable from the Cloud." options. This will allow you to send data to the device from the Murano UI.
Find out more about Resources here.
1. Navigate to the Settings tab 2. Under 'Protocol' select HTTP Device API 3. Under 'Provisioning'->'Authentication' select 'Token'" 4. Scroll Up and click SAVE
Find out more about Connectivity Settings here.
Flash and Run the Example Application
In this section, you will flash and run an example application for a connected lightbulb in Arduino.
In Arduino, create a new sketch by selecting File > New.
Load the Exosite connected lightbulb example sketch with device application code by selecting File > Examples > Exosite > Murano-SmartLightBulb-ThingDevBoard.
In your sketch, edit the Wi-Fi configuration parameters for your local Wi-Fi network (SSID and password) and the Murano Product ID parameters for your product.
To find your IoT-Connector Product ID:
In Murano, navigate to your Solution view and select the Product you just created.
At the top of the page, locate the ID button and click it to copy the Product ID to the clipboard.
Make sure the Thing Dev Board is connected to your computer via a micro-USB cable and select your device’s serial port with Tools > Port > "your_port".
NOTE: Your device will likely be the only one. If it is not, you can figure out which is correct by unplugging your device and finding which device disappears.
Click the arrow icon to upload. This will first compile and then download the firmware image to the selected board.
Open the Serial Monitor and set it to 115200 baud.
Locate the MAC Address in the serial monitor output; this will serve as the device identifier for the device under your Product in Murano. The device identifier or serial number is device-specific. In this situation, the Exosite Arduino library uses the device's pre-programmed MAC address. Also note that just below the MAC Address you should see a message indicating the device has been activated successfully, meaning the device can now be viewed in the Murano UI.
NOTE: Deselect the "Autoscroll" checkbox if the log window goes past the top.
View the Device in Murano
In this section, you will view a device under your Product in Murano.
In Murano, navigate to the SOLUTIONS tab and select the Product you just created.
Navigate to the Devices tab where you should see the newly created and activated device. The green checkmark indicates the product was activated using a secured connection.
Select your device and ensure that data is showing up.
Create a Dashboard
In this section, you will create a dashboard to view the data from the connected lightbulb and turn it on and off remotely.
From the device view, open the ACTIONS dropdown on the right-hand side and select "View dashboard".
Click "+ ADD PANE" to house the widgets you will create.
In the pane that appears, click the plus sign "+" to add a widget.
In the widget popup that appears, select "Text" from the TYPE drop-down menu and complete the remaining fields (TITLE: "Temperature"; VALUE: "resources["temperature"]"; UNITS: "F"). Click SAVE.
Create another pane and text widget for humidity and complete the remaining fields (TITLE: "Humidity"; VALUE: "resources["humidity"]"; UNITS: "%"). Click SAVE.
Add a third pane and widget. In the widget popup that appears, select "Toggle Switch" from the TYPE drop-down menu and complete the remaining fields (TITLE: "On / Off"; VALUE: "resources["state"]"; ON VALUE: "1"; OFF VALUE: "0"). Click SAVE.
Refresh your browser if you do not see data coming through in the Humidity and Temperature widgets. Now turn the light on and off using the toggle switch on your dashboard. You should see the LED turn on and off on the Thing Dev Board accordingly.
You can also verify that the state is changing via the Serial Monitor in the Arduino IDE.
Congratulations—you just remotely turned a light on and off.
Now that you have a basic understanding of Murano connectivity, you can get forward by: