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:   ESP8266Interface IFTTT mbed

Fork of IFTTT_Ethernet_Example by Austin Blackstone

Files at this revision

API Documentation at this revision

Comitter:
mbedAustin
Date:
Mon Jul 13 17:55:59 2015 +0000
Parent:
0:0f0676c43e4b
Child:
2:7677729fe02d
Commit message:
Initial Example for If This Then That with ESP8266

Changed in this revision

ESP8266Interface.lib Show annotated file Show diff for this revision Revisions of this file
EthernetInterface.lib Show diff for this revision Revisions of this file
HTTPClient-SSL.lib Show diff for this revision Revisions of this file
IFTTT.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ESP8266Interface.lib	Mon Jul 13 17:55:59 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/ESP8266/code/ESP8266Interface/#03fd9333670d
--- a/EthernetInterface.lib	Sun Jun 28 03:41:06 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/#2fc406e2553f
--- 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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IFTTT.lib	Mon Jul 13 17:55:59 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/mbedAustin/code/IFTTT/#c916e13a269a
--- a/main.cpp	Sun Jun 28 03:41:06 2015 +0000
+++ b/main.cpp	Mon Jul 13 17:55:59 2015 +0000
@@ -1,60 +1,29 @@
 #include "mbed.h"
-#include "EthernetInterface.h"
-#include "HTTPClient.h"
- 
-EthernetInterface eth;
-HTTPClient http;
-char str[512] = {};
-char json[125] = {};
-char eventName[] = "helloworld";
-char key[] = "ChangeThisToTheKeyProvidedByIFTTonTheMakerChannel";
-char value1[] = {"A"}, value2[] = {"B"}, value3[] = {"C"};
+#include "ESP8266Interface.h"
+#include "TCPSocketConnection.h"
+#include "ifttt.h"
+
+ESP8266Interface wifi(D1,D0,D2,"ssid","passkey",115200); // TX,RX,Reset,SSID,Password,Baud
+RawSerial pc(USBTX, USBRX); // tx, rx
 
-int main() 
+int main()
 {
-    eth.init(); //Use DHCP
-    eth.connect();
-    printf("IP Address is %s \n\r", eth.getIPAddress());
+    pc.baud(9600);
+    wifi.init(); //Reset
+    wifi.connect(); //Use DHCP
+    printf("IP Address is %s \n\r", wifi.getIPAddress());
+    TCPSocketConnection socket;
     
-    //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();  
- 
+    // 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();
+
+    ifttt.addIngredients("Sending","GET","data");
+    ifttt.trigger(IFTTT_GET);
+
+    ifttt.addIngredients("Sending","POST","things");
+    ifttt.trigger(IFTTT_POST);
     while(1) {
     }
 }
--- a/mbed-rtos.lib	Sun Jun 28 03:41:06 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#d3d0e710b443