whatever
Dependencies: C027 C027_Support M2XStreamClient PowerControl jsonlite mbed-rtos mbed
Fork of PONY_Ph0-uAXIS by
main.cpp@17:c293780a40ac, 2014-05-14 (annotated)
- Committer:
- mazgch
- Date:
- Wed May 14 12:24:04 2014 +0000
- Revision:
- 17:c293780a40ac
- Parent:
- 16:43f6de7bc38b
- Child:
- 18:50e6c4ed8a4a
only test large socket request on LPC1768
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lawliet | 0:4e3cb26f6019 | 1 | #include "mbed.h" |
mazgch | 2:b77151f111a9 | 2 | #include "GPS.h" |
mazgch | 2:b77151f111a9 | 3 | #include "MDM.h" |
lawliet | 0:4e3cb26f6019 | 4 | |
mazgch | 9:26f694bc31b4 | 5 | //---------------------------------------------------------------------- |
mazgch | 9:26f694bc31b4 | 6 | // You may need to configure these parameters |
mazgch | 9:26f694bc31b4 | 7 | |
mazgch | 9:26f694bc31b4 | 8 | /** Set your secret SIM pin here "1234" |
mazgch | 9:26f694bc31b4 | 9 | */ |
mazgch | 9:26f694bc31b4 | 10 | #define SIMPIN NULL |
mazgch | 9:26f694bc31b4 | 11 | |
mazgch | 9:26f694bc31b4 | 12 | /** The APN of your network operator, sometimes it is "internet" |
mazgch | 9:26f694bc31b4 | 13 | check your contract with the network operator |
mazgch | 9:26f694bc31b4 | 14 | */ |
mazgch | 9:26f694bc31b4 | 15 | #define APN "gprs.swisscom.ch" |
mazgch | 9:26f694bc31b4 | 16 | |
mazgch | 9:26f694bc31b4 | 17 | /** Set the user name for your APN, or NULL if not needed |
mazgch | 9:26f694bc31b4 | 18 | */ |
mazgch | 9:26f694bc31b4 | 19 | #define USERNAME NULL |
mazgch | 9:26f694bc31b4 | 20 | |
mazgch | 9:26f694bc31b4 | 21 | /** Set the password for your APN, or NULL if not needed |
mazgch | 9:26f694bc31b4 | 22 | */ |
mazgch | 9:26f694bc31b4 | 23 | #define PASSWORD NULL |
mazgch | 9:26f694bc31b4 | 24 | |
mazgch | 10:d2da2028a233 | 25 | //---------------------------------------------------------------------- |
mazgch | 11:b8505cbbd55c | 26 | /* This example was tested on C027-U20 and C027-G35 with the on board modem. |
mazgch | 11:b8505cbbd55c | 27 | |
mazgch | 11:b8505cbbd55c | 28 | Additionally it was tested with a shield where the SARA-G350 RX/TX/PWRON |
mazgch | 11:b8505cbbd55c | 29 | is connected to D0/D1/D4 and the GPS SCL/SDA is connected D15/D15. In this |
mazgch | 11:b8505cbbd55c | 30 | configuration the following platforms were tested (it is likely that others |
mazgch | 11:b8505cbbd55c | 31 | will work as well) |
mazgch | 12:96c7b62c7aaf | 32 | - U-BLOX: C027-XX. |
mazgch | 12:96c7b62c7aaf | 33 | - NXP: LPC1549v2 |
mazgch | 12:96c7b62c7aaf | 34 | - Freescale: FRDM-KL25Z, FRDM-KL46Z |
mazgch | 12:96c7b62c7aaf | 35 | - STM: NUCLEO-F401RE, NUCLEO-F030R8 |
mazgch | 11:b8505cbbd55c | 36 | */ |
mazgch | 13:662bd1df9a72 | 37 | #if defined(TARGET_UBLOX_C027) |
mazgch | 13:662bd1df9a72 | 38 | #define C027_USEONBOARD // remove this if you have the GSM/GPS shield mounted |
mazgch | 10:d2da2028a233 | 39 | #endif |
mazgch | 10:d2da2028a233 | 40 | |
mazgch | 13:662bd1df9a72 | 41 | #ifdef C027_USEONBOARD |
mazgch | 13:662bd1df9a72 | 42 | #include "C027.h" |
mazgch | 13:662bd1df9a72 | 43 | C027 c027; |
mazgch | 15:ea10b6cf8c85 | 44 | #elif TARGET_LPC4088 |
mazgch | 15:ea10b6cf8c85 | 45 | // mapping for use with the EA QSB base board |
mazgch | 15:ea10b6cf8c85 | 46 | #define GPSSCL p20 |
mazgch | 15:ea10b6cf8c85 | 47 | #define GPSSDA p19 |
mazgch | 15:ea10b6cf8c85 | 48 | #define GPSADR (66<<1) // GPS I2C Address |
mazgch | 15:ea10b6cf8c85 | 49 | #define MDMPWRON p33 |
mazgch | 15:ea10b6cf8c85 | 50 | #define MDMTXD p9 |
mazgch | 15:ea10b6cf8c85 | 51 | #define MDMRXD p10 |
mazgch | 15:ea10b6cf8c85 | 52 | #define MDMCTS NC |
mazgch | 15:ea10b6cf8c85 | 53 | #define MDMRTS NC |
mazgch | 15:ea10b6cf8c85 | 54 | #define MDMBAUD 115200 |
mazgch | 13:662bd1df9a72 | 55 | #else |
mazgch | 10:d2da2028a233 | 56 | #define GPSSCL D15 |
mazgch | 10:d2da2028a233 | 57 | #define GPSSDA D14 |
mazgch | 10:d2da2028a233 | 58 | #define GPSADR (66<<1) // GPS I2C Address |
mazgch | 10:d2da2028a233 | 59 | #define MDMPWRON D4 |
mazgch | 10:d2da2028a233 | 60 | #define MDMTXD D1 |
mazgch | 10:d2da2028a233 | 61 | #define MDMRXD D0 |
mazgch | 10:d2da2028a233 | 62 | #define MDMCTS NC |
mazgch | 10:d2da2028a233 | 63 | #define MDMRTS NC |
mazgch | 10:d2da2028a233 | 64 | #define MDMBAUD 115200 |
mazgch | 10:d2da2028a233 | 65 | #endif |
mazgch | 10:d2da2028a233 | 66 | |
mazgch | 10:d2da2028a233 | 67 | // no tracing if serial is shared with the VCP |
mazgch | 15:ea10b6cf8c85 | 68 | #define DOTRACE ((USBRX!=MDMRXD)&&(USBTX!=MDMTXD)) |
mazgch | 15:ea10b6cf8c85 | 69 | #define TRACE (!DOTRACE)?:printf |
lawliet | 0:4e3cb26f6019 | 70 | |
lawliet | 0:4e3cb26f6019 | 71 | int main(void) |
lawliet | 0:4e3cb26f6019 | 72 | { |
mazgch | 2:b77151f111a9 | 73 | int ret; |
mazgch | 17:c293780a40ac | 74 | #ifdef TARGET_LPC1768 |
mazgch | 16:43f6de7bc38b | 75 | char buf[2048] = ""; |
mazgch | 17:c293780a40ac | 76 | #else |
mazgch | 17:c293780a40ac | 77 | char buf[512] = ""; |
mazgch | 17:c293780a40ac | 78 | #endif |
lawliet | 0:4e3cb26f6019 | 79 | |
mazgch | 13:662bd1df9a72 | 80 | // only trace if the serial is different from our modem port |
mazgch | 15:ea10b6cf8c85 | 81 | if (DOTRACE) { |
mazgch | 11:b8505cbbd55c | 82 | Serial pc(USBTX,USBRX); |
mazgch | 11:b8505cbbd55c | 83 | pc.baud(115200); |
mazgch | 11:b8505cbbd55c | 84 | } |
mazgch | 11:b8505cbbd55c | 85 | |
mazgch | 11:b8505cbbd55c | 86 | wait_ms(1000); |
mazgch | 2:b77151f111a9 | 87 | |
mazgch | 10:d2da2028a233 | 88 | TRACE("GSM/GPS Support Example\r\n"); |
mazgch | 11:b8505cbbd55c | 89 | |
mazgch | 10:d2da2028a233 | 90 | #ifdef C027_USEONBOARD |
mazgch | 10:d2da2028a233 | 91 | // turn on the supplies of the Modem and the GPS |
mazgch | 2:b77151f111a9 | 92 | c027.mdmPower(true); |
mazgch | 4:90ab1ec64b0e | 93 | c027.gpsPower(true); |
mazgch | 10:d2da2028a233 | 94 | #else |
mazgch | 10:d2da2028a233 | 95 | // turn on the Modem |
mazgch | 10:d2da2028a233 | 96 | DigitalOut mdmPwrOn(MDMPWRON, 0); |
mazgch | 10:d2da2028a233 | 97 | wait_ms(150); |
mazgch | 10:d2da2028a233 | 98 | mdmPwrOn = 1; |
mazgch | 10:d2da2028a233 | 99 | #endif |
mazgch | 2:b77151f111a9 | 100 | wait(2); |
mazgch | 11:b8505cbbd55c | 101 | |
mazgch | 10:d2da2028a233 | 102 | // Create the GPS object |
mazgch | 13:662bd1df9a72 | 103 | #if GPSADR // use GPSI2C class |
mazgch | 13:662bd1df9a72 | 104 | GPSI2C gps(GPSSDA,GPSSCL,GPSADR); |
mazgch | 13:662bd1df9a72 | 105 | #elif GPSBAUD // or GPSSerial class |
mazgch | 13:662bd1df9a72 | 106 | GPSSerial gps(GPSTXD,GPSRXD,GPSBAUD); |
mazgch | 10:d2da2028a233 | 107 | #else |
mazgch | 10:d2da2028a233 | 108 | #warning "please define the pins for the GPS" |
mazgch | 10:d2da2028a233 | 109 | #endif |
mazgch | 11:b8505cbbd55c | 110 | |
mazgch | 10:d2da2028a233 | 111 | // Create the modem object |
mazgch | 7:e000317ddef6 | 112 | MDMSerial mdm(MDMTXD,MDMRXD,MDMBAUD |
mazgch | 10:d2da2028a233 | 113 | #if DEVICE_SERIAL_FC |
mazgch | 7:e000317ddef6 | 114 | ,MDMRTS,MDMCTS |
mazgch | 10:d2da2028a233 | 115 | #endif |
mazgch | 2:b77151f111a9 | 116 | ); |
mazgch | 11:b8505cbbd55c | 117 | |
mazgch | 2:b77151f111a9 | 118 | // initialize the modem |
mazgch | 10:d2da2028a233 | 119 | TRACE("Device Init\r\n"); |
mazgch | 5:5366d39d3719 | 120 | MDMParser::DevStatus devStatus; |
mazgch | 5:5366d39d3719 | 121 | MDMParser::NetStatus netStatus; |
mazgch | 10:d2da2028a233 | 122 | bool mdmOk = mdm.init(SIMPIN, &devStatus); |
mazgch | 10:d2da2028a233 | 123 | if (mdmOk) |
mazgch | 4:90ab1ec64b0e | 124 | { |
mazgch | 15:ea10b6cf8c85 | 125 | if (DOTRACE) mdm.dumpDevStatus(&devStatus); |
mazgch | 5:5366d39d3719 | 126 | |
mazgch | 4:90ab1ec64b0e | 127 | // wait until we are connected |
mazgch | 10:d2da2028a233 | 128 | TRACE("Network Check\r\n"); |
mazgch | 5:5366d39d3719 | 129 | while (!mdm.checkNetStatus(&netStatus)) |
mazgch | 4:90ab1ec64b0e | 130 | wait_ms(1000); |
mazgch | 2:b77151f111a9 | 131 | |
mazgch | 15:ea10b6cf8c85 | 132 | if (DOTRACE) mdm.dumpNetStatus(&netStatus); |
mazgch | 10:d2da2028a233 | 133 | TRACE("Network Join\r\n"); |
mazgch | 4:90ab1ec64b0e | 134 | // join the internet connection |
mazgch | 5:5366d39d3719 | 135 | MDMParser::IP ip = |
mazgch | 9:26f694bc31b4 | 136 | mdm.join(APN,USERNAME,PASSWORD); |
mazgch | 5:5366d39d3719 | 137 | if (ip != NOIP) |
mazgch | 2:b77151f111a9 | 138 | { |
mazgch | 15:ea10b6cf8c85 | 139 | if (DOTRACE) mdm.dumpIp(ip); |
mazgch | 10:d2da2028a233 | 140 | TRACE("Socket Create\r\n"); |
mazgch | 4:90ab1ec64b0e | 141 | int socket = mdm.socketSocket(MDMParser::IPPROTO_TCP); |
mazgch | 4:90ab1ec64b0e | 142 | if (socket >= 0) |
mazgch | 2:b77151f111a9 | 143 | { |
mazgch | 10:d2da2028a233 | 144 | TRACE("Socket Connect\r\n"); |
mazgch | 16:43f6de7bc38b | 145 | mdm.socketSetBlocking(socket, 10000); |
mazgch | 4:90ab1ec64b0e | 146 | if (mdm.socketConnect(socket, "mbed.org", 80)) |
mazgch | 4:90ab1ec64b0e | 147 | { |
mazgch | 10:d2da2028a233 | 148 | TRACE("Make a Http Post Request\r\n"); |
mazgch | 4:90ab1ec64b0e | 149 | const char http[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\r\n\r\n"; |
mazgch | 10:d2da2028a233 | 150 | TRACE("Socket Send\r\n"); |
mazgch | 4:90ab1ec64b0e | 151 | mdm.socketSend(socket, http, sizeof(http)-1); |
mazgch | 4:90ab1ec64b0e | 152 | |
mazgch | 10:d2da2028a233 | 153 | TRACE("Socket Recving\r\n"); |
mazgch | 4:90ab1ec64b0e | 154 | while (true) { |
mazgch | 4:90ab1ec64b0e | 155 | ret = mdm.socketReadable(socket); |
mazgch | 4:90ab1ec64b0e | 156 | if (ret > 0) |
mazgch | 4:90ab1ec64b0e | 157 | ret = mdm.socketRecv(socket, buf, sizeof(buf)-1); |
mazgch | 4:90ab1ec64b0e | 158 | if (ret < 0) |
mazgch | 4:90ab1ec64b0e | 159 | break; |
mazgch | 4:90ab1ec64b0e | 160 | else if (ret > 0) |
mazgch | 10:d2da2028a233 | 161 | TRACE("Socket Recv \"%*s\"\r\n", ret, buf); |
mazgch | 4:90ab1ec64b0e | 162 | } |
mazgch | 10:d2da2028a233 | 163 | TRACE("Socket Close\r\n"); |
mazgch | 4:90ab1ec64b0e | 164 | mdm.socketClose(socket); |
mazgch | 4:90ab1ec64b0e | 165 | } |
mazgch | 10:d2da2028a233 | 166 | TRACE("Socket Free\r\n"); |
mazgch | 4:90ab1ec64b0e | 167 | mdm.socketFree(socket); |
mazgch | 4:90ab1ec64b0e | 168 | } |
mazgch | 2:b77151f111a9 | 169 | |
mazgch | 16:43f6de7bc38b | 170 | int port = 7; |
mazgch | 16:43f6de7bc38b | 171 | const char* host = "echo.u-blox.com"; |
mazgch | 16:43f6de7bc38b | 172 | MDMParser::IP ip = mdm.gethostbyname(host); |
mazgch | 16:43f6de7bc38b | 173 | char data[] = "\r\nxxx Socket Hello World\r\n" |
mazgch | 17:c293780a40ac | 174 | #ifdef TARGET_LPC1768 |
mazgch | 17:c293780a40ac | 175 | "00 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 176 | "01 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 177 | "02 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 178 | "03 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 179 | "04 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 180 | |
mazgch | 17:c293780a40ac | 181 | "05 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 182 | "06 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 183 | "07 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 184 | "08 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 185 | "09 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 16:43f6de7bc38b | 186 | |
mazgch | 17:c293780a40ac | 187 | "10 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 188 | "11 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 189 | "12 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 190 | "13 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 191 | "14 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 192 | |
mazgch | 17:c293780a40ac | 193 | "15 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 194 | "16 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 195 | "17 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 196 | "18 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 197 | "19 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 16:43f6de7bc38b | 198 | #endif |
mazgch | 17:c293780a40ac | 199 | "End\r\n"; |
mazgch | 16:43f6de7bc38b | 200 | |
mazgch | 16:43f6de7bc38b | 201 | TRACE("Testing TCP sockets with ECHO server\r\n"); |
mazgch | 16:43f6de7bc38b | 202 | socket = mdm.socketSocket(MDMParser::IPPROTO_TCP); |
mazgch | 16:43f6de7bc38b | 203 | if (socket >= 0) |
mazgch | 16:43f6de7bc38b | 204 | { |
mazgch | 16:43f6de7bc38b | 205 | mdm.socketSetBlocking(socket, 10000); |
mazgch | 16:43f6de7bc38b | 206 | if (mdm.socketConnect(socket, host, port)) { |
mazgch | 16:43f6de7bc38b | 207 | memcpy(data, "\r\nTCP", 5); |
mazgch | 16:43f6de7bc38b | 208 | ret = mdm.socketSend(socket, data, sizeof(data)-1); |
mazgch | 16:43f6de7bc38b | 209 | if (ret == sizeof(data)-1) { |
mazgch | 16:43f6de7bc38b | 210 | TRACE("Socket Send %d \"%s\"\r\n", ret, data); |
mazgch | 16:43f6de7bc38b | 211 | } |
mazgch | 16:43f6de7bc38b | 212 | ret = mdm.socketRecv(socket, buf, sizeof(buf)-1); |
mazgch | 16:43f6de7bc38b | 213 | if (ret >= 0) { |
mazgch | 16:43f6de7bc38b | 214 | TRACE("Socket Recv %d \"%.*s\"\r\n", ret, ret, buf); |
mazgch | 16:43f6de7bc38b | 215 | } |
mazgch | 16:43f6de7bc38b | 216 | mdm.socketClose(socket); |
mazgch | 16:43f6de7bc38b | 217 | } |
mazgch | 16:43f6de7bc38b | 218 | mdm.socketFree(socket); |
mazgch | 16:43f6de7bc38b | 219 | } |
mazgch | 16:43f6de7bc38b | 220 | |
mazgch | 16:43f6de7bc38b | 221 | TRACE("Testing UDP sockets with ECHO server\r\n"); |
mazgch | 16:43f6de7bc38b | 222 | socket = mdm.socketSocket(MDMParser::IPPROTO_UDP, port); |
mazgch | 16:43f6de7bc38b | 223 | if (socket >= 0) |
mazgch | 16:43f6de7bc38b | 224 | { |
mazgch | 16:43f6de7bc38b | 225 | mdm.socketSetBlocking(socket, 10000); |
mazgch | 16:43f6de7bc38b | 226 | memcpy(data, "\r\nUDP", 5); |
mazgch | 16:43f6de7bc38b | 227 | ret = mdm.socketSendTo(socket, ip, port, data, sizeof(data)-1); |
mazgch | 16:43f6de7bc38b | 228 | if (ret == sizeof(data)-1) { |
mazgch | 16:43f6de7bc38b | 229 | TRACE("Socket SendTo %s:%d " IPSTR " %d \"%s\"\r\n", host, port, IPNUM(ip), ret, data); |
mazgch | 16:43f6de7bc38b | 230 | } |
mazgch | 16:43f6de7bc38b | 231 | ret = mdm.socketRecvFrom(socket, &ip, &port, buf, sizeof(buf)-1); |
mazgch | 16:43f6de7bc38b | 232 | if (ret >= 0) { |
mazgch | 16:43f6de7bc38b | 233 | TRACE("Socket RecvFrom " IPSTR ":%d %d \"%.*s\" \r\n", IPNUM(ip),port, ret, ret,buf); |
mazgch | 16:43f6de7bc38b | 234 | } |
mazgch | 16:43f6de7bc38b | 235 | mdm.socketFree(socket); |
mazgch | 16:43f6de7bc38b | 236 | } |
mazgch | 16:43f6de7bc38b | 237 | |
mazgch | 4:90ab1ec64b0e | 238 | // disconnect |
mazgch | 10:d2da2028a233 | 239 | TRACE("Network Disconnect\r\n"); |
mazgch | 4:90ab1ec64b0e | 240 | mdm.disconnect(); |
mazgch | 2:b77151f111a9 | 241 | } |
mazgch | 2:b77151f111a9 | 242 | |
mazgch | 5:5366d39d3719 | 243 | const char* ussd = "*#134#"; // You may get answer "UNKNOWN APPLICATION" |
mazgch | 10:d2da2028a233 | 244 | TRACE("Send Ussd Command %s\r\n", ussd); |
mazgch | 5:5366d39d3719 | 245 | ret = mdm.ussdCommand(ussd, buf); |
mazgch | 4:90ab1ec64b0e | 246 | if (ret > 0) |
mazgch | 10:d2da2028a233 | 247 | TRACE("Got Ussd Answer: \"%*s\"\r\n", ret, buf); |
mazgch | 10:d2da2028a233 | 248 | } |
mazgch | 10:d2da2028a233 | 249 | TRACE("Checking SMS and GPS\r\n"); |
mazgch | 10:d2da2028a233 | 250 | char link[128] = ""; |
mazgch | 10:d2da2028a233 | 251 | unsigned int i = 0xFFFFFFFF; |
mazgch | 10:d2da2028a233 | 252 | const int wait = 100; |
mazgch | 10:d2da2028a233 | 253 | bool abort = false; |
mazgch | 11:b8505cbbd55c | 254 | //DigitalOut led(LED1); |
mazgch | 10:d2da2028a233 | 255 | while (!abort) { |
mazgch | 11:b8505cbbd55c | 256 | // led = !led; |
mazgch | 10:d2da2028a233 | 257 | while ((ret = gps.getMessage(buf, sizeof(buf))) > 0) |
mazgch | 10:d2da2028a233 | 258 | { |
mazgch | 10:d2da2028a233 | 259 | int len = LENGTH(ret); |
mazgch | 10:d2da2028a233 | 260 | //TRACE("NMEA: %.*s\r\n", len-2, msg); |
mazgch | 14:ab7c8627f950 | 261 | if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6) && !strncmp("$GPGLL", buf, 6)) |
mazgch | 4:90ab1ec64b0e | 262 | { |
mazgch | 10:d2da2028a233 | 263 | double la = 0, lo = 0; |
mazgch | 10:d2da2028a233 | 264 | char ch; |
mazgch | 10:d2da2028a233 | 265 | if (gps.getNmeaAngle(1,buf,len,la) && |
mazgch | 10:d2da2028a233 | 266 | gps.getNmeaAngle(3,buf,len,lo) && |
mazgch | 10:d2da2028a233 | 267 | gps.getNmeaItem(6,buf,len,ch) && ch == 'A') |
mazgch | 4:90ab1ec64b0e | 268 | { |
mazgch | 10:d2da2028a233 | 269 | TRACE("GPS Location: %.5f %.5f\r\n", la, lo); |
mazgch | 10:d2da2028a233 | 270 | sprintf(link, "I am here!\n" |
mazgch | 10:d2da2028a233 | 271 | "https://maps.google.com/?q=%.5f,%.5f", la, lo); |
mazgch | 4:90ab1ec64b0e | 272 | } |
mazgch | 4:90ab1ec64b0e | 273 | } |
mazgch | 10:d2da2028a233 | 274 | } |
mazgch | 10:d2da2028a233 | 275 | if (mdmOk && (i++ == 10000/wait)) { |
mazgch | 10:d2da2028a233 | 276 | i = 0; |
mazgch | 10:d2da2028a233 | 277 | // check the network status |
mazgch | 15:ea10b6cf8c85 | 278 | if (mdm.checkNetStatus(&netStatus)) { |
mazgch | 15:ea10b6cf8c85 | 279 | if (DOTRACE) mdm.dumpNetStatus(&netStatus); |
mazgch | 15:ea10b6cf8c85 | 280 | } |
mazgch | 10:d2da2028a233 | 281 | |
mazgch | 10:d2da2028a233 | 282 | // checking unread sms |
mazgch | 10:d2da2028a233 | 283 | int ix[8]; |
mazgch | 10:d2da2028a233 | 284 | int n = mdm.smsList("REC UNREAD", ix, 8); |
mazgch | 10:d2da2028a233 | 285 | if (8 < n) n = 8; |
mazgch | 10:d2da2028a233 | 286 | while (0 < n--) |
mazgch | 10:d2da2028a233 | 287 | { |
mazgch | 10:d2da2028a233 | 288 | char num[32]; |
mazgch | 10:d2da2028a233 | 289 | TRACE("Unread SMS at index %d\r\n", ix[n]); |
mazgch | 10:d2da2028a233 | 290 | if (mdm.smsRead(ix[n], num, buf, sizeof(buf))) { |
mazgch | 10:d2da2028a233 | 291 | TRACE("Got SMS from \"%s\" with text \"%s\"\r\n", num, buf); |
mazgch | 10:d2da2028a233 | 292 | TRACE("Delete SMS at index %d\r\n", ix[n]); |
mazgch | 10:d2da2028a233 | 293 | mdm.smsDelete(ix[n]); |
mazgch | 10:d2da2028a233 | 294 | // provide a reply |
mazgch | 10:d2da2028a233 | 295 | const char* reply = "Hello my friend"; |
mazgch | 10:d2da2028a233 | 296 | if (strstr(buf, /*w*/"here are you")) |
mazgch | 10:d2da2028a233 | 297 | reply = *link ? link : "I don't know"; // reply wil location link |
mazgch | 10:d2da2028a233 | 298 | TRACE("Send SMS reply \"%s\" to \"%s\"\r\n", reply, num); |
mazgch | 10:d2da2028a233 | 299 | mdm.smsSend(num, reply); |
mazgch | 4:90ab1ec64b0e | 300 | } |
mazgch | 4:90ab1ec64b0e | 301 | } |
mazgch | 9:26f694bc31b4 | 302 | } |
mazgch | 10:d2da2028a233 | 303 | wait_ms(wait); |
lawliet | 0:4e3cb26f6019 | 304 | } |
mazgch | 10:d2da2028a233 | 305 | mdm.powerOff(); |
mazgch | 10:d2da2028a233 | 306 | gps.powerOff(); |
mazgch | 10:d2da2028a233 | 307 | TRACE("Shutdown\r\n"); |
mazgch | 10:d2da2028a233 | 308 | #ifdef C027_USEONBOARD |
mazgch | 10:d2da2028a233 | 309 | // now it is safe to switch LDOs off |
mazgch | 2:b77151f111a9 | 310 | c027.mdmPower(false); |
mazgch | 4:90ab1ec64b0e | 311 | c027.gpsPower(false); |
mazgch | 10:d2da2028a233 | 312 | #endif |
lawliet | 0:4e3cb26f6019 | 313 | return 0; |
lawliet | 0:4e3cb26f6019 | 314 | } |
mazgch | 2:b77151f111a9 | 315 |