Own fork of MbedSmartRestMain
Dependencies: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
main.cpp@27:bfd402593acc, 2014-05-22 (annotated)
- Committer:
- vwochnik
- Date:
- Thu May 22 18:07:13 2014 +0000
- Revision:
- 27:bfd402593acc
- Parent:
- 24:8f9b678a7932
- Child:
- 28:2004400abeec
change u-blox modem driver
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 | 27:bfd402593acc | 5 | //---------------------------------------------------------------------- |
vwochnik | 27:bfd402593acc | 6 | // You may need to configure these parameters |
vwochnik | 27:bfd402593acc | 7 | |
vwochnik | 27:bfd402593acc | 8 | /** Set your secret SIM pin here "1234" |
vwochnik | 27:bfd402593acc | 9 | */ |
vwochnik | 27:bfd402593acc | 10 | #define SIMPIN NULL |
vwochnik | 27:bfd402593acc | 11 | |
vwochnik | 27:bfd402593acc | 12 | /** The APN of your network operator, sometimes it is "internet" |
vwochnik | 27:bfd402593acc | 13 | check your contract with the network operator |
vwochnik | 27:bfd402593acc | 14 | */ |
vwochnik | 27:bfd402593acc | 15 | #define APN "public4.m2minternet.com" |
vwochnik | 27:bfd402593acc | 16 | |
vwochnik | 27:bfd402593acc | 17 | /** Set the user name for your APN, or NULL if not needed |
vwochnik | 27:bfd402593acc | 18 | */ |
vwochnik | 27:bfd402593acc | 19 | #define USERNAME NULL |
vwochnik | 27:bfd402593acc | 20 | |
vwochnik | 27:bfd402593acc | 21 | /** Set the password for your APN, or NULL if not needed |
vwochnik | 27:bfd402593acc | 22 | */ |
vwochnik | 27:bfd402593acc | 23 | #define PASSWORD NULL |
vwochnik | 27:bfd402593acc | 24 | |
vwochnik | 0:ed4d6fd405ea | 25 | C027 c027; |
vwochnik | 27:bfd402593acc | 26 | MDMSerial mdm; |
vwochnik | 27:bfd402593acc | 27 | char cIMEI[21] = "ADASDF1312"; |
vwochnik | 23:0a48eebaaba8 | 28 | char cIMSI[16] = ""; |
vwochnik | 6:642e7c233e83 | 29 | char cCellId[9] = ""; |
vwochnik | 27:bfd402593acc | 30 | char cICCID[24] = "12345"; |
vwochnik | 6:642e7c233e83 | 31 | sigq_t sigQ = {0, 0}; |
vwochnik | 0:ed4d6fd405ea | 32 | |
vwochnik | 0:ed4d6fd405ea | 33 | int main() |
vwochnik | 0:ed4d6fd405ea | 34 | { |
vwochnik | 24:8f9b678a7932 | 35 | int ret; size_t c; |
vwochnik | 7:f77afd49c35d | 36 | |
vwochnik | 7:f77afd49c35d | 37 | puts("Started..."); |
vwochnik | 15:0ccf0f530a05 | 38 | io_init(); |
vwochnik | 15:0ccf0f530a05 | 39 | puts("IO initialized."); |
vwochnik | 15:0ccf0f530a05 | 40 | |
vwochnik | 7:f77afd49c35d | 41 | c027.mdmWakeup(); |
vwochnik | 7:f77afd49c35d | 42 | c027.mdmReset(); |
vwochnik | 7:f77afd49c35d | 43 | c027.mdmPower(true); |
vwochnik | 6:642e7c233e83 | 44 | |
vwochnik | 24:8f9b678a7932 | 45 | /*puts("Searching for login..."); |
vwochnik | 24:8f9b678a7932 | 46 | // get imsi number |
vwochnik | 24:8f9b678a7932 | 47 | printf("IMSI: %s\n", imsi()); |
vwochnik | 24:8f9b678a7932 | 48 | apndb_t *apn = apndb_get(imsi()); |
vwochnik | 24:8f9b678a7932 | 49 | if (apn == NULL) |
vwochnik | 24:8f9b678a7932 | 50 | puts("No APN found."); |
vwochnik | 24:8f9b678a7932 | 51 | else |
vwochnik | 24:8f9b678a7932 | 52 | printf("APN: %s\n", apn->apn); |
vwochnik | 24:8f9b678a7932 | 53 | */ |
vwochnik | 27:bfd402593acc | 54 | |
vwochnik | 27:bfd402593acc | 55 | if (!mdm.connect(SIMPIN, APN,USERNAME,PASSWORD, true)) { |
vwochnik | 24:8f9b678a7932 | 56 | puts("GPRS connection failure."); |
vwochnik | 24:8f9b678a7932 | 57 | return 2; |
vwochnik | 4:363b4cc49445 | 58 | } |
vwochnik | 24:8f9b678a7932 | 59 | |
vwochnik | 24:8f9b678a7932 | 60 | /*printf("IMSI: %s\n", imsi()); |
vwochnik | 24:8f9b678a7932 | 61 | apn = apndb_get(imsi()); |
vwochnik | 24:8f9b678a7932 | 62 | if (apn == NULL) |
vwochnik | 24:8f9b678a7932 | 63 | puts("No APN found."); |
vwochnik | 24:8f9b678a7932 | 64 | else |
vwochnik | 24:8f9b678a7932 | 65 | printf("APN: %s\n", apn->apn); |
vwochnik | 24:8f9b678a7932 | 66 | */ |
vwochnik | 24:8f9b678a7932 | 67 | |
vwochnik | 8:940c782eec5e | 68 | // get before starting program as they're permanent |
vwochnik | 13:4045b6ac448d | 69 | if ((!strlen(imei())) || (!strlen(iccid()))) { |
vwochnik | 12:beb64aa0da86 | 70 | puts("Couldn't read IMEI or ICCID."); |
vwochnik | 12:beb64aa0da86 | 71 | return 2; |
vwochnik | 12:beb64aa0da86 | 72 | } |
vwochnik | 23:0a48eebaaba8 | 73 | |
vwochnik | 23:0a48eebaaba8 | 74 | // Shown on display |
vwochnik | 23:0a48eebaaba8 | 75 | signalQuality(); |
vwochnik | 4:363b4cc49445 | 76 | |
vwochnik | 7:f77afd49c35d | 77 | puts("Starting program..."); |
vwochnik | 8:940c782eec5e | 78 | |
vwochnik | 8:940c782eec5e | 79 | // restart program upon failure |
vwochnik | 8:940c782eec5e | 80 | do { |
vwochnik | 8:940c782eec5e | 81 | ret = program(); |
vwochnik | 12:beb64aa0da86 | 82 | if (ret) |
vwochnik | 12:beb64aa0da86 | 83 | puts("Restarting program..."); |
vwochnik | 8:940c782eec5e | 84 | } while (ret); |
vwochnik | 4:363b4cc49445 | 85 | |
vwochnik | 6:642e7c233e83 | 86 | c027.mdmPower(false); |
vwochnik | 6:642e7c233e83 | 87 | |
vwochnik | 8:940c782eec5e | 88 | return 0; |
vwochnik | 4:363b4cc49445 | 89 | } |
vwochnik | 4:363b4cc49445 | 90 | |
vwochnik | 6:642e7c233e83 | 91 | const char * imei() |
vwochnik | 4:363b4cc49445 | 92 | { |
vwochnik | 6:642e7c233e83 | 93 | return cIMEI; |
vwochnik | 0:ed4d6fd405ea | 94 | } |
vwochnik | 4:363b4cc49445 | 95 | |
vwochnik | 23:0a48eebaaba8 | 96 | const char * imsi() |
vwochnik | 23:0a48eebaaba8 | 97 | { |
vwochnik | 23:0a48eebaaba8 | 98 | return cIMSI; |
vwochnik | 23:0a48eebaaba8 | 99 | } |
vwochnik | 23:0a48eebaaba8 | 100 | |
vwochnik | 6:642e7c233e83 | 101 | const char * cellId() |
vwochnik | 4:363b4cc49445 | 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 | 7:f77afd49c35d | 108 | return cICCID; |
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 | 20:ef9cc1b42e9d | 114 | |
vwochnik | 20:ef9cc1b42e9d | 115 | lcd_signal(0, 0); |
vwochnik | 4:363b4cc49445 | 116 | |
vwochnik | 6:642e7c233e83 | 117 | return &sigQ; |
vwochnik | 4:363b4cc49445 | 118 | } |