This library provides data update method to Fastsensing.
Dependents: SCP1000_Fastsensing
Fastsensing.cpp
- Committer:
- AkiraK
- Date:
- 2017-05-19
- Revision:
- 7:c29803218447
- Parent:
- 6:8338b52bd7bb
- Child:
- 9:313790e8b56d
File content as of revision 7:c29803218447:
/* MIT License Copyright (c) 2017 Fast Sensing Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "Fastsensing.h" void Fastsensing::ethConnect() { eth.init(); //Use DHCP. Initialize setting of eth. eth.connect(100); //Connect Bring the interface up. } void Fastsensing::ethDisconnect() { eth.disconnect(); //EthernetInterface closed } 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, 128); //Send request is reqUrl as get method and get Response Result. Time out is 5000 //printf("%d\n", res); //printf("%d\n", http.getHTTPResponseCode()); 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 } }