- Silicon Labs Community
- Welcome and Announcements
- Silicon Labs Knowledge Base
- 8-bit MCU
- 32-bit MCU
- Bluetooth / Wi-Fi
- Other Products Category
- Optical/RH/Temp Sensor
- Other Products
- Hardware and Software Tools
- Simplicity Studio and Software
- General Discussions and Suggestions
- Chinese Forum
- Software Libraries
- Development Kits
- Reference Designs
- Third Party Tools
- White Papers
- Official Blog of Silicon Labs
- Chinese Blog
07-13-2016 08:30 AM
This project is a follow up of the IFTTT article which instructed how to setup an IFTTT recipe and add a row to a google docs spreadsheet by sending an HTTP POST request from the Wizard Gecko WGM110 Wi-Fi Module.
On that example there was no additional data being sent on the HTTP request but on this project we will go one step further and add a JSON body to the request containing temperature and humidity data.
The temperature and humidity data are read from the Si7021 temperature and humidity sensor on-board the WSTK through I2C. The request is sent by pushing PB0 on the WSTK.
Please refer to IFTTT article mentioned in the introduction to learn how to create a recipe. To run this example you have to create a recipe and select the Twitter channel for "this" (don't forget to connect Twitter to your IFTTT account first) and then select chose "Post a tweet" as the action. You are free to write any text for the tweet and that includes adding up to 3 values which can be sent in the HTTP request.
For this project we created a Wizard Gecko Twitter account and using the recipe below the module is tweeting the temperature and humidity of our office in Espoo, Finland.
Adding the JSON body
For adding the data in JSON format we based on the implementation from the 'sensor' example of the WGM110 SDK.
# Procedure for creating the JSON data body export procedure build_response_data() # Generate a response request_data_len = 0 call api_add_json_object_start() # Temperature name call api_add_json_object_name(API_PARAM_JSON_TEMPERATUR
E_LEN, API_PARAM_JSON_TEMPERATURE(:)) # Temperature value call api_add_json_integer(i2c_temperature) # adding a comma between JSON object element call api_add_comma() # Humidity name call api_add_json_object_name(API_PARAM_JSON_HUMIDITY_L EN, API_PARAM_JSON_HUMIDITY(:)) # Humidity value call api_add_json_integer(i2c_humidity) # JSON status object end call api_add_json_object_end() call api_add_crlf() call api_add_crlf() end
The full HTTP request is bellow where 'tt' and 'hh' are the temperature and humidity values respectively.
POST /trigger/YOUR_EVENT/with/key/YOUR_KEY HTTP/1.1\r\n
Press PB0 -> LED1 goes on -> LED1 goes off -> Tweet