post sensor data to esp yun

Dependencies:   WIZnetInterface mbed

Fork of espyun by root root

Revision:
9:b5c8b5e14195
Parent:
8:472cd389f3eb
--- a/main.cpp	Fri Nov 25 01:38:01 2016 +0000
+++ b/main.cpp	Fri Nov 25 06:54:18 2016 +0000
@@ -2,6 +2,8 @@
 #include "EthernetInterface.h"
 #include "cJSON.h"
 
+#define MASTER_KEY "b1e92cf17fe4482647924941949ab2b07ffab548"
+
 DigitalInOut myIOD10(D10);
 DigitalIn myInD11(D11);
 DigitalOut myOutD12(D12);
@@ -142,12 +144,12 @@
     //char http_POST_cmd[500] = "POST /v1/datastreams/jhtest/datapoint/ HTTP/1.1\r\nUser-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3\r\n"\
                      // "Host:iot.espressif.cn\r\nAccept: */*\r\nAuthorization: token ebe1671e9d9f42a5231d017ec550552b9bae2cdf\r\n"\
                      // "Content-Length: 33\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n";
-    char http_POST_cmd[500];// = "POST /v1/datastreams/test/datapoint/ HTTP/1.1\r\nUser-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3\r\n"\
+    //char http_POST_cmd[500];// = "POST /v1/datastreams/test/datapoint/ HTTP/1.1\r\nUser-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3\r\n"\
     //                  "Host:iot.espressif.cn\r\nAccept: */*\r\nAuthorization: token b1e92cf17fe4482647924941949ab2b07ffab548\r\n"\
     //                  "Content-Length: ";
-    sprintf(http_POST_cmd,"POST /v1/datastreams/%s/datapoint/ HTTP/1.1\r\nUser-Agent: curl/7.35.0\r\n"\
-                      "Host:iot.espressif.cn\r\nAccept: */*\r\nAuthorization: token b1e92cf17fe4482647924941949ab2b07ffab548\r\n"\
-                      "Content-Length: ", receive_module[num-1]);
+    sprintf(g_buffer,"POST /v1/datastreams/%s/datapoint/ HTTP/1.1\r\nUser-Agent: curl/7.35.0\r\n"\
+                      "Host:iot.espressif.cn\r\nAccept: */*\r\nAuthorization: token %s\r\n"\
+                      "Content-Length: ", receive_module[num-1], MASTER_KEY);
     num--;
     if (num == 0)
         num = 4;
@@ -155,12 +157,12 @@
     char len[2]; 
     len[0]=strlen(pJSON_http_post)/10%10+48;
     len[1]=strlen(pJSON_http_post)%10+48;
-    strcat(http_POST_cmd,len);
-    strcat(http_POST_cmd,"\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n");
+    strcat(g_buffer,len);
+    strcat(g_buffer,"\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\n");
      
-    strcat(http_POST_cmd,pJSON_http_post);
-    conn.send_all(http_POST_cmd, strlen(http_POST_cmd));//http_cmd for http,pJSON for socket,should be three changes
-    pc.printf("%s\r\n",http_POST_cmd); 
+    strcat(g_buffer,pJSON_http_post);
+    conn.send_all(g_buffer, strlen(g_buffer));//http_cmd for http,pJSON for socket,should be three changes
+    pc.printf("%s\r\n",g_buffer); 
     
     char *buffer = NULL;
     buffer = (char *)malloc(MallocSize);
@@ -190,11 +192,11 @@
         }
     }
     
-    const char http_cmd[] = "GET /v1/datastreams/Led/datapoint/ HTTP/1.1\r\nUser-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3\r\n"\
-                      "Host:iot.espressif.cn\r\nAccept: */*\r\nAuthorization: token b1e92cf17fe4482647924941949ab2b07ffab548\r\n\r\n";
+    snprintf(g_buffer,sizeof(g_buffer),"GET /v1/datastreams/Led/datapoint/ HTTP/1.1\r\nUser-Agent: curl/7.22.0 (i686-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3\r\n"\
+                      "Host:iot.espressif.cn\r\nAccept: */*\r\nAuthorization: token %s\r\n\r\n",MASTER_KEY);
     
-    conn.send_all(http_cmd, strlen(http_cmd));//http_cmd for http,pJSON for socket,should be three changes
-    pc.printf("%s\r\n",http_cmd);
+    conn.send_all(g_buffer, strlen(g_buffer));//http_cmd for http,pJSON for socket,should be three changes
+    pc.printf("%s\r\n",g_buffer);
     
     int ret;