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:
xinlei
Date:
Mon Feb 16 09:17:30 2015 +0000
Revision:
71:063c45e99578
Parent:
68:0dc778a16d0d
Child:
72:c5709ae7b193
Various minor bug fixes

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;
xinlei 71:063c45e99578 34 DeviceIO io(gps);
vwochnik 58:4cc0ae5a7058 35
vwochnik 68:0dc778a16d0d 36 //mdm.setDebug(4);
xinlei 71:063c45e99578 37 io.lcdPrint("Device Init");
vwochnik 52:8f1370084268 38 if (!mdm.init(SIM_PIN, &devStatus))
vwochnik 52:8f1370084268 39 status = 1;
vwochnik 52:8f1370084268 40 else if (!gps.init())
vwochnik 52:8f1370084268 41 status = 2;
Cumulocity 47:89ae46d5c466 42
vwochnik 52:8f1370084268 43 switch (status) {
vwochnik 52:8f1370084268 44 case 1:
xinlei 71:063c45e99578 45 io.lcdPrint("Modem Init Failure", "Check SIM");
vwochnik 52:8f1370084268 46 break;
vwochnik 52:8f1370084268 47 case 2:
xinlei 71:063c45e99578 48 io.lcdPrint("GPS Init Failure");
vwochnik 52:8f1370084268 49 break;
vwochnik 52:8f1370084268 50 }
vwochnik 52:8f1370084268 51
vwochnik 52:8f1370084268 52 if (status != 0)
vwochnik 52:8f1370084268 53 goto error;
vwochnik 52:8f1370084268 54
Cumulocity 46:f6976fd64387 55
xinlei 71:063c45e99578 56 io.lcdPrint("Register Network", "IMEI", devStatus.imei);
Cumulocity 42:104746744af8 57
Cumulocity 41:804f6a0bda26 58 if (!mdm.registerNet()) {
xinlei 71:063c45e99578 59 io.lcdPrint("Network Reg Error");
vwochnik 52:8f1370084268 60 goto error;
vwochnik 28:2004400abeec 61 }
vwochnik 28:2004400abeec 62
xinlei 71:063c45e99578 63 io.lcdPrint("Join Network");
vwochnik 52:8f1370084268 64 #ifdef SIM_APN
vwochnik 52:8f1370084268 65 if (mdm.join(SIM_APN, SIM_USER, SIM_PASS) == NOIP) {
vwochnik 55:a0f7295ed6b6 66 #else
vwochnik 55:a0f7295ed6b6 67 if (mdm.join() == NOIP) {
vwochnik 55:a0f7295ed6b6 68 #endif
xinlei 71:063c45e99578 69 io.lcdPrint("Network join failure");
vwochnik 52:8f1370084268 70 goto error;
vwochnik 52:8f1370084268 71 }
vwochnik 8:940c782eec5e 72
vwochnik 52:8f1370084268 73 {
vwochnik 52:8f1370084268 74 uint8_t tries;
vwochnik 52:8f1370084268 75 DeviceInfo deviceInfo(mdm, devStatus);
vwochnik 67:c360a2b2c948 76 DeviceMemory deviceMemory(mdm);
vwochnik 67:c360a2b2c948 77
vwochnik 67:c360a2b2c948 78 if (io.resetButtonPressed()) {
xinlei 71:063c45e99578 79 io.lcdPrint("Factory Reset");
xinlei 71:063c45e99578 80 if (deviceMemory.resetPlatformCredentials()) {
xinlei 71:063c45e99578 81 // io.deviceFeedback().beepSuccess();
xinlei 71:063c45e99578 82 io.lcdPrint("Reset Success");
xinlei 71:063c45e99578 83 }
xinlei 71:063c45e99578 84 else {
xinlei 71:063c45e99578 85 // io.deviceFeedback().beepFailure();
xinlei 71:063c45e99578 86 io.lcdPrint("Reset Failure");
xinlei 71:063c45e99578 87 }
xinlei 71:063c45e99578 88 // Thread::wait(1000);
vwochnik 67:c360a2b2c948 89 return;
vwochnik 67:c360a2b2c948 90 }
vwochnik 67:c360a2b2c948 91
vwochnik 67:c360a2b2c948 92 MbedAgent agent(io, mdm, deviceInfo, deviceMemory);
vwochnik 52:8f1370084268 93
xinlei 71:063c45e99578 94 io.lcdPrint("Agent Init");
vwochnik 52:8f1370084268 95 if (!agent.init()) {
xinlei 71:063c45e99578 96 io.lcdPrint("Agent Init Failure");
vwochnik 52:8f1370084268 97 goto error;
vwochnik 52:8f1370084268 98 }
vwochnik 52:8f1370084268 99
vwochnik 52:8f1370084268 100 tries = 3;
vwochnik 52:8f1370084268 101 do {
xinlei 71:063c45e99578 102 // io.lcdPrint("AGENT RUN");
xinlei 71:063c45e99578 103 puts("R");
vwochnik 52:8f1370084268 104 if (agent.run())
vwochnik 52:8f1370084268 105 break;
vwochnik 52:8f1370084268 106 } while (--tries > 0);
Cumulocity 41:804f6a0bda26 107
vwochnik 52:8f1370084268 108 if (tries == 0) {
xinlei 71:063c45e99578 109 io.lcdPrint("Agent Run Failure");
vwochnik 52:8f1370084268 110 goto error;
Cumulocity 41:804f6a0bda26 111 }
vwochnik 52:8f1370084268 112 }
vwochnik 32:56804dd00193 113
vwochnik 30:daa499571db7 114 mdm.disconnect();
vwochnik 8:940c782eec5e 115 return 0;
vwochnik 52:8f1370084268 116
vwochnik 52:8f1370084268 117 error:
vwochnik 52:8f1370084268 118 mdm.disconnect();
vwochnik 52:8f1370084268 119 return 1;
vwochnik 4:363b4cc49445 120 }