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 Vincent Wochnik

Files at this revision

API Documentation at this revision

Comitter:
vwochnik
Date:
Wed Feb 05 16:22:22 2014 +0000
Parent:
4:363b4cc49445
Child:
6:642e7c233e83
Commit message:
fix

Changed in this revision

MbedSmartRest.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/MbedSmartRest.lib	Sun Feb 02 16:40:59 2014 +0000
+++ b/MbedSmartRest.lib	Wed Feb 05 16:22:22 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/vwochnik/code/MbedSmartRest/#3bbb83e7cbfd
+http://mbed.org/users/vwochnik/code/MbedSmartRest/#478414cc15a4
--- a/main.cpp	Sun Feb 02 16:40:59 2014 +0000
+++ b/main.cpp	Wed Feb 05 16:22:22 2014 +0000
@@ -8,8 +8,9 @@
 #include "ComposedRecord.h"
 #include "CharValue.h"
 #include "IntegerValue.h"
+#include "FloatValue.h"
 
-const char * const serialNumber = "curltest-1234567";
+const char * const serialNumber = "ublox-123456789";
 StaticData srtpl(
 // get device by identity
 // Usage: 100,<SERIAL/NR>
@@ -19,41 +20,51 @@
 "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_IsDevice\"\":{}}\"\r\n"
+"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"
 // 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"
+// 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"
 );
 
 long existing();
 long create();
 bool identify(long deviceId);
+bool measurement(long deviceId, double rssi, int ber);
 
 C027 c027;
-MbedSmartRest client("http://developer.cumulocity.com/s", "vaillant/admin", "klanpi", "com_cumulocity_MbedTestDevice_1.0");
-//MbedSmartRest client("http://nocore.info:8888/", "vaillant/admin", "klanpi", "com_cumulocity_MbedTestDevice_1.0");
+MbedSmartRest client("http://developer.cumulocity.com/s", "vaillant/admin", "klanpi", "com_u-blox_C027_REV-A_0.3");
+//MbedSmartRest client("http://nocore.info:8888/", "vaillant/admin", "klanpi", "com_cumulocity_MbedTestDevice_2.0");
 
 int main()
 {
-    long deviceId;
+    long deviceId; double rssi; int ber;
+    
+    puts("Hello!");
 
-    c027.mdmPower(true);
-    UbloxUSBGSMModem modem;
+     c027.mdmWakeup();
+     c027.mdmReset();
+     c027.mdmPower(true);
+     UbloxUSBGSMModem modem;
 
     if (modem.connect("public4.m2minternet.com")) {
         puts("GPRS connection failure.");
         return 2;
     }
-
+    
     puts("Bootstrapping");
     if (client.bootstrap(srtpl) != SMARTREST_SUCCESS) {
         puts("Bootstrapping failed.");
         return 2;
     }
-
+    
+    puts("Starting action...");
+    
     if ((deviceId = existing()) == 0) {
         deviceId = create();
         if (deviceId != 0)
@@ -61,6 +72,17 @@
     }
 
     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);
+        }
+    }
 
     modem.disconnect();
     c027.mdmPower(false);    
@@ -169,3 +191,20 @@
     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));
+
+    if (client.send(newMoRec) != SMARTREST_SUCCESS) {
+        puts("Send failed.");
+        return false;
+    }
+
+    client.stop();
+    return true;
+}
\ No newline at end of file