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:
vwochnik
Date:
Sat Dec 06 19:47:23 2014 +0000
Revision:
68:0dc778a16d0d
Parent:
67:c360a2b2c948
Child:
71:063c45e99578
configuration for interval

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"
vwochnik 67:c360a2b2c948 6 #include "DeviceMemory.h"
Cumulocity 41:804f6a0bda26 7 #include "MbedAgent.h"
Cumulocity 47:89ae46d5c466 8 #include "GPSTracker.h"
vwochnik 0:ed4d6fd405ea 9
vwochnik 68:0dc778a16d0d 10 #include "DeviceConfiguration.h"
vwochnik 68:0dc778a16d0d 11
vwochnik 67:c360a2b2c948 12 #include <stdio.h>
vwochnik 67:c360a2b2c948 13
vwochnik 52:8f1370084268 14 /**
vwochnik 52:8f1370084268 15 * SIM PIN. Null for no pin.
vwochnik 52:8f1370084268 16 */
vwochnik 52:8f1370084268 17 #define SIM_PIN NULL
vwochnik 52:8f1370084268 18
vwochnik 52:8f1370084268 19 /**
vwochnik 52:8f1370084268 20 * SIM GPRS login data. Leave commented out for automatic setting.
vwochnik 52:8f1370084268 21 */
vwochnik 52:8f1370084268 22 //#define SIM_APN ""
vwochnik 52:8f1370084268 23 //#define SIM_USER ""
vwochnik 52:8f1370084268 24 //#define SIM_PASS ""
vwochnik 52:8f1370084268 25
vwochnik 0:ed4d6fd405ea 26 int main()
vwochnik 0:ed4d6fd405ea 27 {
Cumulocity 41:804f6a0bda26 28 MDMParser::DevStatus devStatus;
Cumulocity 46:f6976fd64387 29 int res;
vwochnik 52:8f1370084268 30 uint8_t status = 0;
Cumulocity 42:104746744af8 31
vwochnik 55:a0f7295ed6b6 32 MDMRtos<MDMSerial> mdm;
Cumulocity 47:89ae46d5c466 33 GPSI2C gps;
vwochnik 58:4cc0ae5a7058 34
vwochnik 68:0dc778a16d0d 35 //mdm.setDebug(4);
vwochnik 27:bfd402593acc 36
vwochnik 52:8f1370084268 37 if (!mdm.init(SIM_PIN, &devStatus))
vwochnik 52:8f1370084268 38 status = 1;
vwochnik 52:8f1370084268 39 else if (!gps.init())
vwochnik 52:8f1370084268 40 status = 2;
Cumulocity 47:89ae46d5c466 41
Cumulocity 47:89ae46d5c466 42 DeviceIO io(gps);
vwochnik 52:8f1370084268 43
vwochnik 52:8f1370084268 44 switch (status) {
vwochnik 52:8f1370084268 45 case 1:
vwochnik 55:a0f7295ed6b6 46 io.lcdPrint("MODEM INIT FAILURE", "CHECK SIM");
vwochnik 52:8f1370084268 47 break;
vwochnik 52:8f1370084268 48 case 2:
vwochnik 52:8f1370084268 49 io.lcdPrint("GPS INIT FAILURE");
vwochnik 52:8f1370084268 50 break;
vwochnik 52:8f1370084268 51 }
vwochnik 52:8f1370084268 52
vwochnik 52:8f1370084268 53 if (status != 0)
vwochnik 52:8f1370084268 54 goto error;
vwochnik 52:8f1370084268 55
Cumulocity 47:89ae46d5c466 56 io.lcdPrint("DEVICE INIT");
Cumulocity 46:f6976fd64387 57
vwochnik 55:a0f7295ed6b6 58 io.lcdPrint("REGISTER NETWORK", "IMEI", devStatus.imei);
Cumulocity 42:104746744af8 59
Cumulocity 41:804f6a0bda26 60 if (!mdm.registerNet()) {
Cumulocity 42:104746744af8 61 io.lcdPrint("NETWORK REG ERROR");
vwochnik 52:8f1370084268 62 goto error;
vwochnik 28:2004400abeec 63 }
vwochnik 28:2004400abeec 64
vwochnik 55:a0f7295ed6b6 65 io.lcdPrint("JOIN NETWORK");
vwochnik 52:8f1370084268 66 #ifdef SIM_APN
vwochnik 52:8f1370084268 67 if (mdm.join(SIM_APN, SIM_USER, SIM_PASS) == NOIP) {
vwochnik 55:a0f7295ed6b6 68 #else
vwochnik 55:a0f7295ed6b6 69 if (mdm.join() == NOIP) {
vwochnik 55:a0f7295ed6b6 70 #endif
vwochnik 52:8f1370084268 71 io.lcdPrint("NETWORK JOIN FAILURE");
vwochnik 52:8f1370084268 72 goto error;
vwochnik 52:8f1370084268 73 }
vwochnik 8:940c782eec5e 74
vwochnik 52:8f1370084268 75 {
vwochnik 52:8f1370084268 76 uint8_t tries;
vwochnik 52:8f1370084268 77 DeviceInfo deviceInfo(mdm, devStatus);
vwochnik 67:c360a2b2c948 78 DeviceMemory deviceMemory(mdm);
vwochnik 67:c360a2b2c948 79
vwochnik 67:c360a2b2c948 80 if (io.resetButtonPressed()) {
vwochnik 67:c360a2b2c948 81 if (deviceMemory.resetPlatformCredentials())
vwochnik 67:c360a2b2c948 82 io.deviceFeedback().beepSuccess();
vwochnik 67:c360a2b2c948 83 else
vwochnik 67:c360a2b2c948 84 io.deviceFeedback().beepFailure();
vwochnik 67:c360a2b2c948 85 Thread::wait(1000);
vwochnik 67:c360a2b2c948 86 return;
vwochnik 67:c360a2b2c948 87 }
vwochnik 67:c360a2b2c948 88
vwochnik 67:c360a2b2c948 89 MbedAgent agent(io, mdm, deviceInfo, deviceMemory);
vwochnik 52:8f1370084268 90
vwochnik 52:8f1370084268 91 io.lcdPrint("AGENT INIT");
vwochnik 52:8f1370084268 92 if (!agent.init()) {
vwochnik 52:8f1370084268 93 io.lcdPrint("AGENT INIT FAILURE");
vwochnik 52:8f1370084268 94 goto error;
vwochnik 52:8f1370084268 95 }
vwochnik 52:8f1370084268 96
vwochnik 52:8f1370084268 97 tries = 3;
vwochnik 52:8f1370084268 98 do {
vwochnik 52:8f1370084268 99 io.lcdPrint("AGENT RUN");
vwochnik 52:8f1370084268 100 if (agent.run())
vwochnik 52:8f1370084268 101 break;
vwochnik 52:8f1370084268 102 } while (--tries > 0);
Cumulocity 41:804f6a0bda26 103
vwochnik 52:8f1370084268 104 if (tries == 0) {
vwochnik 52:8f1370084268 105 io.lcdPrint("AGENT RUN FAILURE");
vwochnik 52:8f1370084268 106 goto error;
Cumulocity 41:804f6a0bda26 107 }
vwochnik 52:8f1370084268 108 }
vwochnik 32:56804dd00193 109
vwochnik 30:daa499571db7 110 mdm.disconnect();
vwochnik 8:940c782eec5e 111 return 0;
vwochnik 52:8f1370084268 112
vwochnik 52:8f1370084268 113 error:
vwochnik 52:8f1370084268 114 mdm.disconnect();
vwochnik 52:8f1370084268 115 return 1;
vwochnik 4:363b4cc49445 116 }