• CONNECTING TO WEB SERVICES

    Learn to connect your ESPresso Lite V2 to external open web services

    ThingSpeak

    https://thingspeak.com

    A free web application that allow users to send and retrieve sensor data for logging and visualization purpose.

    Freeboard

    https://freeboard.io/

    A free web-service that allow users to create customized dashboards to visualize the sensor data sent to the cloud.

    IFTTT

    https://ifttt.com/

    A free web-service that allow users to connect other web-services together, triggered based on the conditional statement of “if this then that”

  • USING THINGSPEAK

    Data logging and visualization tool

    ThingSpeak is a free web application that allow users to send and retrieve sensor data for logging and visualization purpose.

    1. Set up the circuit

    Connect the DHT22 & OLED directly

    The ESPresso Lite V2 is specially designed to accomodate the pins of the DHT22 digital humidity & temperature sensor and the OLED 128x64C directly without the need of jumper wires.

     

    (The illustration on the left is used to indicate the layout of the jumper wires in event breadboard is used.)

    2. Create new ThingSpeak account

    3. Create a new channel

    • Click on New Channel and enter the necessary information about this channel e.g. Name, Description, Fields etc
    • For this tutorial, enter Temperature in the box and select Field 1 and Humidity for Field 2

    4. Get the channel API key

    • Click on the API Keys tab and copy the key under the section Write API Key
    • The format of the API Keys are something like

    Pxxxxxxxxxxxxx2

     

    • If you feel your API key has been compromised, click Generate New Write API Key to create a new key.​
    • For your information, the API keys enable you to write data to a channel or read data from a private channel. API keys are auto-generated when you create a new channel.

    5. Upload the Arduino sketch to the ESPresso Lite V2

    Run the Arduino IDE (latest version 1.6.9) and use the following example sketch (authored by Shahrulnizam). Change the API Key in the sketch to the Write API key indicated in your ThingSpeak channel.

    6. Connect to the Internet

    • Once the sketch is successfully uploaded to the ESPresso Lite V2, connect the board to the Internet.
    • Refer to the section Connect to Internet for more information (http://www.espressolite.com/connect-to-internet)
    • The board will reboot and the OLED will display the temperature and humidity data every 8 seconds. (See image on the left).

    7. Visualize the DHT22 data

    At the Channels section, click on the Private View tab to display the temperature and humidity charts.

  • USING FREEBOARD

    We will be using Freeboard as our data visualization service

    If you are already subscribed to the MQTT broker, you will receive JSON messages at specific intervals. Unfortunately we cannot easily make sense of the JSON data without visualizing it. As such, Freeboard allows us convert the JSON information into 2-D graphics for the purpose of visualization.

    1. Using DHT22 sensor

    By default, the V2.0 out of the box is already pre-loaded with the workshop sketch that also controls the DHT22 digital temperature and humidity sensors.

    2. Let's visualize temperature from our sensor

    Assuming you have DHT22 connected into the V2.0 board:

     

    At Datasources, click on Add

    3. Select type of data source

    Select the type of datasource as Paho MQTT.

    4. Fill in the following details

    Key in the following details:

    • Name: <something>
    • MQTT Server: mqtt.espert.io
    • Port: 8000
    • Use SSL: No
    • Client Id: <copy from MQTT Websocket panel>
    • Topic: ESPert/xxxxxxxx/Status
    • JSON Message?: Yes

     

    Make sure xxxxx is replaced with your own board id.

    5. Making a temperature gauge

    • Click Add Pane > + (add widget) > Gauge and key in ‘Temperature’.
    • Set the units as ‘C’ and min and max units as ‘0’ and ‘100’ respectively
    • Click Datasource > Espert (name of datasource) > msg > temperature

    6. Complete it.

    • Once this is completed, a temperature gauge will be displayed.

    If you want to publish the Freeboard panel to a website, save the panel under <name>.json.

    Go to http://www.espert.io

    Create a new object

    Click on the GREEN square to add new object

    Create a new object under My Freeboard > (add object-click on the green square at the upper left corner)

    Enter the name of the object and the corresponding <name>. JSON file and Save it.

    Get the Freeboard key

    Click on the BLUE icon to create object

    Click on the blue icon and copy the URL display in the browser.

     

    The format of the URL looks like:

    http://www.espert.io/freeboard/index.html#key=xxxxxxxxxxx

     

    In your website, embed this URL in iFrame:

     

    <iframe src="http://www.espert.io/freeboard/index.html#key=xxxxxxxxxxx" width="800" height="600" align="top">

    </iframe>

    Example of a live dashboard show below

  • Using IFTTT

    Conditional programming with IFTTT web service

    IFTTT or “If This Then That” is a free web-service that allow users to connect other web-services together, triggered based on the conditional statement of “if this then that”. IFTTT can help novice IoT learner to create simple a IoT service as you can turn everyday things into ‘smart’ objects by setting up its relationship using simple logic such as “if the room is too hot, then turn on the air-conditioning”.

     

    In this case, you can create your own 'hot' button service where if you press a button (GPIO0), then it will trigger a push short text notification to your smartphone.

    1. Create a 'hot' button service

    If button GPIO0 is pressed, then a text notification is triggered and sent to smartphone

    2. Create IFTTT account

    Begin by creating an IFTTT account at http://ifttt.com

    3. Create an applet*

    *previously known as 'recipe'

    Create an applet (or recipe) by selecting a channel for the trigger. You will be using the Maker channel.

     

    Connect to the Maker channel and find out what is the key (auto-generated) for you.

     

    Copy this key (Ctrl-C) as we will need to use this later.

    4. Go to MQTT web socket panel

    At the message box of the MQTT panel, publish the JSON format of the IFTTT key to the MQTT broker:

     

    {"IFTTT" : "XXXIFTTXXXXXX"}

     

    where xxxIFTTxxxxx is the IFTTT key assigned to your channel.

     

    This step essentially hardcodes the IFTTT key into the V2.0 to prevent third-party abuse of the key. As such it will recognise subsequent 'button' message and return the trigger event. The device will retain the information even after it has been switched off.

    5. Check the OLED display

    If the IFTTT key is successfully published, the OLED will display the message, "PARSE OK".

     

    If not, it will display, "PARSE FAIL"

    6. Choose trigger service for 'THIS'

    Firstly make sure that you have obtained the IFTTT channel key and publish the key via the MQTT web socket panel at http://www.espert.io/mqtt

     

    Once these prior setup is done, you can start creating your own button recipe.

     

    Choose Maker as the trigger service.Click on Receive a web request.

    7. Choose a trigger

    Click on Receive a web request.

    8. Complete trigger fields

    Name the Event Name as 'button'*.

     

    *Any other name may not work for this example

    9.Choose action service for 'THAT'

    Select and choose maker

    10. Choose an action

    Click on Make a web request.

    11. Get ready your smartphone key

    Your smartphone key is a series of numbers generated randomly by espert.io (check out the URL panel) when you have complete the user registration with the mobile app.

     

    For more information about obtaining the smartphone key, refer to instructions to 'Create a Cloud account' here.

    12. Complete action fields

    In the URL box, key in the HTTP-MQTT bridge using the format:

     

    http://www.espert.io/MySmartphone/send?key=xxxxxxx&message=yyyyyyyy

     

    where xxxxxx is the smartphone key and yyyyy is the message you want to trigger.

     

    In this example, we use the message

    "This is triggered by IFTT"

     

    For Method, select GET or POST from the drop-down menu.

     

    Leave the Content Type and Body empty.

     

    Click 'Create Action'.

    13. Test it out.

    Proceed to test out your first IoT service.

     

    Press the button GPIO0 firmly (hold for at least 1 sec)

      14. Check the OLED display

      When the user button GPIO0 is pressed, the screen will show 'Requesting...'

       

      If the IFTTT trigger is successfully fired, it will show the message, "Congratulations! You've fired the button event".

      15. Check your smartphone

      When you open your ESPert IoT Mobile App , you will be able to see the message and its timestamp.

      If it works, congratulations!

       

      If it doesn’t, continue to troubleshoot and identify the steps you may have missed out:

      • Are your board and/or smartphone connected to the Internet?
      • Have you created a cloud account at espert.io ?
      • Have you installed the app and tried sending push notification to yourself?
      • Have you connected or subscribed to the MQTT broker?
      • Did you use or key in your own board id instead of the one shown in the examples?
      • Did you use your own IFTTT channel key instead of the one shown in the examples?