![](/media/cache/group/u-blox_logo_trans.png.50x50_q85.png)
portable version of the cumulocity demo
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
main.cpp@29:853741b9ea3b, 2014-05-26 (annotated)
- Committer:
- vwochnik
- Date:
- Mon May 26 08:10:27 2014 +0000
- Revision:
- 29:853741b9ea3b
- Parent:
- 28:2004400abeec
- Child:
- 30:daa499571db7
minor fixes for modem connection
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vwochnik | 6:642e7c233e83 | 1 | #include "common.h" |
vwochnik | 23:0a48eebaaba8 | 2 | #include "apndb.h" |
vwochnik | 15:0ccf0f530a05 | 3 | #include "io.h" |
vwochnik | 0:ed4d6fd405ea | 4 | |
vwochnik | 0:ed4d6fd405ea | 5 | C027 c027; |
vwochnik | 27:bfd402593acc | 6 | MDMSerial mdm; |
vwochnik | 28:2004400abeec | 7 | sigq_t sigQ = {}; |
vwochnik | 28:2004400abeec | 8 | char cCellId[8+1]; |
vwochnik | 28:2004400abeec | 9 | MDMParser::DevStatus devStatus = {}; |
vwochnik | 28:2004400abeec | 10 | MDMParser::NetStatus netStatus = {}; |
vwochnik | 0:ed4d6fd405ea | 11 | |
vwochnik | 0:ed4d6fd405ea | 12 | int main() |
vwochnik | 0:ed4d6fd405ea | 13 | { |
vwochnik | 24:8f9b678a7932 | 14 | int ret; size_t c; |
vwochnik | 7:f77afd49c35d | 15 | |
vwochnik | 7:f77afd49c35d | 16 | puts("Started..."); |
vwochnik | 15:0ccf0f530a05 | 17 | io_init(); |
vwochnik | 15:0ccf0f530a05 | 18 | puts("IO initialized."); |
vwochnik | 15:0ccf0f530a05 | 19 | |
vwochnik | 7:f77afd49c35d | 20 | c027.mdmWakeup(); |
vwochnik | 7:f77afd49c35d | 21 | c027.mdmReset(); |
vwochnik | 7:f77afd49c35d | 22 | c027.mdmPower(true); |
vwochnik | 28:2004400abeec | 23 | Thread::wait(2000); |
vwochnik | 27:bfd402593acc | 24 | |
vwochnik | 28:2004400abeec | 25 | puts("Initializing modem."); |
vwochnik | 29:853741b9ea3b | 26 | if (!mdm.init(NULL, &devStatus)) { |
vwochnik | 28:2004400abeec | 27 | puts("Modem initialization failed. Check your PIN number."); |
vwochnik | 28:2004400abeec | 28 | return 1; |
vwochnik | 28:2004400abeec | 29 | } |
vwochnik | 28:2004400abeec | 30 | |
vwochnik | 28:2004400abeec | 31 | puts("Searching for login..."); |
vwochnik | 28:2004400abeec | 32 | apndb_t *apn = apndb_get(devStatus.imsi); |
vwochnik | 28:2004400abeec | 33 | if (apn == NULL) { |
vwochnik | 28:2004400abeec | 34 | puts("No APN found. Stop."); |
vwochnik | 28:2004400abeec | 35 | return 1; |
vwochnik | 4:363b4cc49445 | 36 | } |
vwochnik | 29:853741b9ea3b | 37 | |
vwochnik | 29:853741b9ea3b | 38 | // print out basic device data |
vwochnik | 29:853741b9ea3b | 39 | printf("IMEI: %s\n", devStatus.imei); |
vwochnik | 29:853741b9ea3b | 40 | printf("IMSI: %s\n", devStatus.imsi); |
vwochnik | 24:8f9b678a7932 | 41 | |
vwochnik | 28:2004400abeec | 42 | // wait until we are connected |
vwochnik | 28:2004400abeec | 43 | int i = 60; |
vwochnik | 28:2004400abeec | 44 | while (!mdm.checkNetStatus(&netStatus)) { |
vwochnik | 28:2004400abeec | 45 | if ((netStatus.reg == MDMParser::REG_DENIED) || (i-- == 0)) |
vwochnik | 28:2004400abeec | 46 | break; |
vwochnik | 28:2004400abeec | 47 | Thread::wait(2000); |
vwochnik | 28:2004400abeec | 48 | } |
vwochnik | 28:2004400abeec | 49 | |
vwochnik | 28:2004400abeec | 50 | if ((netStatus.reg == MDMParser::REG_DENIED) || (i == 0)) { |
vwochnik | 28:2004400abeec | 51 | puts("Network connection failed."); |
vwochnik | 28:2004400abeec | 52 | return 1; |
vwochnik | 28:2004400abeec | 53 | } |
vwochnik | 28:2004400abeec | 54 | |
vwochnik | 29:853741b9ea3b | 55 | printf("Carrier: %s\n", apn->carrier); |
vwochnik | 28:2004400abeec | 56 | puts("Joining Network."); |
vwochnik | 29:853741b9ea3b | 57 | if (mdm.join(apn->apn) == NOIP) { |
vwochnik | 29:853741b9ea3b | 58 | puts("Could not join network. Make sure chosen carrier is correct and no credentials are required."); |
vwochnik | 28:2004400abeec | 59 | return 1; |
vwochnik | 28:2004400abeec | 60 | } |
vwochnik | 24:8f9b678a7932 | 61 | |
vwochnik | 8:940c782eec5e | 62 | // get before starting program as they're permanent |
vwochnik | 13:4045b6ac448d | 63 | if ((!strlen(imei())) || (!strlen(iccid()))) { |
vwochnik | 12:beb64aa0da86 | 64 | puts("Couldn't read IMEI or ICCID."); |
vwochnik | 12:beb64aa0da86 | 65 | return 2; |
vwochnik | 12:beb64aa0da86 | 66 | } |
vwochnik | 23:0a48eebaaba8 | 67 | |
vwochnik | 23:0a48eebaaba8 | 68 | // Shown on display |
vwochnik | 23:0a48eebaaba8 | 69 | signalQuality(); |
vwochnik | 4:363b4cc49445 | 70 | |
vwochnik | 7:f77afd49c35d | 71 | puts("Starting program..."); |
vwochnik | 8:940c782eec5e | 72 | |
vwochnik | 8:940c782eec5e | 73 | // restart program upon failure |
vwochnik | 8:940c782eec5e | 74 | do { |
vwochnik | 8:940c782eec5e | 75 | ret = program(); |
vwochnik | 12:beb64aa0da86 | 76 | if (ret) |
vwochnik | 12:beb64aa0da86 | 77 | puts("Restarting program..."); |
vwochnik | 8:940c782eec5e | 78 | } while (ret); |
vwochnik | 4:363b4cc49445 | 79 | |
vwochnik | 6:642e7c233e83 | 80 | c027.mdmPower(false); |
vwochnik | 6:642e7c233e83 | 81 | |
vwochnik | 8:940c782eec5e | 82 | return 0; |
vwochnik | 4:363b4cc49445 | 83 | } |
vwochnik | 4:363b4cc49445 | 84 | |
vwochnik | 6:642e7c233e83 | 85 | const char * imei() |
vwochnik | 4:363b4cc49445 | 86 | { |
vwochnik | 28:2004400abeec | 87 | return devStatus.imei; |
vwochnik | 0:ed4d6fd405ea | 88 | } |
vwochnik | 4:363b4cc49445 | 89 | |
vwochnik | 23:0a48eebaaba8 | 90 | const char * imsi() |
vwochnik | 23:0a48eebaaba8 | 91 | { |
vwochnik | 28:2004400abeec | 92 | return devStatus.imsi; |
vwochnik | 23:0a48eebaaba8 | 93 | } |
vwochnik | 23:0a48eebaaba8 | 94 | |
vwochnik | 6:642e7c233e83 | 95 | const char * cellId() |
vwochnik | 4:363b4cc49445 | 96 | { |
vwochnik | 28:2004400abeec | 97 | if (!mdm.checkNetStatus(&netStatus)) |
vwochnik | 28:2004400abeec | 98 | return NULL; |
vwochnik | 28:2004400abeec | 99 | |
vwochnik | 28:2004400abeec | 100 | if (snprintf(cCellId, sizeof(cCellId), "%X", netStatus.ci) < 1) |
vwochnik | 28:2004400abeec | 101 | return NULL; |
vwochnik | 28:2004400abeec | 102 | |
vwochnik | 6:642e7c233e83 | 103 | return cCellId; |
vwochnik | 4:363b4cc49445 | 104 | } |
vwochnik | 4:363b4cc49445 | 105 | |
vwochnik | 7:f77afd49c35d | 106 | const char * iccid() |
vwochnik | 7:f77afd49c35d | 107 | { |
vwochnik | 28:2004400abeec | 108 | return devStatus.ccid; |
vwochnik | 7:f77afd49c35d | 109 | } |
vwochnik | 7:f77afd49c35d | 110 | |
vwochnik | 6:642e7c233e83 | 111 | sigq_t * signalQuality() |
vwochnik | 4:363b4cc49445 | 112 | { |
vwochnik | 6:642e7c233e83 | 113 | sigQ.rssi = 0; sigQ.ber = 0; |
vwochnik | 28:2004400abeec | 114 | if (!mdm.checkNetStatus(&netStatus)) |
vwochnik | 28:2004400abeec | 115 | return NULL; |
vwochnik | 28:2004400abeec | 116 | |
vwochnik | 28:2004400abeec | 117 | sigQ.rssi = netStatus.rssi; |
vwochnik | 28:2004400abeec | 118 | sigQ.ber = netStatus.ber; |
vwochnik | 20:ef9cc1b42e9d | 119 | |
vwochnik | 28:2004400abeec | 120 | lcd_signal(sigQ.rssi, sigQ.ber); |
vwochnik | 6:642e7c233e83 | 121 | return &sigQ; |
vwochnik | 4:363b4cc49445 | 122 | } |