SmartREST client reference implementation for the u-blox C027 mbed compatible device.

Dependencies:   C027 C027_Support mbed mbed-rtos MbedSmartRest LM75B MMA7660 C12832

Fork of MbedSmartRestTest by Vincent Wochnik

Revision:
19:7bee744fe527
Parent:
16:94d6eae3195a
Child:
20:ef9cc1b42e9d
--- a/program.cpp	Tue Feb 18 15:57:38 2014 +0000
+++ b/program.cpp	Tue Feb 18 17:17:48 2014 +0000
@@ -14,7 +14,7 @@
 void loop(long deviceId);
 void signalMeasurement(long deviceId, Aggregator& aggr);
 void temperatureMeasurement(long deviceId, Aggregator& aggr);
-void countMeasurement(long deviceId, Aggregator& aggr);
+void analogMeasurement(long deviceId, Aggregator& aggr);
 void motionMeasurement(long deviceId, Aggregator& aggr);
 
 StaticData srtpl(
@@ -26,7 +26,7 @@
 "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\"\":\"\"Mbed Test Device\"\",\"\"type\"\":\"\"com_ublox_C027_REV-A\"\",\"\"c8y_Hardware\"\":{\"\"revision\"\":\"\"1\"\",\"\"model\"\":\"\"Ublox C027\"\",\"\"serialNumber\"\":\"\"%%\"\"},\"\"c8y_SupportedMeasurements\"\":[\"\"c8y_SignalStrength\"\",\"\"c8y_TemperatureMeasurement\"\",\"\"c8y_CountMeasurement\"\",\"\"c8y_MotionMeasurement\"\"],\"\"c8y_RequiredAvailability\"\":{ \"\"responseInterval\"\":15},\"\"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_ublox_C027_REV-A\"\",\"\"c8y_Hardware\"\":{\"\"revision\"\":\"\"1\"\",\"\"model\"\":\"\"Ublox C027\"\",\"\"serialNumber\"\":\"\"%%\"\"},\"\"c8y_SupportedMeasurements\"\":[\"\"c8y_SignalStrength\"\",\"\"c8y_TemperatureMeasurement\"\",\"\"c8y_AnalogMeasurement\"\",\"\"c8y_MotionMeasurement\"\"],\"\"c8y_RequiredAvailability\"\":{ \"\"responseInterval\"\":15},\"\"c8y_IsDevice\"\":{}}\"\r\n"
 // Get device id
 // Response: 201,<DEVICE/ID>
 "11,201,,\"$.c8y_IsDevice\",\"$.id\"\r\n"
@@ -43,15 +43,15 @@
 // USAGE: 105,<DEVICE/ID>,<TEMPERATURE>
 "10,105,POST,/measurement/measurements,application/vnd.com.nsn.cumulocity.measurement+json,application/vnd.com.nsn.cumulocity.measurement+json,%%,NOW UNSIGNED NUMBER,\"{\"\"time\"\":\"\"%%\"\",\"\"source\"\":{\"\"id\"\":\"\"%%\"\"},\"\"type\"\":\"\"c8y_TemperatureMeasurement\"\",\"\"c8y_TemperatureMeasurement\"\":{\"\"T\"\":{\"\"value\"\":%%,\"\"unit\"\":\"\"C\"\"}}}\"\r\n"
 // Insert measurement
-// USAGE: 105,<DEVICE/ID>,<COUNTER>
-"10,106,POST,/measurement/measurements,application/vnd.com.nsn.cumulocity.measurement+json,application/vnd.com.nsn.cumulocity.measurement+json,%%,NOW UNSIGNED UNSIGNED,\"{\"\"time\"\":\"\"%%\"\",\"\"source\"\":{\"\"id\"\":\"\"%%\"\"},\"\"type\"\":\"\"c8y_CountMeasurement\"\",\"\"c8y_CountMeasurement\"\":{\"\"n\"\":{\"\"value\"\":%%,\"\"unit\":\"\"\"\"}}}\"\r\n"
+// USAGE: 105,<DEVICE/ID>,<ANALOG0>,<ANALOG1>
+"10,106,POST,/measurement/measurements,application/vnd.com.nsn.cumulocity.measurement+json,application/vnd.com.nsn.cumulocity.measurement+json,%%,NOW UNSIGNED UNSIGNED UNSIGNED,\"{\"\"time\"\":\"\"%%\"\",\"\"source\"\":{\"\"id\"\":\"\"%%\"\"},\"\"type\"\":\"\"c8y_AnalogMeasurement\"\",\"\"c8y_AnalogMeasurement\"\":{\"\"analog0\"\":{\"\"value\"\":%%,\"\"unit\"\":\"\"%\"\"},\"\"analog1\"\":{\"\"value\"\":%%,\"\"unit\"\":\"\"%\"\"}}}\"\r\n"
 // Insert measurement
 // USAGE: 105,<DEVICE/ID>,<X>,<Y>,<Z>
 "10,107,POST,/measurement/measurements,application/vnd.com.nsn.cumulocity.measurement+json,application/vnd.com.nsn.cumulocity.measurement+json,%%,NOW UNSIGNED NUMBER NUMBER NUMBER,\"{\"\"time\"\":\"\"%%\"\",\"\"source\"\":{\"\"id\"\":\"\"%%\"\"},\"\"type\"\":\"\"c8y_MotionMeasurement\"\",\"\"c8y_MotionMeasurement\"\":{\"\"x\"\":{\"\"value\"\":%%,\"\"unit\"\":\"\"m^2/s\"\"},\"\"y\"\":{\"\"value\"\":%%,\"\"unit\"\":\"\"m^2/s\"\"},\"\"z\"\":{\"\"value\"\":%%,\"\"unit\"\":\"\"m^2/s\"\"}}}\"\r\n"
 );
 
 float interval = 120.0; // send measurements every two minutes
-MbedSmartRest client("http://developer.cumulocity.com/s", "vaillant/admin", "klanpi", "com_u-blox_C027_REV-A_0.9");
+MbedSmartRest client("http://developer.cumulocity.com/s", "vaillant/admin", "klanpi", "com_u-blox_C027_REV-A_0.10");
 
 int program(void)
 {
@@ -74,8 +74,9 @@
         if (!identify(deviceId))
             return 2;
     }
-    if (!update(deviceId))
-        return 3;
+    //if (!update(deviceId))
+    //    return 3;
+    update(deviceId);
 
     printf("Device ID: %ld\r\n", deviceId);
 
@@ -256,7 +257,7 @@
     client.stop();
     aggr.clear();
     temperatureMeasurement(deviceId, aggr);
-    countMeasurement(deviceId, aggr);
+    analogMeasurement(deviceId, aggr);
     if (client.send(aggr) != SMARTREST_SUCCESS) {
         puts("Send failed.");
     }
@@ -296,13 +297,16 @@
     aggr.add(measurement);
 }
 
-void countMeasurement(long deviceId, Aggregator& aggr)
+void analogMeasurement(long deviceId, Aggregator& aggr)
 {
+    long analog0 = (long)(potentiometer(0) * 100.0);
+    long analog1 = (long)(potentiometer(1) * 100.0);
     ComposedRecord measurement;
     IntegerValue msgId(106);
     IntegerValue devId(deviceId);
-    IntegerValue n(counter());
-    measurement.add(msgId).add(devId).add(n);
+    IntegerValue an0(analog0);
+    IntegerValue an1(analog1);
+    measurement.add(msgId).add(devId).add(an0).add(an1);
     aggr.add(measurement);
 }