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: program.cpp
- Revision:
- 7:f77afd49c35d
- Parent:
- 6:642e7c233e83
- Child:
- 8:940c782eec5e
--- a/program.cpp Mon Feb 10 15:46:26 2014 +0000
+++ b/program.cpp Wed Feb 12 11:25:26 2014 +0000
@@ -5,7 +5,7 @@
#include "IntegerValue.h"
#include "FloatValue.h"
-const char * const serialNumber = "ublox-123456789";
+const char * const serialNumber = "ublox-1231aa8d9";
StaticData srtpl(
// get device by identity
// Usage: 100,<SERIAL/NR>
@@ -15,29 +15,33 @@
"11,200,\"$.managedObject\",,\"$.id\"\r\n"
// Create device
// Usage: 101,<SERIAL/NR>
-"10,101,POST,/inventory/managedObjects,application/vnd.com.nsn.cumulocity.managedObject+json,application/vnd.com.nsn.cumulocity.managedObject+json,%%,STRING,\"{\"\"name\"\":\"\"Curl Test Device\"\",\"\"type\"\":\"\"com_yourcompany?CurlDevice_1.0\"\",\"\"c8y_Hardware\"\":{\"\"revision\"\":\"\"1\"\",\"\"model\"\":\"\"Curl Test Device\"\",\"\"serialNumber\"\":\"\"%%\"\"},\"\"c8y_SupportedMeasurements\"\":[\"\"c8y_SignalStrength\"\"],\"\"c8y_IsDevice\"\":{}}\"\r\n"
+"10,101,POST,/inventory/managedObjects,application/vnd.com.nsn.cumulocity.managedObject+json,application/vnd.com.nsn.cumulocity.managedObject+json,%%,STRING,\"{\"\"name\"\":\"\"Mbed Test Device\"\",\"\"type\"\":\"\"com_yourcompany?CurlDevice_1.0\"\",\"\"c8y_Hardware\"\":{\"\"revision\"\":\"\"1\"\",\"\"model\"\":\"\"Curl Test Device\"\",\"\"serialNumber\"\":\"\"%%\"\"},\"\"c8y_SupportedMeasurements\"\":[\"\"c8y_SignalStrength\"\"],\"\"c8y_IsDevice\"\":{}}\"\r\n"
// Get device id
// Response: 201,<DEVICE/ID>
"11,201,,\"$.c8y_IsDevice\",\"$.id\"\r\n"
// Insert global ID
// Usage: 102,<DEVICE/ID>,<SERIAL/NR>
"10,102,POST,/identity/globalIds/%%/externalIds,application/vnd.com.nsn.cumulocity.externalId+json,application/vnd.com.nsn.cumulocity.externalId+json,%%,UNSIGNED STRING,\"{\"\"type\"\":\"\"c8y_Serial\"\",\"\"externalId\"\":\"\"%%\"\"}\"\r\n"
+// Update IMEI, CellId and iccid
+// Usage: 103,<DEVICE/ID>,<IMEI>,<CELL/ID>,<ICCID>
+"10,103,PUT,/inventory/managedObjects/%%,application/vnd.com.nsn.cumulocity.managedObject+json,application/vnd.com.nsn.cumulocity.managedObject+json,%%,UNSIGNED STRING STRING STRING,\"{\"\"c8y_Mobile\"\":{\"\"imei\"\":\"\"%%\"\",\"\"cellId\"\":\"\"%%\"\",\"\"iccid\"\":\"\"%%\"\"}}\"\r\n"
// Insert measurement
-// USAGE: 103,<DEVICE/ID>,<RSSI>,<BER>
-"10,103,POST,/measurement/measurements,application/vnd.com.nsn.cumulocity.measurement+json,application/vnd.com.nsn.cumulocity.measurement+json,%%,NOW UNSIGNED NUMBER UNSIGNED,\"{\"\"time\"\":\"\"%%\"\",\"\"source\"\":{\"\"id\"\":\"\"%%\"\"},\"\"type\"\":\"\"c8y_SignalStrength\"\",\"\"c8y_SignalStrength\"\":{\"\"rssi\"\":{\"\"value\"\":%%,\"\"unit\"\":\"\"dBm\"\"},\"\"ber\"\":{\"\"value\"\":%%,\"\"unit\"\":\"\"%\"\"}}}\"\r\n"
+// USAGE: 104,<DEVICE/ID>,<RSSI>,<BER>
+"10,104,POST,/measurement/measurements,application/vnd.com.nsn.cumulocity.measurement+json,application/vnd.com.nsn.cumulocity.measurement+json,%%,NOW UNSIGNED NUMBER UNSIGNED,\"{\"\"time\"\":\"\"%%\"\",\"\"source\"\":{\"\"id\"\":\"\"%%\"\"},\"\"type\"\":\"\"c8y_SignalStrength\"\",\"\"c8y_SignalStrength\"\":{\"\"rssi\"\":{\"\"value\"\":%%,\"\"unit\"\":\"\"dBm\"\"},\"\"ber\"\":{\"\"value\"\":%%,\"\"unit\"\":\"\"%\"\"}}}\"\r\n"
);
long existing();
long create();
bool identify(long deviceId);
+bool update(long deviceId);
bool measurement(long deviceId, double rssi, int ber);
-MbedSmartRest client("http://developer.cumulocity.com/s", "vaillant/admin", "klanpi", "com_u-blox_C027_REV-A_0.3");
+MbedSmartRest client("http://developer.cumulocity.com/s", "vaillant/admin", "klanpi", "com_u-blox_C027_REV-A_0.5");
//MbedSmartRest client("http://nocore.info:8888/", "vaillant/admin", "klanpi", "com_cumulocity_MbedTestDevice_2.0");
int program(void)
{
- long deviceId; double rssi; int ber;
+ long deviceId; sigq_t *signal;
puts("Hello!");
@@ -51,21 +55,21 @@
if ((deviceId = existing()) == 0) {
deviceId = create();
- if (deviceId != 0)
- identify(deviceId);
+ if (deviceId == 0)
+ return 1;
+ if (!identify(deviceId))
+ return 2;
}
+ if (!update(deviceId))
+ return 3;
printf("Device ID: %ld\r\n", deviceId);
- if (deviceId != 0) {
- rssi = -50;
- ber = 50;
-
- while (true) {
- printf("[MEASUREMENT] RSSI: %lf, BER: %d %%\n", rssi, ber);
- measurement(deviceId, rssi, ber);
- wait(60000);
- }
+ while (true) {
+ signal = signalQuality();
+ printf("[MEASUREMENT] RSSI: %lf, BER: %d %%\n", signal->rssi, signal->ber);
+ measurement(deviceId, signal->rssi, signal->ber);
+ wait(2000);
}
return 0;
@@ -174,13 +178,47 @@
return true;
}
+bool update(long deviceId)
+{
+ ComposedRecord newMoRec(true); // set copy=true b/c tmp objects
+ ParsedRecord received;
+
+ puts("Updating device data...");
+
+ newMoRec.add(IntegerValue(103)).add(IntegerValue(deviceId)).add(CharValue(imei())).add(CharValue(cellId())).add(CharValue(iccid()));
+
+ if (client.send(newMoRec) != SMARTREST_SUCCESS) {
+ puts("Send failed.");
+ return false;
+ }
+
+ if (client.receive(received) != SMARTREST_SUCCESS) {
+ puts("Update failed.");
+ return false;
+ }
+
+ if (received.values() != 3) {
+ puts("Bad received data.");
+ return false;
+ }
+
+ if (received.value(0).integerValue() != 201) {
+ puts("Bad received data.");
+ return false;
+ }
+
+ client.stop();
+
+ return true;
+}
+
bool measurement(long deviceId, double rssi, int ber)
{
ComposedRecord newMoRec(true); // set copy=true b/c tmp objects
puts("Creating measurement...");
- newMoRec.add(IntegerValue(103)).add(IntegerValue(deviceId)).add(FloatValue(rssi, 0)).add(IntegerValue(ber));
+ newMoRec.add(IntegerValue(104)).add(IntegerValue(deviceId)).add(FloatValue(rssi, 0)).add(IntegerValue(ber));
if (client.send(newMoRec) != SMARTREST_SUCCESS) {
puts("Send failed.");
