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.

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.6.1 and click "Install." (other versions are not designed to work with this Tutorial)

      image alt text

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

      image alt text

    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

    6. When complete, click "Close."

Getting Started

Create a Product in Murano

In this section, you will create a new Product in Murano using the Exosite Exchange.

  1. In Murano, navigate to the EXCHANGE tab, or click SHOP EXCHANGE.

    image alt text

  2. Scroll down until you find the "Connected Lightbulb Quickstart" Exchange Element and click on it.

    image alt text

  3. In the upper right-hand section of the page, click on ADD PRODUCT. This will add the Element to your toolbox. To create a new product using this Element, click on CREATE PRODUCT.

    image alt text

  4. In the Create New Solution popup, enter a name for the Product in the Product Name field and click ADD.

    image alt text

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

    image alt text

  6. 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 create the Product using the Exchange Element template, 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. When choosing how your devices communicate with the platform, make sure "HTTPS Device API" is selected. For the "AUTHENTICATION METHOD", select "Token".

      image alt text

    2. Scroll down and click SAVE, 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 ID button and click it to copy the Product ID to the clipboard.

      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. The green checkmark indicates the product was activated using a secured connection.

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