
Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Revision 131:a06da6952339, committed 2015-08-07
- Comitter:
- xinlei
- Date:
- Fri Aug 07 12:44:43 2015 +0000
- Parent:
- 130:ca312ec4bd0f
- Parent:
- 129:dc9e37d4bc05
- Child:
- 132:7b6b4e515a0d
- Commit message:
- SmartRestConf: more host candidates added.
Changed in this revision
MbedAgent.cpp | Show annotated file Show diff for this revision Revisions of this file |
util/SmartRestConf.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/MbedAgent.cpp Fri Aug 07 12:38:28 2015 +0000 +++ b/MbedAgent.cpp Fri Aug 07 12:44:43 2015 +0000 @@ -120,7 +120,6 @@ l = snprintf(buf, sizeof(buf), fmtSmartRest, "/s", l, buf2); sock.setBlocking(3000); l = sock.sendOnly(buf, l); - aInfo("[SEND] agent: %d\n", l); if (l < 0) aWarning("%s\n", status); }
--- a/mbed-rtos.lib Fri Aug 07 12:38:28 2015 +0000 +++ b/mbed-rtos.lib Fri Aug 07 12:44:43 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#85a52b7ef44b +http://mbed.org/users/mbed_official/code/mbed-rtos/#5c72830f2d48
--- a/mbed.bld Fri Aug 07 12:38:28 2015 +0000 +++ b/mbed.bld Fri Aug 07 12:44:43 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/dbbf35b96557 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/7cff1c4259d7 \ No newline at end of file
--- a/measurement/Potentiometer.cpp Fri Aug 07 12:38:28 2015 +0000 +++ b/measurement/Potentiometer.cpp Fri Aug 07 12:44:43 2015 +0000 @@ -48,8 +48,6 @@ return 0; } - if (t_interval >= TIME_LIMIT_ANA) - aInfo("[%f]: %f, %f (%f, %f)\n", t_interval, data[0], data[1], oldValues[0], oldValues[1]); size_t l = snprintf(buf, maxLen, fmt, deviceID, data[0], data[1]); if (status) { snprintf(status, num, "Send Poti %.1f,%.1f", data[0], data[1]);
--- a/operation/PollThread.cpp Fri Aug 07 12:38:28 2015 +0000 +++ b/operation/PollThread.cpp Fri Aug 07 12:44:43 2015 +0000 @@ -3,18 +3,13 @@ #include "PollThread.h" #include "logging.h" -static size_t _volSend = 0; -static size_t _volRecv = 0; - bool PollThread::handshake() { int l = snprintf(buf2, sizeof(buf2), "%s", "80\r\n"); l = snprintf(buf, sizeof(buf), fmtSmartRest, uri, l, buf2); sock.setBlocking(3000); - _volSend += l; l = sock.sendAndReceive(buf, l, sizeof(buf)); if (l <= 0) return false; - _volRecv += l; const char* p = skipHTTPHeader(buf); if (p == NULL) return false; size_t i = 0; @@ -30,10 +25,8 @@ int l = snprintf(buf2, sizeof(buf2), "81,%s,%s\r\n", bayeuxId, chn); l = snprintf(buf, sizeof(buf), fmtSmartRest, uri, l, buf2); sock.setBlocking(3000); - _volSend += l; l = sock.sendAndReceive(buf, l, sizeof(buf)); if (l <= 0) return false; - _volRecv += l; const char *p = skipHTTPHeader(buf); if (p == NULL) return false; for (; *p && !isgraph(*p); ++p); @@ -45,11 +38,36 @@ int l = snprintf(buf2, sizeof(buf2), "83,%s\r\n", bayeuxId); l = snprintf(buf, sizeof(buf), fmtSmartRest, uri, l, buf2); sock.setBlocking(610000); // Timeout after 10m:10s - _volSend += l; - aInfo("[SEND] poll: %d\n", _volSend); - l = sock.sendAndReceive(buf, l, sizeof(buf)); - _volRecv += l; - aInfo("[RECV] poll: %d\n", _volRecv); +// sock.setBlocking(-1); +// l = sock.sendAndReceive(buf, l, sizeof(buf)); + int c = sock.connect(); + if (c < 0) { + sock.close(); + return false; + } + c = sock.send(buf, l); + if (c < 0) { + sock.close(); + return false; + } + // Avoid heartbeat message overflows the buffer + l = 0; + for (unsigned short i = 0; i < 200; ++i) { + int l2 = sock.receive(buf+l, sizeof(buf)-l); + printf("l2: %d\n", l2); + if (l2 > 0) { + printf("poll: %.*s\n", l2, buf+l); + l += l2; + } else if (!sock.is_connected()) { + break; + } else { + l = l2; + break; + } + } + if (l >= 0) + buf[l] = 0; + sock.close(); return l>0; }
--- a/util/SmartRestConf.cpp Fri Aug 07 12:38:28 2015 +0000 +++ b/util/SmartRestConf.cpp Fri Aug 07 12:44:43 2015 +0000 @@ -9,8 +9,9 @@ char srAuthStr[100] = {0}; //const char *srX_ID = "com_cumulocity_MbedAgent_1.5.2"; const char *srX_ID = NULL; -//const char *srHost = "developer.cumulocity.com"; -const char *srHost = "dev-b.cumulocity.com"; +const char *srHost = "developer.cumulocity.com"; +//const char *srHost = "dev-b.cumulocity.com"; +//const char *srHost = "dev-d.cumulocity.com"; //const char *srHost = "management.m2m-devicecloud.com"; long deviceID = 0; char fmtSmartRest[200] = {0};
--- a/util/SmartRestSocket.h Fri Aug 07 12:38:28 2015 +0000 +++ b/util/SmartRestSocket.h Fri Aug 07 12:44:43 2015 +0000 @@ -2,13 +2,14 @@ #define SMARTRESTSOCKET_H #include "TCPSocketConnection.h" -class SmartRestSocket : private TCPSocketConnection +class SmartRestSocket : public TCPSocketConnection { public: SmartRestSocket(): TCPSocketConnection() { memset(cachedIP, 0, sizeof(cachedIP)); } virtual ~SmartRestSocket() {} + int connect(); int sendOnly(char *buf, int size); int sendAndReceive(char *buf, int size, int maxSize); /* Set the timeout for the socket. @@ -21,7 +22,6 @@ Socket::set_blocking(false, timeout); } private: - int connect(); char cachedIP[16]; };