This library provides data update method to Fastsensing.
Dependents: SCP1000_Fastsensing
Diff: Fastsensing.cpp
- Revision:
- 12:fee4921dd28a
- Parent:
- 9:313790e8b56d
--- a/Fastsensing.cpp Sun Jul 02 08:40:05 2017 +0000 +++ b/Fastsensing.cpp Wed Jul 12 10:11:36 2017 +0000 @@ -39,7 +39,7 @@ //Error handling about deviceID length if(strlen(channelId) != 8) { - printf("Error1 : Device ID length is not correctly.\n"); + printf("Error2 : Channel ID length is not correctly.\n"); return -2; } @@ -50,8 +50,12 @@ //Open Socket TCPSocket socket; //Create a socket on a network interface - socket.open(ð); //Create a network socket + int error = socket.open(ð); //Create a network socket socket.connect("f-io.net", 80); //Connect remote host + if(error < 0) { + printf("Error3 : Error code is %d\n", error); //If TCPSocket.open is failed, return error; + return -3; + } //Create query strcpy(req, basedHead); //based Url is copied to req @@ -62,14 +66,12 @@ strcat(req, query); //Concatenate req and query strcat(req, basedFoot); //Concatenate req and basedFoot int scount = socket.send(req, sizeof req); //Count - //printf("sent %d [%.*s]\n", scount, strstr(req, "\r\n")-req, req); //Send time and Send data display - if(display == 1) printf("Sent [%.*s]\n", strstr(req, "\r\n")-req, req); //Send time and Send data display + if(display == 1) printf("sent %d [%.*s]\n", scount, strstr(req, "\r\n")-req, req); //Send time and Send data display // Recieve response char rbuffer[64]; int rcount = socket.recv(rbuffer, sizeof rbuffer); //Recieve count - //printf("recv %d [%.*s]\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer); //Display Recieve data - if(display == 1) printf("Recieve [%.*s]\n", strstr(rbuffer, "\r\n")-rbuffer, rbuffer); //Display Recieve data + if(display == 1) printf("recv %d [%.*s]\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer); //Display Recieve data // Close the socket socket.close(); @@ -97,7 +99,7 @@ //Error handling about channelID length for(int a = 0; a < 3; a++) { if(strlen(channelId[a]) != 8) { - printf("Error1 : Device ID length is not correctly.\n"); + printf("Error2 : Channel ID length is not correctly.\n"); return -2; } } @@ -109,8 +111,12 @@ //Open Socket TCPSocket socket; //Create a socket on a network interface - socket.open(ð); //Create a network socket with ip address(stack) + int open_error = socket.open(ð); //Create a network socket with ip address(stack) socket.connect("f-io.net", 80); //Connect remote host + if(open_error < 0){ + printf("Error3 : Error code is %d\n", error); //If TCPSocket.open is failed, return error; + return -3; + } //Create query strcpy(req, basedHead); //based Url is copied to req @@ -122,16 +128,13 @@ strcat(req, query); //Concatenate req and query } strcat(req, basedFoot); //Concatenate req and basedFoot - //printf("%s\n", req); int scount = socket.send(req, sizeof req); //Count - //printf("sent %d [%.*s]\n", scount, strstr(req, "\r\n")-req, req); //Send time and Send data display - if(display == 1) printf("Sent [%.*s]\n", strstr(req, "\r\n")-req, req); //Send time and Send data display + if(display == 1) printf("sent %d [%.*s]\n", scount, strstr(req, "\r\n")-req, req); //Send time and Send data display // Recieve response char rbuffer[64]; int rcount = socket.recv(rbuffer, sizeof rbuffer); //Recieve count - //printf("recv %d [%.*s]\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer); //Display Recieve data - if(display == 1) printf("Recieve [%.*s]\n", strstr(rbuffer, "\r\n")-rbuffer, rbuffer); //Display Recieve data + if(display == 1) printf("recv %d [%.*s]\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer); //Display Recieve data // Close the socket socket.close();