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 49:ac0ba9d54ebc, committed 2014-07-28
- Comitter:
- Cumulocity
- Date:
- Mon Jul 28 11:49:42 2014 +0000
- Parent:
- 48:d5e21301543e
- Child:
- 50:4e8b3f8e7134
- Commit message:
- increased library stability, gps tracking, minor fixes
Changed in this revision
--- a/DeviceBootstrap.cpp Fri Jul 25 20:16:32 2014 +0000 +++ b/DeviceBootstrap.cpp Mon Jul 28 11:49:42 2014 +0000 @@ -47,7 +47,6 @@ char buf[DEVICE_BOOTSTRAP_CREDENTIALS_LENGTH*2+2], *ptr; int res = _mdm.readFile(CREDENTIALS_FILE, buf, sizeof(buf)); - if (res < 0) return false;
--- a/DeviceIntegration.cpp Fri Jul 25 20:16:32 2014 +0000 +++ b/DeviceIntegration.cpp Mon Jul 28 11:49:42 2014 +0000 @@ -61,7 +61,7 @@ // template bootstrapping process if (_client.bootstrap(_tpl) != SMARTREST_SUCCESS) { puts("Template bootstrap failed."); - return 1; + return false; } puts("Hello.");
--- a/GPSTracker.cpp Fri Jul 25 20:16:32 2014 +0000 +++ b/GPSTracker.cpp Mon Jul 28 11:49:42 2014 +0000 @@ -69,7 +69,6 @@ void GPSTracker::thread_func(void const *arg) { GPSTracker *that; - return; that = (GPSTracker*)arg; that->thread(); }
--- a/LocationUpdate.cpp Fri Jul 25 20:16:32 2014 +0000 +++ b/LocationUpdate.cpp Mon Jul 28 11:49:42 2014 +0000 @@ -1,4 +1,5 @@ #include "LocationUpdate.h" +#include "Aggregator.h" #include "ComposedRecord.h" #include "CharValue.h" #include "IntegerValue.h" @@ -18,9 +19,14 @@ if (_init) return false; - // Insert measurement + // Update device position // USAGE: 108,<DEVICE/ID>,<ALTITUDE>,<LATITUDE>,<LONGITUDE> - if (!_tpl.add("10,108,POST,/event/events,application/vnd.com.nsn.cumulocity.event+json,,%%,NOW UNSIGNED NUMBER NUMBER NUMBER,\"{\"\"time\"\":\"\"%%\"\",\"\"source\"\":{\"\"id\"\":\"\"%%\"\"},\"\"type\"\":\"\"c8y_LocationUpdate\"\",\"\"c8y_Position\"\":{\"\"alt\"\":%%,\"\"lat\"\":%%,\"\"lng\"\":%%}}\"")) + if (!_tpl.add("10,108,PUT,/inventory/managedObjects/%%,application/vnd.com.nsn.cumulocity.managedObject+json,application/vnd.com.nsn.cumulocity.managedObject+json,%%,UNSIGNED NUMBER NUMBER NUMBER,\"{\"\"c8y_Position\"\":{\"\"alt\"\":%%,\"\"lat\"\":%%,\"\"lng\"\":%%},\"\"c8y_MotionTracking\"\":{\"\"active\"\":true}}\"\r\n")) + return false; + + // Insert measurement + // USAGE: 109,<DEVICE/ID>,<ALTITUDE>,<LATITUDE>,<LONGITUDE> + if (!_tpl.add("10,109,POST,/event/events,application/vnd.com.nsn.cumulocity.event+json,application/vnd.com.nsn.cumulocity.event+json,%%,NOW UNSIGNED NUMBER NUMBER NUMBER,\"{\"\"time\"\":\"\"%%\"\",\"\"source\"\":{\"\"id\"\":\"\"%%\"\"},\"\"type\"\":\"\"c8y_LocationUpdate\"\",\"\"text\"\":\"\"Mbed location update\"\",\"\"c8y_Position\"\":{\"\"alt\"\":%%,\"\"lat\"\":%%,\"\"lng\"\":%%}}\"")) return false; _init = true; @@ -31,36 +37,35 @@ { GPSTracker::Position position; - if (!_gpsTracker.position(&position)) + if (!_gpsTracker.position(&position)) { + puts("No GPS data available."); return true; + } puts("Starting measurement sending."); - - ComposedRecord record; - IntegerValue msgId(108); + + Aggregator aggregator; + ComposedRecord record1, record2; + IntegerValue msgId1(108); + IntegerValue msgId2(109); IntegerValue devId(_deviceId); - FloatValue altitude(position.altitude, 6); + FloatValue altitude(position.altitude, 2); FloatValue latitude(position.latitude, 6); - FloatValue longitude(position.longitude, 1); - if ((!record.add(msgId)) || (!record.add(devId)) || (!record.add(altitude)) || (!record.add(latitude)) || (!record.add(longitude))) + FloatValue longitude(position.longitude, 6); + if ((!record1.add(msgId1)) || (!record1.add(devId)) || (!record1.add(altitude)) || (!record1.add(latitude)) || (!record1.add(longitude))) + return false; + if ((!record2.add(msgId2)) || (!record2.add(devId)) || (!record2.add(altitude)) || (!record2.add(latitude)) || (!record2.add(longitude))) + return false; + if ((!aggregator.add(record1)) || (!aggregator.add(record2))) return false; - if (_client.send(record) != SMARTREST_SUCCESS) { + puts("Sending GPS measurement."); + if (_client.send(aggregator) != SMARTREST_SUCCESS) { puts("Signal measurement failed."); _client.stop(); return false; } - - ParsedRecord recvd; - if (_client.receive(recvd) != SMARTREST_SUCCESS) { - puts("Nothing received."); - _client.stop(); - return true; - } - - for (size_t n = 0; n < recvd.values(); n++) - puts(recvd.rawValue(n)); - + _client.stop(); return true; }
--- a/MbedAgent.h Fri Jul 25 20:16:32 2014 +0000 +++ b/MbedAgent.h Mon Jul 28 11:49:42 2014 +0000 @@ -17,7 +17,7 @@ #define MBED_AGENT_HOST "developer.cumulocity.com" #define MBED_AGENT_PORT 80 -#define MBED_AGENT_DEVICE_IDENTIFIER "com_cumulocity_MbedAgent_1.0.3" +#define MBED_AGENT_DEVICE_IDENTIFIER "com_cumulocity_MbedAgent_1.0.5" #define MBED_AGENT_INTERVAL 60.0 class MbedAgent
--- a/MbedSmartRest.lib Fri Jul 25 20:16:32 2014 +0000 +++ b/MbedSmartRest.lib Mon Jul 28 11:49:42 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/Cumulocity/code/MbedSmartRest/#2b74510900da +http://mbed.org/users/Cumulocity/code/MbedSmartRest/#cd7ba1ddb664
--- a/main.cpp Fri Jul 25 20:16:32 2014 +0000 +++ b/main.cpp Mon Jul 28 11:49:42 2014 +0000 @@ -22,11 +22,11 @@ } puts("Modem initialized"); - /*if (!gps.init()) { + if (!gps.init()) { puts("GPS initialization failed."); return 1; } - puts("Gps initialized.");*/ + puts("Gps initialized."); DeviceIO io(gps); io.lcdPrint("DEVICE INIT");