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 42:104746744af8, committed 2014-07-24
- Comitter:
- Cumulocity
- Date:
- Thu Jul 24 14:17:07 2014 +0000
- Parent:
- 41:804f6a0bda26
- Child:
- 43:eff77697d88c
- Commit message:
- added telekom apn, minor improvements
Changed in this revision
--- a/DeviceBootstrap.cpp Tue Jul 15 12:44:34 2014 +0000 +++ b/DeviceBootstrap.cpp Thu Jul 24 14:17:07 2014 +0000 @@ -35,7 +35,7 @@ bool DeviceBootstrap::obtainFromStorage() { char buf[DEVICE_BOOTSTRAP_CREDENTIALS_LENGTH*2+2], *ptr; - + int res = _mdm.readFile(CREDENTIALS_FILE, buf, sizeof(buf)); if (res < 0) @@ -56,14 +56,16 @@ bool DeviceBootstrap::obtainFromPlatform() { uint8_t ret; - - printf("Starting device bootstrap with '%s'\n", _deviceInfo.imei()); + const char *id; + + id = _deviceInfo.imsi(); + printf("Starting device bootstrap with '%s'\n", id); ComposedRecord record; ParsedRecord recvdRecord; IntegerValue msgId(61); - CharValue identifier(_deviceInfo.imei()); + CharValue identifier(id); if ((!record.add(msgId)) || (!record.add(identifier))) return false; @@ -85,7 +87,11 @@ Thread::wait(2000); continue; } + _client.stop(); + for (size_t q = 0; q < recvdRecord.values(); q++) + puts(recvdRecord.rawValue(q)); + if ((recvdRecord.values() < 1) || (recvdRecord.value(0).integerValue() == 50)) { puts("No credentials available yet. Retrying.");
--- a/MbedAgent.cpp Tue Jul 15 12:44:34 2014 +0000 +++ b/MbedAgent.cpp Thu Jul 24 14:17:07 2014 +0000 @@ -1,7 +1,8 @@ #include "MbedAgent.h" #include "rtos.h" -MbedAgent::MbedAgent(MDMSerial& mdm, DeviceInfo& deviceInfo) : +MbedAgent::MbedAgent(DeviceIO& io, MDMSerial& mdm, DeviceInfo& deviceInfo) : + _io(io), _mdm(mdm), _deviceInfo(deviceInfo), _client(MBED_AGENT_HOST, MBED_AGENT_PORT, MBED_AGENT_DEVICE_IDENTIFIER),
--- a/MbedAgent.h Tue Jul 15 12:44:34 2014 +0000 +++ b/MbedAgent.h Thu Jul 24 14:17:07 2014 +0000 @@ -21,7 +21,7 @@ class MbedAgent { public: - MbedAgent(MDMSerial&, DeviceInfo&); + MbedAgent(DeviceIO&, MDMSerial&, DeviceInfo&); bool init(); bool run(); @@ -30,7 +30,7 @@ void loop(); private: - DeviceIO _io; + DeviceIO& _io; MDMSerial& _mdm; DeviceInfo& _deviceInfo; MbedSmartRest _client;
--- a/apndb.cpp Tue Jul 15 12:44:34 2014 +0000 +++ b/apndb.cpp Thu Jul 24 14:17:07 2014 +0000 @@ -3,19 +3,22 @@ #include "stdio.h" #include "string.h" -#define APNDB_COUNT 5 - // Contains all tuples apndb_t apndb[] = { - { .mcc = "204", .mnc = "04", .carrier = "Vodafone NL", .apn = "public4.m2minternet.com" } + { .mcc = "262", .mnc = "02", .carrier = "Telekom", .apn = "m2m.business" }, + { .mcc = "262", .mnc = "06", .carrier = "Telekom", .apn = "m2m.business" }, + { .mcc = "204", .mnc = "04", .carrier = "Vodafone NL", .apn = "public4.m2minternet.com" }, + { .mcc = NULL, .mnc = NULL, .carrier = NULL, .apn = NULL } // ending terminator }; apndb_t * apndb_get(const char * imsi) { char chr1[8], chr2[8]; size_t len; + size_t i; - for (size_t i = 0; i < APNDB_COUNT; i++) { + i = 0; + while (apndb[i].mcc != NULL) { strcpy(chr1, apndb[i].mcc); strcat(chr1, apndb[i].mnc); len = strlen(chr1); @@ -24,6 +27,7 @@ if (strcmp(chr1, chr2) == 0) return &apndb[i]; + i++; } return NULL;
--- a/main.cpp Tue Jul 15 12:44:34 2014 +0000 +++ b/main.cpp Thu Jul 24 14:17:07 2014 +0000 @@ -8,43 +8,54 @@ int main() { MDMParser::DevStatus devStatus; + DeviceIO io; + + io.lcdPrint("DEVICE INIT"); MDMSerial mdm; //mdm.setDebug(4); if (!mdm.init(NULL, &devStatus)) { puts("Modem initialization failed. Check your PIN number."); + io.lcdPrint("MODEM INIT FAILURE"); return 1; } + io.lcdPrint("IMEI", devStatus.imei); + + // print out basic device data + printf("IMEI: %s\n", devStatus.imei); + printf("IMSI: %s\n", devStatus.imsi); + puts("Searching for login..."); apndb_t *apn = apndb_get(devStatus.imsi); if (apn == NULL) { puts("No APN found. Stop."); + io.lcdPrint("NO APN FOUND"); return 1; } - // print out basic device data - printf("IMEI: %s\n", devStatus.imei); - printf("IMSI: %s\n", devStatus.imsi); - if (!mdm.registerNet()) { puts("Network registration failed."); + io.lcdPrint("NETWORK REG ERROR"); return 1; } printf("Carrier: %s\n", apn->carrier); puts("Joining Network."); + io.lcdPrint("JOINING CARRIER", apn->carrier); if (mdm.join(apn->apn) == NOIP) { + io.lcdPrint("NETWORK JOIN FAILURE"); puts("Could not join network. Make sure chosen carrier is correct and no credentials are required."); return 1; } DeviceInfo deviceInfo(mdm, devStatus); - MbedAgent agent(mdm, deviceInfo); + MbedAgent agent(io, mdm, deviceInfo); puts("Starting agent ..."); if (!agent.init()) { + io.lcdPrint("AGENT INIT FAILURE"); puts("Initialization failure."); mdm.disconnect(); return 1; @@ -53,6 +64,7 @@ size_t tries = 3; do { + io.lcdPrint("RUN AGENT"); puts("Running agent ..."); if (!agent.run()) {