If This Then That interface library. Designed to hook up to various services provided by IFTTT.
Fork of IFTTT by
Diff: ifttt.cpp
- Revision:
- 1:4d2664ecc1e2
- Parent:
- 0:4f7b5d6048b3
- Child:
- 2:b368358ab24c
--- a/ifttt.cpp Fri Jul 10 21:43:50 2015 +0000 +++ b/ifttt.cpp Fri Jul 10 21:58:16 2015 +0000 @@ -141,17 +141,28 @@ return false; } - // Prep data to send + // Prep data to send, the Assembled POST packet should look like this + // + // + //POST /trigger/<eventName>/with/key/<secretKey> HTTP/1.1 + //Host: maker.ifttt.com + //Content-Length: <length of POST data> + //Content-Type: application/json + // + //{"value1":"<v1>","value2":"<v2>","value3":"<v3>"} + // + // + char str[IFTTT_MAX_SIZE_STRING] = {0}; char header[100] = {0}; - sprintf(header, "POST /trigger/%s/with/key/%s HTTP/1.1\r\n"); + sprintf(header, "POST /trigger/%s/with/key/%s HTTP/1.1\r\n",eventName,secretKey); const char * host = "Host: maker.ifttt.com\r\n"; char contentLen[50] = {0}; - //sprintf(contentLen,"Content-Length: %s\r\n"); const char * contentType = "Content-Type: application/json\r\n\r\n"; - char str[IFTTT_MAX_SIZE_STRING] = {0}; - //sprintf(str, "POST /trigger/%s/with/key/%s HTTP/1.1\r\nHost: maker.ifttt.com\r\nContent-Length: 50\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n{\"value1\":\"%s\",\"value2\":\"%s\",\"value3\":\"%s\"}\r\n\r\n",eventName,secretKey,v1,v2,v3); - int thingsize = 50; - sprintf(str, "POST /trigger/%s/with/key/%s HTTP/1.1\r\nHost: maker.ifttt.com\r\nContent-Length: %d\r\nContent-Type: application/json\r\n\r\n{\"value1\":\"%s\",\"value2\":\"%s\",\"value3\":\"data\"}\r\n",eventName,secretKey,thingsize,v1,v2,v3); + char valueData [50] = {0}; + sprintf(valueData,"{\"value1\":\"%s\",\"value2\":\"%s\",\"value3\":\"%s\"}\r\n",v1,v2,v3); + sprintf(contentLen,"Content-Length: %d\r\n",sizeof(valueData)); + sprintf(str,"%s%s%s%s%s",header,host,contentLen,contentType,valueData); + DBG("String to send is:\n\r%s",str); // Send Data @@ -165,7 +176,7 @@ return false; } DBG("Waiting on reply ... \r\n"); - int ret = this->socket->receive(str,50); + int ret = this->socket->receive(str,IFTTT_MAX_SIZE_STRING); str[ret]=0; DBG("Received String : %s",str); this->socket->close();