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: measurement/LocationUpdate.cpp
- Revision:
- 73:313975bfec96
- Parent:
- 72:c5709ae7b193
- Child:
- 74:ca3001991fdc
--- a/measurement/LocationUpdate.cpp Mon Feb 16 13:15:52 2015 +0000
+++ b/measurement/LocationUpdate.cpp Tue Feb 17 16:31:30 2015 +0000
@@ -7,13 +7,18 @@
#include "logging.h"
#define THRESHOLD_PERCENT_LOC 0.05 // Percentage cut-off for avoiding sending similar acceleration sensor data.
-#define TIME_LIMIT_LOC 900 // Time interval for forcing a sending even if acceleration sensor readings are constantly similar.
+// Time interval for forcing a sending even if analog sensor readings are constantly similar (in seconds).
+#define TIME_LIMIT_LOC 900
-LocationUpdate::LocationUpdate(AbstractSmartRest& client, SmartRestTemplate& tpl, long& deviceId, GPSTracker& gpsTracker) :
+LocationUpdate::LocationUpdate(AbstractSmartRest& client, SmartRestTemplate& tpl, long& deviceId, GPSTracker& gpsTracker,
+ DeviceIO& io, DeviceInfo& deviceInfo, DeviceBootstrap& bootstrap) :
_client(client),
_tpl(tpl),
_deviceId(deviceId),
- _gpsTracker(gpsTracker)
+ _gpsTracker(gpsTracker),
+ _io(io),
+ _deviceInfo(deviceInfo),
+ _bootstrap(bootstrap)
{
_init = false;
oldValues[0] = 0;
@@ -53,16 +58,24 @@
data[0] = position.altitude;
data[1] = position.latitude;
data[2] = position.longitude;
+ char tenant[25] = {0};
+ snprintf(tenant, 25, "Tenant: %s", _bootstrap.username());
+ char signal[25] = {0};
+ snprintf(signal, 25, "Network: %d dBm", _deviceInfo.signalQuality()->rssi);
if (abs(oldValues[0]-data[0]) <= abs(oldValues[0])*THRESHOLD_PERCENT_LOC &&
abs(oldValues[1]-data[1]) <= abs(oldValues[1])*THRESHOLD_PERCENT_LOC &&
abs(oldValues[2]-data[2]) <= abs(oldValues[2])*THRESHOLD_PERCENT_LOC) {
if (sendingTimer.read() < TIME_LIMIT_LOC) {
- aInfo("Similar location readings found, no sending!\r\n");
+ aDebug("Similar location readings found, no sending!\r\n");
+ _io.lcdPrint(tenant, signal);
return true;
} else {
- aInfo("Sending timer of location sensor timed out at %f s, a sending is forced.\r\n", sendingTimer.read());
+ aDebug("Sending timer of location sensor timed out at %f s, a sending is forced.\r\n", sendingTimer.read());
}
}
+ char status[27] = {0};
+ snprintf(status, 27, "Sending GPS %.1f,%.1f,%.1f", data[0], data[1], data[2]);
+ _io.lcdPrint(tenant, signal, status);
Aggregator aggregator;
ComposedRecord record1, record2;
@@ -79,17 +92,18 @@
if ((!aggregator.add(record1)) || (!aggregator.add(record2)))
return false;
+ float t_start = sendingTimer.read();
if (_client.send(aggregator) != SMARTREST_SUCCESS) {
aError("Signal measurement failed.\r\n");
_client.stop();
return false;
}
-
+ float t_end = sendingTimer.read();
_client.stop();
+ aInfo("Acceleration readings sent in %.1f.\r\n", t_end-t_start);
oldValues[0] = data[0];
oldValues[1] = data[1];
oldValues[2] = data[2];
sendingTimer.reset();
- aInfo("Location readings sent.\r\n");
return true;
}

Cumulocity