Official reference client implementation for Cumulocity SmartREST on u-blox C027.
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Revision 123:3e4a1ed4bad5, committed 2015-05-27
- Comitter:
- xinlei
- Date:
- Wed May 27 09:22:24 2015 +0000
- Parent:
- 122:68217ccb8cd1
- Child:
- 124:311fa85af2b3
- Commit message:
- Temporary work-around for long polling when server not properly close connection.
Changed in this revision
measurement/Signal.cpp | Show annotated file Show diff for this revision Revisions of this file |
operation/PollThread.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/measurement/Signal.cpp Wed May 20 14:30:26 2015 +0000 +++ b/measurement/Signal.cpp Wed May 27 09:22:24 2015 +0000 @@ -16,15 +16,16 @@ static const char *fmt = "104,%ld,%d,%d\r\n"; static char signal[27] = {0}; DeviceInfo::SignalQuality *p = deviceInfo.signalQuality(); - if (p == NULL) - return 0; - else if (p && p->rssi) + + if (p && p->rssi) snprintf(signal, sizeof(signal), "Network: %d dBm", p->rssi); else strncpy(signal, "Network: no coverage", sizeof(signal)); if (strcmp(LCDDisplay::inst().getSecondLine(), signal)) { LCDDisplay::inst().setSecondLine(signal); } + if (p == NULL) + return 0; int data[2] = { p->rssi, p->ber }; if (abs(oldValues[0]-data[0]) <= abs(oldValues[0])*THRESHOLD_PERCENT_SIG &&
--- a/operation/PollThread.cpp Wed May 20 14:30:26 2015 +0000 +++ b/operation/PollThread.cpp Wed May 27 09:22:24 2015 +0000 @@ -9,7 +9,7 @@ l = snprintf(buf, sizeof(buf), fmtSmartRest, uri, l, buf2); sock.setBlocking(3000); l = sock.sendAndReceive(buf, l, sizeof(buf)); - if (l < 0) + if (l <= 0) return false; size_t i = 0; for (const char* p = skipHTTPHeader(buf); isalnum(*p); ++p, ++i) { @@ -24,17 +24,21 @@ 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); - l = sock.sendOnly(buf, l); - return l>=0; + l = sock.sendAndReceive(buf, l, sizeof(buf)); + if (l <= 0) return false; + const char *p = skipHTTPHeader(buf); + if (p == NULL) return false; + for (; *p && !isgraph(*p); ++p); + return *p == 0; } bool PollThread::connect() { int l = snprintf(buf2, sizeof(buf2), "83,%s\r\n", bayeuxId); l = snprintf(buf, sizeof(buf), fmtSmartRest, uri, l, buf2); - sock.setBlocking(-1); + sock.setBlocking(300000); // Timeout after an hour l = sock.sendAndReceive(buf, l, sizeof(buf)); - return l>=0; + return l>0; } void PollThread::threadFunc()