Own fork of MbedSmartRestMain

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Cumulocity Official

Committer:
Cumulocity
Date:
Tue Jul 15 12:44:34 2014 +0000
Revision:
41:804f6a0bda26
Parent:
34:8a0556f39161
Child:
42:104746744af8
refactoring of mbed agent

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Cumulocity 41:804f6a0bda26 1 #include "mbed.h"
Cumulocity 41:804f6a0bda26 2 #include "rtos.h"
Cumulocity 41:804f6a0bda26 3 #include "MDM.h"
Cumulocity 41:804f6a0bda26 4 #include "DeviceInfo.h"
Cumulocity 41:804f6a0bda26 5 #include "MbedAgent.h"
vwochnik 23:0a48eebaaba8 6 #include "apndb.h"
vwochnik 0:ed4d6fd405ea 7
vwochnik 0:ed4d6fd405ea 8 int main()
vwochnik 0:ed4d6fd405ea 9 {
Cumulocity 41:804f6a0bda26 10 MDMParser::DevStatus devStatus;
vwochnik 15:0ccf0f530a05 11
vwochnik 32:56804dd00193 12 MDMSerial mdm;
vwochnik 34:8a0556f39161 13 //mdm.setDebug(4);
vwochnik 27:bfd402593acc 14
vwochnik 29:853741b9ea3b 15 if (!mdm.init(NULL, &devStatus)) {
vwochnik 28:2004400abeec 16 puts("Modem initialization failed. Check your PIN number.");
vwochnik 28:2004400abeec 17 return 1;
vwochnik 28:2004400abeec 18 }
vwochnik 28:2004400abeec 19
vwochnik 28:2004400abeec 20 puts("Searching for login...");
vwochnik 28:2004400abeec 21 apndb_t *apn = apndb_get(devStatus.imsi);
vwochnik 28:2004400abeec 22 if (apn == NULL) {
vwochnik 28:2004400abeec 23 puts("No APN found. Stop.");
vwochnik 28:2004400abeec 24 return 1;
vwochnik 4:363b4cc49445 25 }
vwochnik 29:853741b9ea3b 26
vwochnik 29:853741b9ea3b 27 // print out basic device data
vwochnik 29:853741b9ea3b 28 printf("IMEI: %s\n", devStatus.imei);
vwochnik 29:853741b9ea3b 29 printf("IMSI: %s\n", devStatus.imsi);
vwochnik 24:8f9b678a7932 30
Cumulocity 41:804f6a0bda26 31 if (!mdm.registerNet()) {
vwochnik 32:56804dd00193 32 puts("Network registration failed.");
vwochnik 28:2004400abeec 33 return 1;
vwochnik 28:2004400abeec 34 }
vwochnik 28:2004400abeec 35
vwochnik 29:853741b9ea3b 36 printf("Carrier: %s\n", apn->carrier);
vwochnik 28:2004400abeec 37 puts("Joining Network.");
vwochnik 29:853741b9ea3b 38 if (mdm.join(apn->apn) == NOIP) {
vwochnik 29:853741b9ea3b 39 puts("Could not join network. Make sure chosen carrier is correct and no credentials are required.");
vwochnik 28:2004400abeec 40 return 1;
vwochnik 28:2004400abeec 41 }
vwochnik 23:0a48eebaaba8 42
Cumulocity 41:804f6a0bda26 43 DeviceInfo deviceInfo(mdm, devStatus);
Cumulocity 41:804f6a0bda26 44 MbedAgent agent(mdm, deviceInfo);
vwochnik 4:363b4cc49445 45
Cumulocity 41:804f6a0bda26 46 puts("Starting agent ...");
Cumulocity 41:804f6a0bda26 47 if (!agent.init()) {
Cumulocity 41:804f6a0bda26 48 puts("Initialization failure.");
Cumulocity 41:804f6a0bda26 49 mdm.disconnect();
Cumulocity 41:804f6a0bda26 50 return 1;
Cumulocity 41:804f6a0bda26 51 }
vwochnik 8:940c782eec5e 52
Cumulocity 41:804f6a0bda26 53 size_t tries = 3;
Cumulocity 41:804f6a0bda26 54
vwochnik 8:940c782eec5e 55 do {
Cumulocity 41:804f6a0bda26 56 puts("Running agent ...");
Cumulocity 41:804f6a0bda26 57
Cumulocity 41:804f6a0bda26 58 if (!agent.run()) {
Cumulocity 41:804f6a0bda26 59 puts("Agent failure.");
Cumulocity 41:804f6a0bda26 60 continue;
Cumulocity 41:804f6a0bda26 61 } else {
Cumulocity 41:804f6a0bda26 62 break;
Cumulocity 41:804f6a0bda26 63 }
Cumulocity 41:804f6a0bda26 64 } while (--tries > 0);
vwochnik 32:56804dd00193 65
vwochnik 30:daa499571db7 66 mdm.disconnect();
vwochnik 8:940c782eec5e 67 return 0;
vwochnik 4:363b4cc49445 68 }