Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
main.cpp@45:5d8feae26fe3, 2014-07-24 (annotated)
- Committer:
- Cumulocity
- Date:
- Thu Jul 24 14:52:44 2014 +0000
- Revision:
- 45:5d8feae26fe3
- Parent:
- 42:104746744af8
- Child:
- 46:f6976fd64387
add display output
Who changed what in which revision?
| User | Revision | Line number | New 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 | 45:5d8feae26fe3 | 34 | io.lcdPrint("NO APN FOUND", devStatus.imsi); |
| 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 | } |

Cumulocity