portable version of the cumulocity demo

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Cumulocity Official

Committer:
Cumulocity
Date:
Thu Jul 24 14:17:07 2014 +0000
Revision:
42:104746744af8
Parent:
41:804f6a0bda26
Child:
45:5d8feae26fe3
added telekom apn, minor improvements

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;
Cumulocity 42:104746744af8 11 DeviceIO io;
Cumulocity 42:104746744af8 12
Cumulocity 42:104746744af8 13 io.lcdPrint("DEVICE INIT");
vwochnik 15:0ccf0f530a05 14
vwochnik 32:56804dd00193 15 MDMSerial mdm;
vwochnik 34:8a0556f39161 16 //mdm.setDebug(4);
vwochnik 27:bfd402593acc 17
vwochnik 29:853741b9ea3b 18 if (!mdm.init(NULL, &devStatus)) {
vwochnik 28:2004400abeec 19 puts("Modem initialization failed. Check your PIN number.");
Cumulocity 42:104746744af8 20 io.lcdPrint("MODEM INIT FAILURE");
vwochnik 28:2004400abeec 21 return 1;
vwochnik 28:2004400abeec 22 }
vwochnik 28:2004400abeec 23
Cumulocity 42:104746744af8 24 io.lcdPrint("IMEI", devStatus.imei);
Cumulocity 42:104746744af8 25
Cumulocity 42:104746744af8 26 // print out basic device data
Cumulocity 42:104746744af8 27 printf("IMEI: %s\n", devStatus.imei);
Cumulocity 42:104746744af8 28 printf("IMSI: %s\n", devStatus.imsi);
Cumulocity 42:104746744af8 29
vwochnik 28:2004400abeec 30 puts("Searching for login...");
vwochnik 28:2004400abeec 31 apndb_t *apn = apndb_get(devStatus.imsi);
vwochnik 28:2004400abeec 32 if (apn == NULL) {
vwochnik 28:2004400abeec 33 puts("No APN found. Stop.");
Cumulocity 42:104746744af8 34 io.lcdPrint("NO APN FOUND");
vwochnik 28:2004400abeec 35 return 1;
vwochnik 4:363b4cc49445 36 }
vwochnik 29:853741b9ea3b 37
Cumulocity 41:804f6a0bda26 38 if (!mdm.registerNet()) {
vwochnik 32:56804dd00193 39 puts("Network registration failed.");
Cumulocity 42:104746744af8 40 io.lcdPrint("NETWORK REG ERROR");
vwochnik 28:2004400abeec 41 return 1;
vwochnik 28:2004400abeec 42 }
vwochnik 28:2004400abeec 43
vwochnik 29:853741b9ea3b 44 printf("Carrier: %s\n", apn->carrier);
vwochnik 28:2004400abeec 45 puts("Joining Network.");
Cumulocity 42:104746744af8 46 io.lcdPrint("JOINING CARRIER", apn->carrier);
vwochnik 29:853741b9ea3b 47 if (mdm.join(apn->apn) == NOIP) {
Cumulocity 42:104746744af8 48 io.lcdPrint("NETWORK JOIN FAILURE");
vwochnik 29:853741b9ea3b 49 puts("Could not join network. Make sure chosen carrier is correct and no credentials are required.");
vwochnik 28:2004400abeec 50 return 1;
vwochnik 28:2004400abeec 51 }
vwochnik 23:0a48eebaaba8 52
Cumulocity 41:804f6a0bda26 53 DeviceInfo deviceInfo(mdm, devStatus);
Cumulocity 42:104746744af8 54 MbedAgent agent(io, mdm, deviceInfo);
vwochnik 4:363b4cc49445 55
Cumulocity 41:804f6a0bda26 56 puts("Starting agent ...");
Cumulocity 41:804f6a0bda26 57 if (!agent.init()) {
Cumulocity 42:104746744af8 58 io.lcdPrint("AGENT INIT FAILURE");
Cumulocity 41:804f6a0bda26 59 puts("Initialization failure.");
Cumulocity 41:804f6a0bda26 60 mdm.disconnect();
Cumulocity 41:804f6a0bda26 61 return 1;
Cumulocity 41:804f6a0bda26 62 }
vwochnik 8:940c782eec5e 63
Cumulocity 41:804f6a0bda26 64 size_t tries = 3;
Cumulocity 41:804f6a0bda26 65
vwochnik 8:940c782eec5e 66 do {
Cumulocity 42:104746744af8 67 io.lcdPrint("RUN AGENT");
Cumulocity 41:804f6a0bda26 68 puts("Running agent ...");
Cumulocity 41:804f6a0bda26 69
Cumulocity 41:804f6a0bda26 70 if (!agent.run()) {
Cumulocity 41:804f6a0bda26 71 puts("Agent failure.");
Cumulocity 41:804f6a0bda26 72 continue;
Cumulocity 41:804f6a0bda26 73 } else {
Cumulocity 41:804f6a0bda26 74 break;
Cumulocity 41:804f6a0bda26 75 }
Cumulocity 41:804f6a0bda26 76 } while (--tries > 0);
vwochnik 32:56804dd00193 77
vwochnik 30:daa499571db7 78 mdm.disconnect();
vwochnik 8:940c782eec5e 79 return 0;
vwochnik 4:363b4cc49445 80 }