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.

Requirements

Hardware Setup

To complete this tutorial, you will need the following hardware:

To begin, connect the components as shown in the image below.

image alt text

Software Setup

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. First download and install the Arduino IDE from the Arduino website.

  2. Open the Arduino IDE, then install the ESP8266 Thing Dev Board 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

    3. Click "OK."

  3. Install the Exosite Arduino library and DHT Sensor library:

    1. Select Sketch > Include Library > Manage Libraries...

      image alt text

    2. In the Library Manager popup that appears, search for "Exosite."

    3. Select version 2.5.2 and click "Install."

      image alt text

    4. Search for "DHT". Install the DHT sensor library.

      image alt text

    5. When complete, click "Close."

Getting Started

Create a Product in Murano

In this section, you will create a new Product in Murano.

  1. In Murano, navigate to the Solutions tab.

  2. To add a Product, click "NEW SOLUTION".

    image alt text

  3. In the New Solution popup:

    1. Enter a name for the Product in the Product Name field.

    2. 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.

    3. Click "ADD."

    image alt text

  4. Once the Product has been created, select it.

    image alt text

  1. 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.

image alt text

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_
  1. Navigate to the SETTINGS tab.

    1. 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.

      image alt text

    2. 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.

  1. In Arduino, create a new sketch by selecting File > New.

  2. Load the Exosite connected lightbulb example sketch with device application code by selecting File > Examples > Exosite > Murano-SmartLightBulb-ThingDevBoard.

    image alt text

  3. 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.

    image alt text

  4. To find your Product ID:

    1. In Murano, navigate to your Solution view and select the Product you just created.

    2. At the top of the page, locate the Product ID and copy it.

      image alt text

  5. 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".

    image alt text

    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.

  6. Click the arrow icon to upload. This will first compile and then download the firmware image to the selected board.

    image alt text

  7. Open the Serial Monitor and set it to 115200 baud.

    image alt text

  8. 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.

    image alt text

    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.

  1. In Murano, navigate to the Solutions tab and select the Product you just created.

  2. Navigate to the DEVICES tab where you should see the newly created and activated device.

    image alt text

  3. Select your device and ensure that data is showing up.

    image alt text

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.

  1. From the device view, open the ACTIONS dropdown on the right-hand side and select "View dashboard".

    image alt text

  2. Click "ADD PANE" to house the widgets you will create.

    image alt text

  3. In the pane that appears, click the plus sign "+" to add a widget.

    image alt text

  4. 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."

    image alt text

  5. Create another pane and text widget for humidity and complete the remaining fields (TITLE: "Humidity"; VALUE: "resources["humidity"]"; UNITS: "%"). Click "SAVE."

    image alt text

  6. 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."

    image alt text

  7. 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.

    image alt text

    You can also verify that the state is changing via the Serial Monitor in the Arduino IDE.

    image alt text

Congratulations—you just remotely turned a light on and off.

UP NEXT: CREATE AN APPLICATION >>