Official reference client implementation for Cumulocity SmartREST on u-blox C027.

Dependencies:   C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed

Fork of MbedSmartRestMain by Vincent Wochnik

Committer:
Cumulocity
Date:
Fri Jul 25 20:16:32 2014 +0000
Revision:
48:d5e21301543e
Parent:
47:89ae46d5c466
Child:
49:ac0ba9d54ebc
comment out reset functionality

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 47:89ae46d5c466 4 #include "GPS.h"
Cumulocity 41:804f6a0bda26 5 #include "DeviceInfo.h"
Cumulocity 41:804f6a0bda26 6 #include "MbedAgent.h"
vwochnik 23:0a48eebaaba8 7 #include "apndb.h"
Cumulocity 47:89ae46d5c466 8 #include "GPSTracker.h"
vwochnik 0:ed4d6fd405ea 9
vwochnik 0:ed4d6fd405ea 10 int main()
vwochnik 0:ed4d6fd405ea 11 {
Cumulocity 41:804f6a0bda26 12 MDMParser::DevStatus devStatus;
Cumulocity 46:f6976fd64387 13 int res;
Cumulocity 42:104746744af8 14
vwochnik 32:56804dd00193 15 MDMSerial mdm;
Cumulocity 47:89ae46d5c466 16 GPSI2C gps;
vwochnik 34:8a0556f39161 17 //mdm.setDebug(4);
vwochnik 27:bfd402593acc 18
vwochnik 29:853741b9ea3b 19 if (!mdm.init(NULL, &devStatus)) {
vwochnik 28:2004400abeec 20 puts("Modem initialization failed. Check your PIN number.");
Cumulocity 47:89ae46d5c466 21 return 1;
Cumulocity 47:89ae46d5c466 22 }
Cumulocity 47:89ae46d5c466 23 puts("Modem initialized");
Cumulocity 47:89ae46d5c466 24
Cumulocity 47:89ae46d5c466 25 /*if (!gps.init()) {
Cumulocity 47:89ae46d5c466 26 puts("GPS initialization failed.");
vwochnik 28:2004400abeec 27 return 1;
vwochnik 28:2004400abeec 28 }
Cumulocity 47:89ae46d5c466 29 puts("Gps initialized.");*/
Cumulocity 47:89ae46d5c466 30
Cumulocity 47:89ae46d5c466 31 DeviceIO io(gps);
Cumulocity 47:89ae46d5c466 32 io.lcdPrint("DEVICE INIT");
Cumulocity 46:f6976fd64387 33
Cumulocity 48:d5e21301543e 34 /*if (io.resetButtonPressed()) {
Cumulocity 47:89ae46d5c466 35 puts("Resetting program.");
Cumulocity 46:f6976fd64387 36 res = mdm.delFile("001_CREDENTIALS");
Cumulocity 46:f6976fd64387 37 if (res < 0) {
Cumulocity 46:f6976fd64387 38 puts("Credential reset failed.");
Cumulocity 46:f6976fd64387 39 io.lcdPrint("CREDENTIAL RESET", "FAILURE", "PLEASE RESTART DEVICE");
Cumulocity 46:f6976fd64387 40 } else {
Cumulocity 46:f6976fd64387 41 puts("Credential reset successful.");
Cumulocity 46:f6976fd64387 42 io.lcdPrint("CREDENTIAL RESET", "SUCCESS", "PLEASE RESTART DEVICE");
Cumulocity 46:f6976fd64387 43 }
Cumulocity 46:f6976fd64387 44 return 0;
Cumulocity 48:d5e21301543e 45 }*/
vwochnik 28:2004400abeec 46
Cumulocity 42:104746744af8 47 io.lcdPrint("IMEI", devStatus.imei);
Cumulocity 42:104746744af8 48
Cumulocity 42:104746744af8 49 // print out basic device data
Cumulocity 42:104746744af8 50 printf("IMEI: %s\n", devStatus.imei);
Cumulocity 42:104746744af8 51 printf("IMSI: %s\n", devStatus.imsi);
Cumulocity 42:104746744af8 52
vwochnik 28:2004400abeec 53 puts("Searching for login...");
vwochnik 28:2004400abeec 54 apndb_t *apn = apndb_get(devStatus.imsi);
vwochnik 28:2004400abeec 55 if (apn == NULL) {
vwochnik 28:2004400abeec 56 puts("No APN found. Stop.");
Cumulocity 46:f6976fd64387 57 io.lcdPrint("NO APN FOUND", "IMEI:", devStatus.imsi);
vwochnik 28:2004400abeec 58 return 1;
vwochnik 4:363b4cc49445 59 }
Cumulocity 47:89ae46d5c466 60 puts("Connected.");
vwochnik 29:853741b9ea3b 61
Cumulocity 41:804f6a0bda26 62 if (!mdm.registerNet()) {
vwochnik 32:56804dd00193 63 puts("Network registration failed.");
Cumulocity 42:104746744af8 64 io.lcdPrint("NETWORK REG ERROR");
vwochnik 28:2004400abeec 65 return 1;
vwochnik 28:2004400abeec 66 }
vwochnik 28:2004400abeec 67
vwochnik 29:853741b9ea3b 68 printf("Carrier: %s\n", apn->carrier);
vwochnik 28:2004400abeec 69 puts("Joining Network.");
Cumulocity 42:104746744af8 70 io.lcdPrint("JOINING CARRIER", apn->carrier);
vwochnik 29:853741b9ea3b 71 if (mdm.join(apn->apn) == NOIP) {
Cumulocity 42:104746744af8 72 io.lcdPrint("NETWORK JOIN FAILURE");
vwochnik 29:853741b9ea3b 73 puts("Could not join network. Make sure chosen carrier is correct and no credentials are required.");
vwochnik 28:2004400abeec 74 return 1;
vwochnik 28:2004400abeec 75 }
vwochnik 23:0a48eebaaba8 76
Cumulocity 41:804f6a0bda26 77 DeviceInfo deviceInfo(mdm, devStatus);
Cumulocity 42:104746744af8 78 MbedAgent agent(io, mdm, deviceInfo);
vwochnik 4:363b4cc49445 79
Cumulocity 41:804f6a0bda26 80 puts("Starting agent ...");
Cumulocity 41:804f6a0bda26 81 if (!agent.init()) {
Cumulocity 42:104746744af8 82 io.lcdPrint("AGENT INIT FAILURE");
Cumulocity 41:804f6a0bda26 83 puts("Initialization failure.");
Cumulocity 41:804f6a0bda26 84 mdm.disconnect();
Cumulocity 41:804f6a0bda26 85 return 1;
Cumulocity 41:804f6a0bda26 86 }
vwochnik 8:940c782eec5e 87
Cumulocity 41:804f6a0bda26 88 size_t tries = 3;
Cumulocity 41:804f6a0bda26 89
vwochnik 8:940c782eec5e 90 do {
Cumulocity 42:104746744af8 91 io.lcdPrint("RUN AGENT");
Cumulocity 41:804f6a0bda26 92 puts("Running agent ...");
Cumulocity 41:804f6a0bda26 93
Cumulocity 41:804f6a0bda26 94 if (!agent.run()) {
Cumulocity 41:804f6a0bda26 95 puts("Agent failure.");
Cumulocity 41:804f6a0bda26 96 continue;
Cumulocity 41:804f6a0bda26 97 } else {
Cumulocity 41:804f6a0bda26 98 break;
Cumulocity 41:804f6a0bda26 99 }
Cumulocity 41:804f6a0bda26 100 } while (--tries > 0);
vwochnik 32:56804dd00193 101
vwochnik 30:daa499571db7 102 mdm.disconnect();
vwochnik 8:940c782eec5e 103 return 0;
vwochnik 4:363b4cc49445 104 }