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 46:f6976fd64387, committed 2014-07-24
- Comitter:
- Cumulocity
- Date:
- Thu Jul 24 16:02:47 2014 +0000
- Parent:
- 45:5d8feae26fe3
- Child:
- 47:89ae46d5c466
- Commit message:
- implement device credential reset; show username/password on display
Changed in this revision
--- a/DeviceBootstrap.cpp Thu Jul 24 14:52:44 2014 +0000 +++ b/DeviceBootstrap.cpp Thu Jul 24 16:02:47 2014 +0000 @@ -32,6 +32,16 @@ return true; } +const char * DeviceBootstrap::username() +{ + return _username; +} + +const char * DeviceBootstrap::password() +{ + return _password; +} + bool DeviceBootstrap::obtainFromStorage() { char buf[DEVICE_BOOTSTRAP_CREDENTIALS_LENGTH*2+2], *ptr;
--- a/DeviceBootstrap.h Thu Jul 24 14:52:44 2014 +0000 +++ b/DeviceBootstrap.h Thu Jul 24 16:02:47 2014 +0000 @@ -22,6 +22,8 @@ DeviceBootstrap(SmartRest&, MDMSerial&, DeviceInfo&); bool setUpCredentials(); + const char * username(); + const char * password(); protected: bool obtainFromStorage();
--- a/DeviceIO.cpp Thu Jul 24 14:52:44 2014 +0000 +++ b/DeviceIO.cpp Thu Jul 24 16:02:47 2014 +0000 @@ -1,12 +1,18 @@ #include "DeviceIO.h" DeviceIO::DeviceIO() : + _resetButton(D4), // fire button on arduino app shield _temperatureSensor(SDA,SCL), _accelerometer(SDA,SCL), _lcd(D11, D13, D12, D7, D10) { } +bool DeviceIO::resetButtonPressed() +{ + return _resetButton; +} + LM75B& DeviceIO::temperatureSensor() { return _temperatureSensor;
--- a/DeviceIO.h Thu Jul 24 14:52:44 2014 +0000 +++ b/DeviceIO.h Thu Jul 24 16:02:47 2014 +0000 @@ -37,11 +37,13 @@ public: DeviceIO(); + bool resetButtonPressed(); LM75B& temperatureSensor(); MMA7660& accelerometer(); void lcdPrint(const char*, const char* = NULL, const char* = NULL); private: + DigitalIn _resetButton; LM75B _temperatureSensor; MMA7660 _accelerometer; C12832 _lcd;
--- a/MbedAgent.cpp Thu Jul 24 14:52:44 2014 +0000 +++ b/MbedAgent.cpp Thu Jul 24 16:02:47 2014 +0000 @@ -32,9 +32,12 @@ // device bootstrapping process _io.lcdPrint("BOOTSTRAP", _deviceInfo.imei()); if (!_bootstrap.setUpCredentials()) { + _io.lcdPrint("BOOTSTRAP FAILURE"); puts("Could not obtain credentials."); return false; } + _io.lcdPrint("BOOTSTRAP SUCCESSFUL", _bootstrap.username(), _bootstrap.password()); + Thread::wait(5000); _io.lcdPrint("INTEGRATION"); if (!_integration.integrate()) {
--- a/main.cpp Thu Jul 24 14:52:44 2014 +0000 +++ b/main.cpp Thu Jul 24 16:02:47 2014 +0000 @@ -9,6 +9,7 @@ { MDMParser::DevStatus devStatus; DeviceIO io; + int res; io.lcdPrint("DEVICE INIT"); @@ -20,6 +21,18 @@ io.lcdPrint("MODEM INIT FAILURE"); return 1; } + + if (io.resetButtonPressed()) { + res = mdm.delFile("001_CREDENTIALS"); + if (res < 0) { + puts("Credential reset failed."); + io.lcdPrint("CREDENTIAL RESET", "FAILURE", "PLEASE RESTART DEVICE"); + } else { + puts("Credential reset successful."); + io.lcdPrint("CREDENTIAL RESET", "SUCCESS", "PLEASE RESTART DEVICE"); + } + return 0; + } io.lcdPrint("IMEI", devStatus.imei); @@ -31,7 +44,7 @@ apndb_t *apn = apndb_get(devStatus.imsi); if (apn == NULL) { puts("No APN found. Stop."); - io.lcdPrint("NO APN FOUND", devStatus.imsi); + io.lcdPrint("NO APN FOUND", "IMEI:", devStatus.imsi); return 1; }