Connected Lightbulb Using an 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.
NOTE: The ESP8266 Thing Dev Board has a known issue when using Arduino on a Windows machine. Please make sure digital pin 0 is grounded, or use a Linux machine to complete this tutorial.
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:
First download and install the Arduino IDE from the Arduino website.
Open the Arduino IDE, then install the ESP8266 Thing Dev Board board support:
Select Arduino > Preferences....
In the Preferences popup that appears, paste this link into the Additional Boards Manager URLs field:
Install the Exosite Arduino library and DHT Sensor library:
Select Sketch > Include Library > Manage Libraries...
In the Library Manager popup that appears, search for "Exosite."
Select version 2.5.2 and click "Install."
Search for "DHT". Install the DHT sensor library.
When complete, click "Close."
Create a Product in Murano
In this section, you will create a new Product in Murano.
In Murano, navigate to the Solutions tab.
To add a Product, click "NEW SOLUTION".
In the New Solution popup:
Enter a name for the Product in the Product Name field.
Select Smart Lightbulb Example in the Choose starting point drop-down menu.
This will allow you to use a product template spec file to set up the product definition.
Once the Product has been created, select it.
- Navigate to the RESOURCES tab.
These are the resources your device will interact with. They were created automatically from the product template you selected in the previous step. In this example, the device will generally write data to the temperature, humidity, and uptime aliases, while watching the state alias for changes.
NOTE: If you did not use the template URL in the previous step, you can manually configure your product definition. From the RESOURCES tab, add your new resources as specified below. Ensure that state has been configured to be "Modifiable from the Cloud." This will allow you to control this resource from sources other than the device itself—from the UI for example.
* alias: _temperature_, format: _number_ * alias: _humidity_, format: _number_ * alias: _uptime_, format: _number_ * alias: _state_, format: _number_
Navigate to the SETTINGS tab.
Select the checkbox to Allow development devices to connect.
This is necessary because the ESP8266 uses unsecured HTTP connections to communicate with Murano over a unique path. While HTTPS connections are opened with 'PID'.m2.exosite.io, HTTP connections are opened with 'PID'.devmode-m2.exosite.io. You can see this reflected in the domain used in the Arduino Application code.
Scroll down to SAVE the new settings.
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 Product ID:
In Murano, navigate to your Solution view and select the Product you just created.
At the top of the page, locate the Product ID and copy it.
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.
Select your device and ensure that data is showing up.
Create a Dashboard in Murano
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.