![](/media/cache/group/u-blox_logo_trans.png.50x50_q85.png)
portable version of the cumulocity demo
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
main.cpp
- Committer:
- Cumulocity
- Date:
- 2014-07-24
- Revision:
- 46:f6976fd64387
- Parent:
- 45:5d8feae26fe3
- Child:
- 47:89ae46d5c466
File content as of revision 46:f6976fd64387:
#include "mbed.h" #include "rtos.h" #include "MDM.h" #include "DeviceInfo.h" #include "MbedAgent.h" #include "apndb.h" int main() { MDMParser::DevStatus devStatus; DeviceIO io; int res; 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; } 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); // 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", "IMEI:", devStatus.imsi); return 1; } 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(io, mdm, deviceInfo); puts("Starting agent ..."); if (!agent.init()) { io.lcdPrint("AGENT INIT FAILURE"); puts("Initialization failure."); mdm.disconnect(); return 1; } size_t tries = 3; do { io.lcdPrint("RUN AGENT"); puts("Running agent ..."); if (!agent.run()) { puts("Agent failure."); continue; } else { break; } } while (--tries > 0); mdm.disconnect(); return 0; }