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-25
- Revision:
- 48:d5e21301543e
- Parent:
- 47:89ae46d5c466
- Child:
- 49:ac0ba9d54ebc
File content as of revision 48:d5e21301543e:
#include "mbed.h" #include "rtos.h" #include "MDM.h" #include "GPS.h" #include "DeviceInfo.h" #include "MbedAgent.h" #include "apndb.h" #include "GPSTracker.h" int main() { MDMParser::DevStatus devStatus; int res; MDMSerial mdm; GPSI2C gps; //mdm.setDebug(4); if (!mdm.init(NULL, &devStatus)) { puts("Modem initialization failed. Check your PIN number."); return 1; } puts("Modem initialized"); /*if (!gps.init()) { puts("GPS initialization failed."); return 1; } puts("Gps initialized.");*/ DeviceIO io(gps); io.lcdPrint("DEVICE INIT"); /*if (io.resetButtonPressed()) { puts("Resetting program."); 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; } puts("Connected."); 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; }