CONNECTING TO WEB SERVICES
Learn to connect your ESPresso Lite V2 to external open web services
A free web application that allow users to send and retrieve sensor data for logging and visualization purpose.
A free web-service that allow users to create customized dashboards to visualize the sensor data sent to the cloud.
A free web-service that allow users to connect other web-services together, triggered based on the conditional statement of “if this then that”
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.)
3. Create a new channel
4. Get the channel API key
5. Upload the Arduino sketch to the ESPresso Lite V2
6. Connect to the Internet
7. Visualize the DHT22 data
At the Channels section, click on the Private View tab to display the temperature and humidity charts.
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.
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:
Make sure xxxxx is replaced with your own board id.
5. Making a temperature gauge
6. Complete it.
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:
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">
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 IoT service e.g. using your voice to control actuators (e.g. LEDs or servo).
2. Create IFTTT account
Begin by creating an IFTTT account at http://ifttt.com
3. Create a new applet*
*previously known as 'recipe'
Create an applet (or recipe) by selecting a channel for the trigger. You can choose either "Google Assistant" or "Alexa" channel.
4. Complete trigger fields
In this example, we will use 'Google Assistant' as the trigger.
Just complete the fields indicating:
5. Choose 'Webhooks' as 'that' trigger
6. Make a web request
7. Indicate the URL for 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
Go to http://espert.io
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:
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: