Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Diff: LocationUpdate.cpp
- Revision:
- 49:ac0ba9d54ebc
- Parent:
- 47:89ae46d5c466
- Child:
- 55:a0f7295ed6b6
diff -r d5e21301543e -r ac0ba9d54ebc LocationUpdate.cpp
--- 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;
}

Cumulocity