1
Dependencies: EthernetInterface IFTTT mbed-rtos mbed
Fork of IFTTT_Ethernet_Example by
Diff: main.cpp
- Revision:
- 1:3010b44f07ff
- Parent:
- 0:0f0676c43e4b
- Child:
- 2:6ef0af7c37d6
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) { } }