![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
The Hiking Pal tracking device firmware. See full description on the detail page: https://www.hackster.io/bowenfeng/hiking-pal-v1-07c02d
Dependencies: FXOS8700CQ MODSERIAL mbed
Fork of Avnet_ATT_Cellular_IOT by
Revision 87:ca75c5e785a7, committed 2016-12-22
- Comitter:
- bowenfeng
- Date:
- Thu Dec 22 09:32:33 2016 +0000
- Parent:
- 86:5ff234988f53
- Commit message:
- Join latest hiking activity instead.
Changed in this revision
diff -r 5ff234988f53 -r ca75c5e785a7 cell_modem.cpp --- a/cell_modem.cpp Thu Dec 22 06:59:20 2016 +0000 +++ b/cell_modem.cpp Thu Dec 22 09:32:33 2016 +0000 @@ -326,11 +326,9 @@ if ((MySocketData.length() + 1) < sizeof(stringToCharBuf)) { strcpy(stringToCharBuf, MySocketData.c_str()); - if (extract_JSON(stringToCharBuf, &rx_string[0])) - { - PRINTF(GRN "JSON : %s" DEF "\n", &rx_string[0]); - iStatus = 1; //all good - } + char* body = strstr(stringToCharBuf, "\r\n\r\n"); + sprintf(rx_string, body + 4); + iStatus = 1; //all good } else {
diff -r 5ff234988f53 -r ca75c5e785a7 config_me.h --- a/config_me.h Thu Dec 22 06:59:20 2016 +0000 +++ b/config_me.h Thu Dec 22 09:32:33 2016 +0000 @@ -52,7 +52,7 @@ #define TEMP_HUMIDITY_ACCELEROMETER_GPS 3 #define TEMP_HUMIDITY_ACCELEROMETER_PMODSENSORS 4 #define TEMP_HUMIDITY_ACCELEROMETER_PMODSENSORS_VIRTUALSENSORS 5 -static int iSensorsToReport = TEMP_HUMIDITY_ACCELEROMETER_GPS; //modify this to change your selection +static int iSensorsToReport = TEMP_HUMIDITY_ACCELEROMETER; //modify this to change your selection // This is the APN name for the cellular network, you will need to change this, check the instructions included with your SIM card kit: static const char * MY_APN_STR = "m2m.com.attz";
diff -r 5ff234988f53 -r ca75c5e785a7 main.cpp --- a/main.cpp Thu Dec 22 06:59:20 2016 +0000 +++ b/main.cpp Thu Dec 22 09:32:33 2016 +0000 @@ -107,6 +107,15 @@ sprintf(v, "%lld", value); } +long long find_longlong(const char* s, const char* token, const char** end) { + const char* tokenBegin = strstr(s, token); + if (tokenBegin != 0) { + *end = tokenBegin + strlen(token); + return strtoll(tokenBegin + strlen(token), NULL, 0); + } + return 0; +} + void find_longlong(const char* s, const char* token, char v[]) { const char* tokenBegin = strstr(s, token); if (tokenBegin != 0) { @@ -114,6 +123,7 @@ } } + int send_receive(char* request, char* response) { int result = cell_modem_Sendreceive(request, response); SetLedColor(result ? OK_COLOR : ERROR_COLOR); @@ -125,12 +135,32 @@ return send_receive(request, response); } -void find_first_hiking(char hikingId[]) { +void find_latest_hiking(char hikingId[]) { char request[512]; char response[512]; sprintf(request, "GET %s/hikings HTTP/1.1\r\nHost: %s\r\n\r\n", FLOW_BASE_URL, MY_SERVER_URL); if (send_receive(&request[0], &response[0])) { - find_longlong(response, "\"id\":", hikingId); + long long llv; + long long latestId = 0; + const char* begin = response; + PRINTF("%s\n\n", begin); + + char token[] = "\"id\":"; + for (;;) { + llv = find_longlong(begin, token, &begin); + + PRINTF("---> %lld\n", llv); + PRINTF("%s\n", begin); + + if (llv == 0) { + break; + } + if (llv > latestId) { + latestId = llv; + } + } + sprintf(hikingId, "%lld", latestId); + PRINTF("LATEST HIKING ID: %lld", latestId); } } @@ -189,7 +219,7 @@ sprintf(sessionName, "IoT-kit-%d", rand() % 1000); - find_first_hiking(hid); + find_latest_hiking(hid); PRINTF("Found Hiking ID: "); PRINTF(hid); PRINTF("\r\n");