Interface with the If This Then That (IFTTT). This example uses both POST and GET to interface with IFTTT. Up to 3 values can be sent along with the trigger event name.
Dependencies: EthernetInterface IFTTT mbed-rtos mbed
What Is This
This is an example program for using the If This Then That (IFTTT) Maker Channel Service. For more information please see https:developer.mbed.org/components/If-This-Then-That-IFTTT/
How Does It Work
There are two ways to use the channel, you can send either POST or GET requests with up to 3 values per request. Note that the values must have the names "value1", "value2", and "value3", if you call them anything else they will be ignored.
IFTTT
You will need an IFTTT account and enable the maker channel. Once you have registered for this channel you will get a channel key and will be able to register event trigger names.
GET
The GET requests pass the variables through query parameters.
?value1=some&value2=random&vlaue3=values
POST
The POST request will pass the variables through a JSON formatted form.
How To Use It
Register for an IFTTT Account, add the maker channel, add a trigger to the maker channel. Fill in the event name and the key fields in your code with the keys from the ifttt account. Create a recipe that uses the events as triggers, compile the code, load and run it. Now you should be able to trigger a recipe from your mbed device!!!
This is an example of how to use the If This Then That Maker Channel service. There are two ways to access the service, one via a GET request and the other via a POST request. You can send up to 3 variables with each interaction. These variables must be names variable1, variable2, variable 3. The GET requests will send the varaibles in the query string, so it looks like "?variable1=somevalue&variable2=somevalue&variable3=somevalue" . The POST request will send the values in a JSON formatted form request.
// Initialize ifttt object, add up to 3 optional values, trigger event. IFTTT ifttt("YourEventName","ChangeToYourSecretKey", &socket); // EventName, Secret Key, socket to use ifttt.addIngredients("this is awesome","test-ing","data!!!"); // 3 optional Values to send along with trigger. ifttt.trigger();
You can find the IFTTT recipe here.
Revision 1:3010b44f07ff, committed 2015-07-13
- Comitter:
- mbedAustin
- Date:
- Mon Jul 13 18:50:53 2015 +0000
- Parent:
- 0:0f0676c43e4b
- Commit message:
- Changed to use IFTTT library instead of http library.
Changed in this revision
diff -r 0f0676c43e4b -r 3010b44f07ff HTTPClient-SSL.lib --- a/HTTPClient-SSL.lib Sun Jun 28 03:41:06 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/users/ansond/code/HTTPClient-SSL/#a18a06b000f3
diff -r 0f0676c43e4b -r 3010b44f07ff IFTTT.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IFTTT.lib Mon Jul 13 18:50:53 2015 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/mbedAustin/code/IFTTT/#c916e13a269a
diff -r 0f0676c43e4b -r 3010b44f07ff main.cpp --- a/main.cpp Sun Jun 28 03:41:06 2015 +0000 +++ b/main.cpp Mon Jul 13 18:50:53 2015 +0000 @@ -1,60 +1,33 @@ #include "mbed.h" #include "EthernetInterface.h" -#include "HTTPClient.h" - +#include "TCPSocketConnection.h" +#include "ifttt.h" + EthernetInterface eth; -HTTPClient http; -char str[512] = {}; -char json[125] = {}; -char eventName[] = "helloworld"; -char key[] = "ChangeThisToTheKeyProvidedByIFTTonTheMakerChannel"; -char value1[] = {"A"}, value2[] = {"B"}, value3[] = {"C"}; +RawSerial pc(USBTX, USBRX); // tx, rx -int main() +int main() { + pc.baud(9600); eth.init(); //Use DHCP eth.connect(); printf("IP Address is %s \n\r", eth.getIPAddress()); - - //GET - printf("GETing data... \n\r"); - sprintf(str, "https://maker.ifttt.com/trigger/%s/with/key/%s?value1=%s&value2=%s&value3=%s",eventName,key,value1,value2,value3); - printf("String is : %s\n\r",str); - int ret = http.get(str, str, 128); - if (!ret) - { - printf("Page fetched successfully - read %d characters\n\r", strlen(str)); - printf("Result: %s\n", str); - } - else - { - printf("Error - ret = %d - HTTP return code = %d \n\r", ret, http.getHTTPResponseCode()); - } - - //POST - HTTPMap map; - HTTPText inText(str, 512); - map.put("value1", value1); - map.put("value2", value2); - map.put("value3", value3); - sprintf(str, "https://maker.ifttt.com/trigger/%s/with/key/%s",eventName,key); - printf("String is : %s\n\r",str); - printf("POSTing data ....\n\r"); - ret = http.post(str, map, &inText); - if (!ret) - { - printf("Executed POST successfully - read %d characters \n\r", strlen(str)); - printf("Result: %s \n\r", str); - } - else - { - printf("Error - ret = %d - HTTP return code = %d \n\r", ret, http.getHTTPResponseCode()); - } - - - - eth.disconnect(); - + TCPSocketConnection socket; + + // Initialize ifttt object, add up to 3 optional values, trigger event. + IFTTT ifttt("YourEventName","ChangeToYourSecretKey", &socket); // EventName, Secret Key, socket to use + ifttt.addIngredients("this is awesome","test-ing","data!!!"); // 3 optional Values to send along with trigger. + ifttt.trigger(); + + // Send data using GET + ifttt.addIngredients("Sending","GET","data"); + ifttt.trigger(IFTTT_GET); + + // Send Data using POST + ifttt.addIngredients("Sending","POST","things"); + ifttt.trigger(IFTTT_POST); + + eth.disconnect(); while(1) { } }