This library provides data update method to Fastsensing.

Dependents:   SCP1000_Fastsensing

Revision:
0:f26c02be48f9
Child:
1:3f52b4da889a
diff -r 000000000000 -r f26c02be48f9 Fastsensing.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Fastsensing.cpp	Mon Mar 20 01:28:59 2017 +0000
@@ -0,0 +1,57 @@
+#include "Fastsensing.h"
+
+int Fastsensing::updateData(char *deviceId, char *channelId, double data)
+{
+    eth.init();                                 //Use DHCP. Initialize setting of eth.
+    eth.connect();                              //Connect Bring the interface up.
+    char reqUrl[1000];                          //Char array for request
+    char basedUrl[20] = "http://f-io.net/D1/";  //based http url
+    char query[256];                            //The array is for holding query
+    char resResult[256];                        //The array is for holding response result
+    strcpy(reqUrl, basedUrl);                   //based Url is copied to reqUrl
+    strcat(reqUrl, deviceId);                   //Concatenate reqUrl and deviceId
+    sprintf(query, "?%s=%f", channelId, data);  //Create Query String
+    strcat(reqUrl, query);                      //Concatenate reqUrl and query
+    int res = http.get(reqUrl, resResult, 128);//Send request is reqUrl as get method and get Response Result. Time out is 5000
+    printf("%d\n", res);
+    if(!res) {                                  //If session is completed
+        eth.disconnect();                       //EthernetInterface closed
+        printf("disconnected\n");
+        return 0;                               //Return 0
+    } else {                                    //If session is not completed
+        eth.disconnect();                       //EthernetInterface closed
+        printf("disconnected\n");
+        return 1;                               //Return 1
+    }
+}
+
+int Fastsensing::updateDataAll(char *deviceId, char *channelId[3], float data[3])
+{
+    eth.init();                                                 //Use DHCP. Initialize setting of eth.
+    eth.connect();                                              //Connect Bring the interface up.
+    char reqUrl[1000];                                          //Char array for request
+    char basedUrl[20] = "http://f-io.net/D1/";                  //based http url
+    char query[256];                                            //The array is for holding query
+    char resResult[256];                                        //The array is for holding response result
+    char delim;                                                 //delimiter
+    strcpy(reqUrl, basedUrl);                                   //based Url is copied to reqUrl
+    strcat(reqUrl, deviceId);                                   //Concatenate reqUrl and deviceId
+    for(int i = 0; i < 3; i++) {                                //Create request URL
+        if(i == 0) delim = '?';                                 //first query is connected with ?
+        else delim = '&';                                       //After second, query is connected with &
+        sprintf(query, "%c%s=%.1f",delim, channelId[i], data[i]); //Create Query String
+        strcat(reqUrl, query);                                  //Concatenate reqUrl and query
+    }
+    printf("%s\n", reqUrl);
+    int res = http.get(reqUrl, resResult, 300);                 //Send request is reqUrl as get method and get Response Result. Time out is 5000
+    printf("%d\n", res);
+    if(!res) {                                                  //If session is completed
+        eth.disconnect();                                       //EthernetInterface closed
+        printf("disconnected\n");
+        return 0;                                               //Return 0
+    } else {                                                    //If session is not completed
+        eth.disconnect();                                       //EthernetInterface closed
+        printf("disconnected\n");
+        return 1;                                               //Return 1
+    }
+}
\ No newline at end of file