Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
Diff: DeviceBootstrap.cpp
- Revision:
- 52:8f1370084268
- Parent:
- 49:ac0ba9d54ebc
- Child:
- 55:a0f7295ed6b6
--- a/DeviceBootstrap.cpp Tue Jul 29 17:53:43 2014 +0000 +++ b/DeviceBootstrap.cpp Wed Aug 13 10:55:11 2014 +0000 @@ -8,9 +8,10 @@ #include "IntegerValue.h" #include "ParsedRecord.h" -DeviceBootstrap::DeviceBootstrap(SmartRest& client, MDMSerial& mdm, DeviceInfo& deviceInfo) : +DeviceBootstrap::DeviceBootstrap(SmartRest& client, MDMSerial& mdm, DeviceIO& io, DeviceInfo& deviceInfo) : _client(client), _mdm(mdm), + _io(io), _deviceInfo(deviceInfo) { *_username = *_password = '\0'; @@ -26,7 +27,6 @@ puts("Warning: Could not write credentials to file!"); } - printf("Credentials: %s : %s\n", _username, _password); if (_client.setAuthorization(_username, _password) != SMARTREST_SUCCESS) return false; return true; @@ -65,16 +65,13 @@ bool DeviceBootstrap::obtainFromPlatform() { uint8_t ret; - const char *id; - - id = _deviceInfo.imei(); - printf("Starting device bootstrap with '%s'\n", id); + uint8_t tries; ComposedRecord record; ParsedRecord recvdRecord; IntegerValue msgId(61); - CharValue identifier(id); + CharValue identifier(_deviceInfo.imei()); if ((!record.add(msgId)) || (!record.add(identifier))) return false; @@ -82,16 +79,17 @@ if (_client.setAuthorization(DEVICE_BOOTSTRAP_USERNAME, DEVICE_BOOTSTRAP_PASSWORD) != SMARTREST_SUCCESS) return false; - while (true) { + _io.lcdPrint("BOOTSTRAP", _deviceInfo.imei()); + + tries = 255; + do { if (_client.send(record, "") != SMARTREST_SUCCESS) { - puts("Connection unsuccessful. Retrying."); _client.stop(); Thread::wait(2000); continue; } if (_client.receive(recvdRecord) != SMARTREST_SUCCESS) { - puts("Receiving failure."); _client.stop(); Thread::wait(2000); continue; @@ -103,14 +101,12 @@ if ((recvdRecord.values() < 1) || (recvdRecord.value(0).integerValue() == 50)) { - puts("No credentials available yet. Retrying."); Thread::wait(2000); continue; } if ((recvdRecord.value(0).integerValue() != 70) || (recvdRecord.values() != 6)) { - puts("Bad credentials received."); return false; } @@ -118,8 +114,12 @@ recvdRecord.value(4).characterValue(), recvdRecord.value(5).characterValue()); + _io.lcdPrint("BOOTSTRAP SUCCESSFUL", _username, _password); + return true; - } + } while (--tries > 0); + + _io.lcdPrint("BOOTSTRAP FAILURE"); return false; }