Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
main.cpp
- Committer:
- Cumulocity
- Date:
- 2014-07-24
- Revision:
- 45:5d8feae26fe3
- Parent:
- 42:104746744af8
- Child:
- 46:f6976fd64387
File content as of revision 45:5d8feae26fe3:
#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; 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", 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; }