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
Revision 36:2f6a023f0504, committed 2014-07-07
- Comitter:
- Cumulocity
- Date:
- Mon Jul 07 14:20:42 2014 +0000
- Parent:
- 35:ee1c6289e617
- Child:
- 37:4a7f58dd03d2
- Commit message:
- fix device bootstrap
Changed in this revision
MbedSmartRest.lib | Show annotated file Show diff for this revision Revisions of this file |
program.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/MbedSmartRest.lib Thu Jul 03 18:52:04 2014 +0000 +++ b/MbedSmartRest.lib Mon Jul 07 14:20:42 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/Cumulocity/code/MbedSmartRest/#099f76422485 +http://mbed.org/users/Cumulocity/code/MbedSmartRest/#9a11a331e340
--- a/program.cpp Thu Jul 03 18:52:04 2014 +0000 +++ b/program.cpp Mon Jul 07 14:20:42 2014 +0000 @@ -35,7 +35,6 @@ void motionMeasurement(long deviceId, Aggregator& aggr); credentials_t credentials = {}; -char cDeviceIdentifier[48]; StaticData srtpl( // get device by identity @@ -72,7 +71,7 @@ float interval = 120.0; // send measurements every two minutes -MbedSmartRest client("developer.cumulocity.com", 80, credentials.username, credentials.password, cDeviceIdentifier); +MbedSmartRest client("developer.cumulocity.com", 80, credentials.username, credentials.password, TEMPLATE_DEVICE_IDENTIFIER); int program(void) { @@ -93,9 +92,6 @@ strcpy(credentials.password, CREDENTIALS_PASSWORD); #endif - // copy identifier into variable - strcpy(cDeviceIdentifier, TEMPLATE_DEVICE_IDENTIFIER); - lcd_tenant(credentials.username); puts("Hello!"); @@ -135,41 +131,20 @@ { uint8_t ret; - ComposedRecord record(false); + ComposedRecord record; ParsedRecord received; - CharValue deviceId(imei()); - IntegerValue connectMsgId(60); - IntegerValue pollMsgId(61); + + IntegerValue msgId(60); + CharValue identifier(imei()); + if ((!record.add(msgId)) || (!record.add(identifier))) + return false; // copy credentials strcpy(credentials.username, DEVICEBOOTSTRAP_USERNAME); strcpy(credentials.password, DEVICEBOOTSTRAP_PASSWORD); - record.add(connectMsgId); - record.add(deviceId); - - if (client.send(record) != SMARTREST_SUCCESS) { - puts("Could not connect to platform."); - client.stop(); - return false; - } - client.stop(); - - ret = client.receive(received); - if (ret == SMARTREST_SUCCESS) { - if ((received.values() > 0) && (received.value(0).integerValue() == 50)) - puts("Server error. Make sure to register the device before attempting a device bootstrap."); - else - puts("Unknown error."); - return false; - } - record.clear(); - - record.add(pollMsgId); - record.add(deviceId); - while (true) { - if (client.send(record) != SMARTREST_SUCCESS) { + if (client.send(record, "") != SMARTREST_SUCCESS) { puts("Connection unsuccessful. Retrying."); client.stop(); Thread::wait(2000); @@ -191,7 +166,7 @@ } if (received.value(0).integerValue() == 50) { - puts("No values. Retrying."); + puts("No credentials available yet. Retrying."); Thread::wait(2000); continue; }