IFTTT: helloworld

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of IFTTT_Done by TaChing Yu

Revision:
2:678f949dccd7
Parent:
1:3010b44f07ff
Child:
3:a0efe12a75cf
--- a/main.cpp	Mon Jul 13 18:50:53 2015 +0000
+++ b/main.cpp	Sun Sep 11 07:08:30 2016 +0000
@@ -1,7 +1,6 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
 #include "TCPSocketConnection.h"
-#include "ifttt.h"
 
 EthernetInterface eth;
 RawSerial pc(USBTX, USBRX); // tx, rx
@@ -13,21 +12,54 @@
     eth.connect();
     printf("IP Address is %s \n\r", eth.getIPAddress());
     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);
-
+    
+    socket.connect("maker.ifttt.com", 80);
+    /*
+    char str[]="";
+    char *post = "POST /trigger/OWJMAN/with/key/bkJhw8soKcjx28zrqAgeW2 HTTP/1.1\r\n";
+    char *host = "Host: maker.ifttt.com\r\n";
+    char *type = "Content-Type: application/json\r\n\r\n";
+    char contentLen[50] = {0};
+    char *data = "{\"value1\":\"this is awesome\",\"value2\":\"test-ing\",\"value3\":\"data!!!\"}\r\n";
+    sprintf(contentLen,"Content-Length: %d\r\n",strlen(data));
+    sprintf(str,"%s%s%s%s%s",post,host,contentLen,type,data);
+    socket.send_all(str, strlen(str));*/
+    
+    char *post = "POST /trigger/OWJMAN/with/key/bkJhw8soKcjx28zrqAgeW2 HTTP/1.1\r\n";
+    char *host = "Host: maker.ifttt.com\r\n";
+    char *type = "Content-Type: application/json\r\n\r\n";
+    char contentLen[] = "";
+    char *data = "{\"value1\":\"this is awesome\",\"value2\":\"test-ing\",\"value3\":\"data!!!\"}\r\n";
+    sprintf(contentLen,"Content-Length: %d\r\n",strlen(data));
+    socket.send_all(post, strlen(post));
+    socket.send_all(host, strlen(host));
+    socket.send_all(type, strlen(type));
+    socket.send_all(contentLen, strlen(contentLen));
+    socket.send_all(data, strlen(data));
+     
+    char buffer[300];
+    int ret;
+    while (true) {
+        ret = socket.receive(buffer, sizeof(buffer)-1);
+        if (ret <= 0)
+            break;
+        buffer[ret] = '\0';
+        printf("Received %d chars from server:\n%s\n", ret, buffer);
+    }
+    printf("DONE!\n");
+      
+    socket.close();
+    
     eth.disconnect();
-    while(1) {
-    }
+    
+    while(1) {}
 }
+extern "C" void mbed_mac_address(char *mac)
+{
+    mac[0] = 0xD4;
+    mac[1] = 0x3F;
+    mac[2] = 0x7E;
+    mac[3] = 0x4C;
+    mac[4] = 0x7E;
+    mac[5] = 0x1C;
+};