![](/media/cache/profiles/1225293648e26d9c5e54e22e92197cb4.jpg.50x50_q85.jpg)
Test
Fork of C027_SupportTest by
main.cpp@34:0c14098f38f9, 2017-05-08 (annotated)
- Committer:
- sarahmarshy
- Date:
- Mon May 08 21:38:04 2017 +0000
- Revision:
- 34:0c14098f38f9
- Parent:
- 33:e27f40fada64
Test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lawliet | 0:4e3cb26f6019 | 1 | #include "mbed.h" |
mazgch | 9:26f694bc31b4 | 2 | |
mazgch | 19:f022ff746eb8 | 3 | //------------------------------------------------------------------------------------ |
mazgch | 11:b8505cbbd55c | 4 | /* This example was tested on C027-U20 and C027-G35 with the on board modem. |
mazgch | 11:b8505cbbd55c | 5 | |
mazgch | 18:50e6c4ed8a4a | 6 | Additionally it was tested with a shield where the SARA-G350/U260/U270 RX/TX/PWRON |
mazgch | 11:b8505cbbd55c | 7 | is connected to D0/D1/D4 and the GPS SCL/SDA is connected D15/D15. In this |
mazgch | 11:b8505cbbd55c | 8 | configuration the following platforms were tested (it is likely that others |
mazgch | 11:b8505cbbd55c | 9 | will work as well) |
mazgch | 19:f022ff746eb8 | 10 | - U-BLOX: C027-G35, C027-U20, C027-C20 (for shield set define C027_FORCE_SHIELD) |
mazgch | 18:50e6c4ed8a4a | 11 | - NXP: LPC1549v2, LPC4088qsb |
mazgch | 18:50e6c4ed8a4a | 12 | - Freescale: FRDM-KL05Z, FRDM-KL25Z, FRDM-KL46Z, FRDM-K64F |
mazgch | 12:96c7b62c7aaf | 13 | - STM: NUCLEO-F401RE, NUCLEO-F030R8 |
mazgch | 18:50e6c4ed8a4a | 14 | mount resistors SB13/14 1k, SB62/63 0R |
mazgch | 11:b8505cbbd55c | 15 | */ |
mazgch | 19:f022ff746eb8 | 16 | #include "GPS.h" |
mazgch | 19:f022ff746eb8 | 17 | #include "MDM.h" |
mazgch | 19:f022ff746eb8 | 18 | //------------------------------------------------------------------------------------ |
mazgch | 19:f022ff746eb8 | 19 | // You need to configure these cellular modem / SIM parameters. |
mazgch | 19:f022ff746eb8 | 20 | // These parameters are ignored for LISA-C200 variants and can be left NULL. |
mazgch | 19:f022ff746eb8 | 21 | //------------------------------------------------------------------------------------ |
mazgch | 19:f022ff746eb8 | 22 | //! Set your secret SIM pin here (e.g. "1234"). Check your SIM manual. |
mazgch | 30:062717f25e41 | 23 | #define SIMPIN "1922" |
mazgch | 19:f022ff746eb8 | 24 | /*! The APN of your network operator SIM, sometimes it is "internet" check your |
mazgch | 19:f022ff746eb8 | 25 | contract with the network operator. You can also try to look-up your settings in |
mazgch | 19:f022ff746eb8 | 26 | google: https://www.google.de/search?q=APN+list */ |
sarahmarshy | 34:0c14098f38f9 | 27 | #define APN "fast.t-mobile.com" |
mazgch | 19:f022ff746eb8 | 28 | //! Set the user name for your APN, or NULL if not needed |
mazgch | 19:f022ff746eb8 | 29 | #define USERNAME NULL |
mazgch | 19:f022ff746eb8 | 30 | //! Set the password for your APN, or NULL if not needed |
mazgch | 19:f022ff746eb8 | 31 | #define PASSWORD NULL |
mazgch | 19:f022ff746eb8 | 32 | //------------------------------------------------------------------------------------ |
lawliet | 0:4e3cb26f6019 | 33 | |
msinig | 29:16f1037626e3 | 34 | //#define CELLOCATE |
msinig | 29:16f1037626e3 | 35 | |
lawliet | 0:4e3cb26f6019 | 36 | int main(void) |
lawliet | 0:4e3cb26f6019 | 37 | { |
mazgch | 2:b77151f111a9 | 38 | int ret; |
mazgch | 19:f022ff746eb8 | 39 | #ifdef LARGE_DATA |
mazgch | 16:43f6de7bc38b | 40 | char buf[2048] = ""; |
mazgch | 17:c293780a40ac | 41 | #else |
mazgch | 17:c293780a40ac | 42 | char buf[512] = ""; |
mazgch | 17:c293780a40ac | 43 | #endif |
lawliet | 0:4e3cb26f6019 | 44 | |
mazgch | 19:f022ff746eb8 | 45 | // Create the GPS object |
mazgch | 19:f022ff746eb8 | 46 | #if 1 // use GPSI2C class |
mazgch | 19:f022ff746eb8 | 47 | GPSI2C gps; |
mazgch | 19:f022ff746eb8 | 48 | #else // or GPSSerial class |
mazgch | 19:f022ff746eb8 | 49 | GPSSerial gps; |
mazgch | 10:d2da2028a233 | 50 | #endif |
mazgch | 10:d2da2028a233 | 51 | // Create the modem object |
mazgch | 32:b838fcaba45e | 52 | MDMSerial mdm; // use mdm(D1,D0) if you connect the cellular shield to a C027 |
mazgch | 28:334263983fcd | 53 | //mdm.setDebug(4); // enable this for debugging issues |
mazgch | 2:b77151f111a9 | 54 | // initialize the modem |
mazgch | 19:f022ff746eb8 | 55 | MDMParser::DevStatus devStatus = {}; |
mazgch | 19:f022ff746eb8 | 56 | MDMParser::NetStatus netStatus = {}; |
mazgch | 10:d2da2028a233 | 57 | bool mdmOk = mdm.init(SIMPIN, &devStatus); |
mazgch | 19:f022ff746eb8 | 58 | mdm.dumpDevStatus(&devStatus); |
mazgch | 19:f022ff746eb8 | 59 | if (mdmOk) { |
mazgch | 20:52f0e5de8c3d | 60 | #if 0 |
mazgch | 20:52f0e5de8c3d | 61 | // file system API |
mazgch | 19:f022ff746eb8 | 62 | const char* filename = "File"; |
mazgch | 19:f022ff746eb8 | 63 | char buf[] = "Hello World"; |
mazgch | 19:f022ff746eb8 | 64 | printf("writeFile \"%s\"\r\n", buf); |
mazgch | 19:f022ff746eb8 | 65 | if (mdm.writeFile(filename, buf, sizeof(buf))) |
mazgch | 19:f022ff746eb8 | 66 | { |
mazgch | 19:f022ff746eb8 | 67 | memset(buf, 0, sizeof(buf)); |
mazgch | 19:f022ff746eb8 | 68 | int len = mdm.readFile(filename, buf, sizeof(buf)); |
mazgch | 24:81f5b43a6585 | 69 | if (len >= 0) |
mazgch | 19:f022ff746eb8 | 70 | printf("readFile %d \"%.*s\"\r\n", len, len, buf); |
mazgch | 19:f022ff746eb8 | 71 | mdm.delFile(filename); |
mazgch | 19:f022ff746eb8 | 72 | } |
mazgch | 20:52f0e5de8c3d | 73 | #endif |
mazgch | 20:52f0e5de8c3d | 74 | |
mazgch | 20:52f0e5de8c3d | 75 | // wait until we are connected |
mazgch | 20:52f0e5de8c3d | 76 | mdmOk = mdm.registerNet(&netStatus); |
mazgch | 20:52f0e5de8c3d | 77 | mdm.dumpNetStatus(&netStatus); |
mazgch | 20:52f0e5de8c3d | 78 | } |
mazgch | 20:52f0e5de8c3d | 79 | if (mdmOk) |
mazgch | 20:52f0e5de8c3d | 80 | { |
mazgch | 4:90ab1ec64b0e | 81 | // join the internet connection |
mazgch | 19:f022ff746eb8 | 82 | MDMParser::IP ip = mdm.join(APN,USERNAME,PASSWORD); |
mazgch | 32:b838fcaba45e | 83 | if (ip == NOIP) |
mazgch | 32:b838fcaba45e | 84 | printf("Not able to join network"); |
mazgch | 32:b838fcaba45e | 85 | else |
mazgch | 2:b77151f111a9 | 86 | { |
mazgch | 19:f022ff746eb8 | 87 | mdm.dumpIp(ip); |
mazgch | 19:f022ff746eb8 | 88 | printf("Make a Http Post Request\r\n"); |
mazgch | 4:90ab1ec64b0e | 89 | int socket = mdm.socketSocket(MDMParser::IPPROTO_TCP); |
mazgch | 4:90ab1ec64b0e | 90 | if (socket >= 0) |
mazgch | 2:b77151f111a9 | 91 | { |
mazgch | 16:43f6de7bc38b | 92 | mdm.socketSetBlocking(socket, 10000); |
mazgch | 4:90ab1ec64b0e | 93 | if (mdm.socketConnect(socket, "mbed.org", 80)) |
mazgch | 4:90ab1ec64b0e | 94 | { |
mazgch | 4:90ab1ec64b0e | 95 | const char http[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\r\n\r\n"; |
mazgch | 4:90ab1ec64b0e | 96 | mdm.socketSend(socket, http, sizeof(http)-1); |
mazgch | 4:90ab1ec64b0e | 97 | |
mazgch | 19:f022ff746eb8 | 98 | ret = mdm.socketRecv(socket, buf, sizeof(buf)-1); |
mazgch | 19:f022ff746eb8 | 99 | if (ret > 0) |
mazgch | 19:f022ff746eb8 | 100 | printf("Socket Recv \"%*s\"\r\n", ret, buf); |
mazgch | 4:90ab1ec64b0e | 101 | mdm.socketClose(socket); |
mazgch | 4:90ab1ec64b0e | 102 | } |
mazgch | 4:90ab1ec64b0e | 103 | mdm.socketFree(socket); |
mazgch | 4:90ab1ec64b0e | 104 | } |
mazgch | 2:b77151f111a9 | 105 | |
mazgch | 16:43f6de7bc38b | 106 | int port = 7; |
mazgch | 16:43f6de7bc38b | 107 | const char* host = "echo.u-blox.com"; |
mazgch | 16:43f6de7bc38b | 108 | MDMParser::IP ip = mdm.gethostbyname(host); |
mazgch | 16:43f6de7bc38b | 109 | char data[] = "\r\nxxx Socket Hello World\r\n" |
mazgch | 19:f022ff746eb8 | 110 | #ifdef LARGE_DATA |
mazgch | 17:c293780a40ac | 111 | "00 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 112 | "01 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 113 | "02 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 114 | "03 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 115 | "04 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 116 | |
mazgch | 17:c293780a40ac | 117 | "05 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 118 | "06 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 119 | "07 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 120 | "08 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 121 | "09 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 16:43f6de7bc38b | 122 | |
mazgch | 17:c293780a40ac | 123 | "10 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 124 | "11 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 125 | "12 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 126 | "13 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 127 | "14 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 128 | |
mazgch | 17:c293780a40ac | 129 | "15 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 130 | "16 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 131 | "17 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 132 | "18 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 133 | "19 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 16:43f6de7bc38b | 134 | #endif |
mazgch | 17:c293780a40ac | 135 | "End\r\n"; |
mazgch | 16:43f6de7bc38b | 136 | |
mazgch | 19:f022ff746eb8 | 137 | printf("Testing TCP sockets with ECHO server\r\n"); |
mazgch | 16:43f6de7bc38b | 138 | socket = mdm.socketSocket(MDMParser::IPPROTO_TCP); |
mazgch | 16:43f6de7bc38b | 139 | if (socket >= 0) |
mazgch | 16:43f6de7bc38b | 140 | { |
mazgch | 16:43f6de7bc38b | 141 | mdm.socketSetBlocking(socket, 10000); |
mazgch | 16:43f6de7bc38b | 142 | if (mdm.socketConnect(socket, host, port)) { |
mazgch | 16:43f6de7bc38b | 143 | memcpy(data, "\r\nTCP", 5); |
mazgch | 16:43f6de7bc38b | 144 | ret = mdm.socketSend(socket, data, sizeof(data)-1); |
mazgch | 16:43f6de7bc38b | 145 | if (ret == sizeof(data)-1) { |
mazgch | 19:f022ff746eb8 | 146 | printf("Socket Send %d \"%s\"\r\n", ret, data); |
mazgch | 16:43f6de7bc38b | 147 | } |
mazgch | 16:43f6de7bc38b | 148 | ret = mdm.socketRecv(socket, buf, sizeof(buf)-1); |
mazgch | 16:43f6de7bc38b | 149 | if (ret >= 0) { |
mazgch | 19:f022ff746eb8 | 150 | printf("Socket Recv %d \"%.*s\"\r\n", ret, ret, buf); |
mazgch | 16:43f6de7bc38b | 151 | } |
mazgch | 16:43f6de7bc38b | 152 | mdm.socketClose(socket); |
mazgch | 16:43f6de7bc38b | 153 | } |
mazgch | 16:43f6de7bc38b | 154 | mdm.socketFree(socket); |
mazgch | 16:43f6de7bc38b | 155 | } |
mazgch | 16:43f6de7bc38b | 156 | |
mazgch | 19:f022ff746eb8 | 157 | printf("Testing UDP sockets with ECHO server\r\n"); |
mazgch | 16:43f6de7bc38b | 158 | socket = mdm.socketSocket(MDMParser::IPPROTO_UDP, port); |
mazgch | 16:43f6de7bc38b | 159 | if (socket >= 0) |
mazgch | 16:43f6de7bc38b | 160 | { |
mazgch | 16:43f6de7bc38b | 161 | mdm.socketSetBlocking(socket, 10000); |
mazgch | 16:43f6de7bc38b | 162 | memcpy(data, "\r\nUDP", 5); |
mazgch | 16:43f6de7bc38b | 163 | ret = mdm.socketSendTo(socket, ip, port, data, sizeof(data)-1); |
mazgch | 16:43f6de7bc38b | 164 | if (ret == sizeof(data)-1) { |
mazgch | 19:f022ff746eb8 | 165 | printf("Socket SendTo %s:%d " IPSTR " %d \"%s\"\r\n", host, port, IPNUM(ip), ret, data); |
mazgch | 16:43f6de7bc38b | 166 | } |
mazgch | 16:43f6de7bc38b | 167 | ret = mdm.socketRecvFrom(socket, &ip, &port, buf, sizeof(buf)-1); |
mazgch | 16:43f6de7bc38b | 168 | if (ret >= 0) { |
mazgch | 19:f022ff746eb8 | 169 | printf("Socket RecvFrom " IPSTR ":%d %d \"%.*s\" \r\n", IPNUM(ip),port, ret, ret,buf); |
mazgch | 16:43f6de7bc38b | 170 | } |
mazgch | 16:43f6de7bc38b | 171 | mdm.socketFree(socket); |
mazgch | 16:43f6de7bc38b | 172 | } |
mazgch | 16:43f6de7bc38b | 173 | |
mazgch | 4:90ab1ec64b0e | 174 | // disconnect |
mazgch | 4:90ab1ec64b0e | 175 | mdm.disconnect(); |
mazgch | 2:b77151f111a9 | 176 | } |
mazgch | 30:062717f25e41 | 177 | |
mazgch | 30:062717f25e41 | 178 | // http://www.geckobeach.com/cellular/secrets/gsmcodes.php |
mazgch | 30:062717f25e41 | 179 | // http://de.wikipedia.org/wiki/USSD-Codes |
mazgch | 30:062717f25e41 | 180 | const char* ussd = "*130#"; // You may get answer "UNKNOWN APPLICATION" |
mazgch | 30:062717f25e41 | 181 | printf("Ussd Send Command %s\r\n", ussd); |
mazgch | 30:062717f25e41 | 182 | ret = mdm.ussdCommand(ussd, buf); |
mazgch | 30:062717f25e41 | 183 | if (ret > 0) |
mazgch | 30:062717f25e41 | 184 | printf("Ussd Got Answer: \"%s\"\r\n", buf); |
mazgch | 10:d2da2028a233 | 185 | } |
mazgch | 30:062717f25e41 | 186 | |
mazgch | 19:f022ff746eb8 | 187 | printf("SMS and GPS Loop\r\n"); |
mazgch | 10:d2da2028a233 | 188 | char link[128] = ""; |
mazgch | 10:d2da2028a233 | 189 | unsigned int i = 0xFFFFFFFF; |
mazgch | 10:d2da2028a233 | 190 | const int wait = 100; |
mazgch | 10:d2da2028a233 | 191 | bool abort = false; |
msinig | 29:16f1037626e3 | 192 | #ifdef CELLOCATE |
msinig | 29:16f1037626e3 | 193 | const int sensorMask = 3; // Hybrid: GNSS + CellLocate |
msinig | 29:16f1037626e3 | 194 | const int timeoutMargin = 5; // seconds |
msinig | 29:16f1037626e3 | 195 | const int submitPeriod = 60; // 1 minutes in seconds |
msinig | 29:16f1037626e3 | 196 | const int targetAccuracy = 1; // meters |
msinig | 29:16f1037626e3 | 197 | unsigned int j = submitPeriod * 1000/wait; |
msinig | 29:16f1037626e3 | 198 | bool cellLocWait = false; |
msinig | 29:16f1037626e3 | 199 | MDMParser::CellLocData loc; |
msinig | 29:16f1037626e3 | 200 | |
msinig | 29:16f1037626e3 | 201 | //Token can be released from u-blox site, when you got one replace "TOKEN" below |
msinig | 29:16f1037626e3 | 202 | if (!mdm.cellLocSrvHttp("TOKEN")) |
msinig | 29:16f1037626e3 | 203 | mdm.cellLocSrvUdp(); |
msinig | 29:16f1037626e3 | 204 | mdm.cellLocConfigSensor(1); // Deep scan mode |
msinig | 29:16f1037626e3 | 205 | //mdm.cellUnsolIndication(1); |
msinig | 29:16f1037626e3 | 206 | #endif |
mazgch | 11:b8505cbbd55c | 207 | //DigitalOut led(LED1); |
mazgch | 10:d2da2028a233 | 208 | while (!abort) { |
mazgch | 19:f022ff746eb8 | 209 | // led = !led; |
msinig | 29:16f1037626e3 | 210 | #ifndef CELLOCATE |
mazgch | 10:d2da2028a233 | 211 | while ((ret = gps.getMessage(buf, sizeof(buf))) > 0) |
mazgch | 10:d2da2028a233 | 212 | { |
mazgch | 10:d2da2028a233 | 213 | int len = LENGTH(ret); |
mazgch | 19:f022ff746eb8 | 214 | //printf("NMEA: %.*s\r\n", len-2, msg); |
mazgch | 19:f022ff746eb8 | 215 | if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6)) |
mazgch | 4:90ab1ec64b0e | 216 | { |
mazgch | 27:fe3b383dd4ec | 217 | // talker is $GA=Galileo $GB=Beidou $GL=Glonass $GN=Combined $GP=GPS |
mazgch | 27:fe3b383dd4ec | 218 | if ((buf[0] == '$') || buf[1] == 'G') { |
mazgch | 27:fe3b383dd4ec | 219 | #define _CHECK_TALKER(s) ((buf[3] == s[0]) && (buf[4] == s[1]) && (buf[5] == s[2])) |
mazgch | 27:fe3b383dd4ec | 220 | if (_CHECK_TALKER("GLL")) { |
mazgch | 27:fe3b383dd4ec | 221 | double la = 0, lo = 0; |
mazgch | 27:fe3b383dd4ec | 222 | char ch; |
mazgch | 27:fe3b383dd4ec | 223 | if (gps.getNmeaAngle(1,buf,len,la) && |
mazgch | 27:fe3b383dd4ec | 224 | gps.getNmeaAngle(3,buf,len,lo) && |
mazgch | 27:fe3b383dd4ec | 225 | gps.getNmeaItem(6,buf,len,ch) && ch == 'A') |
mazgch | 27:fe3b383dd4ec | 226 | { |
mazgch | 27:fe3b383dd4ec | 227 | printf("GPS Location: %.5f %.5f\r\n", la, lo); |
mazgch | 27:fe3b383dd4ec | 228 | sprintf(link, "I am here!\n" |
mazgch | 27:fe3b383dd4ec | 229 | "https://maps.google.com/?q=%.5f,%.5f", la, lo); |
mazgch | 27:fe3b383dd4ec | 230 | } |
mazgch | 27:fe3b383dd4ec | 231 | } else if (_CHECK_TALKER("GGA") || _CHECK_TALKER("GNS") ) { |
mazgch | 27:fe3b383dd4ec | 232 | double a = 0; |
mazgch | 27:fe3b383dd4ec | 233 | if (gps.getNmeaItem(9,buf,len,a)) // altitude msl [m] |
mazgch | 27:fe3b383dd4ec | 234 | printf("GPS Altitude: %.1f\r\n", a); |
mazgch | 27:fe3b383dd4ec | 235 | } else if (_CHECK_TALKER("VTG")) { |
mazgch | 27:fe3b383dd4ec | 236 | double s = 0; |
mazgch | 27:fe3b383dd4ec | 237 | if (gps.getNmeaItem(7,buf,len,s)) // speed [km/h] |
mazgch | 27:fe3b383dd4ec | 238 | printf("GPS Speed: %.1f\r\n", s); |
mazgch | 19:f022ff746eb8 | 239 | } |
mazgch | 4:90ab1ec64b0e | 240 | } |
mazgch | 4:90ab1ec64b0e | 241 | } |
mazgch | 10:d2da2028a233 | 242 | } |
msinig | 29:16f1037626e3 | 243 | #endif |
msinig | 29:16f1037626e3 | 244 | #ifdef CELLOCATE |
msinig | 29:16f1037626e3 | 245 | if (mdmOk && (j++ == submitPeriod * 1000/wait)) { |
msinig | 29:16f1037626e3 | 246 | j=0; |
msinig | 29:16f1037626e3 | 247 | printf("CellLocate Request\r\n"); |
msinig | 29:16f1037626e3 | 248 | mdm.cellLocRequest(sensorMask, submitPeriod-timeoutMargin, targetAccuracy); |
msinig | 29:16f1037626e3 | 249 | cellLocWait = true; |
msinig | 29:16f1037626e3 | 250 | } |
msinig | 29:16f1037626e3 | 251 | if (cellLocWait && mdm.cellLocGet(&loc)){ |
msinig | 29:16f1037626e3 | 252 | cellLocWait = false; |
msinig | 29:16f1037626e3 | 253 | printf("CellLocate position received, sensor_used: %d, \r\n", loc.sensorUsed ); |
msinig | 29:16f1037626e3 | 254 | printf(" latitude: %0.5f, longitude: %0.5f, altitute: %d\r\n", loc.latitue, loc.longitude, loc.altitutude); |
msinig | 29:16f1037626e3 | 255 | if (loc.sensorUsed == 1) |
msinig | 29:16f1037626e3 | 256 | printf(" uncertainty: %d, speed: %d, direction: %d, vertical_acc: %d, satellite used: %d \r\n", loc.uncertainty,loc.speed,loc.direction,loc.verticalAcc,loc.svUsed); |
msinig | 29:16f1037626e3 | 257 | if (loc.sensorUsed == 1 || loc.sensorUsed == 2) |
msinig | 29:16f1037626e3 | 258 | sprintf(link, "I am here!\n" |
msinig | 29:16f1037626e3 | 259 | "https://maps.google.com/?q=%.5f,%.5f", loc.latitue, loc.longitude); |
msinig | 29:16f1037626e3 | 260 | } |
msinig | 29:16f1037626e3 | 261 | if (cellLocWait && (j%100 == 0 )) |
msinig | 29:16f1037626e3 | 262 | printf("Waiting for CellLocate...\r\n"); |
msinig | 29:16f1037626e3 | 263 | #endif |
mazgch | 19:f022ff746eb8 | 264 | if (mdmOk && (i++ == 5000/wait)) { |
mazgch | 10:d2da2028a233 | 265 | i = 0; |
mazgch | 10:d2da2028a233 | 266 | // check the network status |
mazgch | 15:ea10b6cf8c85 | 267 | if (mdm.checkNetStatus(&netStatus)) { |
mazgch | 19:f022ff746eb8 | 268 | mdm.dumpNetStatus(&netStatus, fprintf, stdout); |
mazgch | 15:ea10b6cf8c85 | 269 | } |
mazgch | 10:d2da2028a233 | 270 | |
mazgch | 10:d2da2028a233 | 271 | // checking unread sms |
mazgch | 10:d2da2028a233 | 272 | int ix[8]; |
mazgch | 10:d2da2028a233 | 273 | int n = mdm.smsList("REC UNREAD", ix, 8); |
mazgch | 10:d2da2028a233 | 274 | if (8 < n) n = 8; |
mazgch | 10:d2da2028a233 | 275 | while (0 < n--) |
mazgch | 10:d2da2028a233 | 276 | { |
mazgch | 10:d2da2028a233 | 277 | char num[32]; |
mazgch | 19:f022ff746eb8 | 278 | printf("Unread SMS at index %d\r\n", ix[n]); |
mazgch | 10:d2da2028a233 | 279 | if (mdm.smsRead(ix[n], num, buf, sizeof(buf))) { |
mazgch | 19:f022ff746eb8 | 280 | printf("Got SMS from \"%s\" with text \"%s\"\r\n", num, buf); |
mazgch | 19:f022ff746eb8 | 281 | printf("Delete SMS at index %d\r\n", ix[n]); |
mazgch | 10:d2da2028a233 | 282 | mdm.smsDelete(ix[n]); |
mazgch | 10:d2da2028a233 | 283 | // provide a reply |
mazgch | 10:d2da2028a233 | 284 | const char* reply = "Hello my friend"; |
mazgch | 10:d2da2028a233 | 285 | if (strstr(buf, /*w*/"here are you")) |
mazgch | 10:d2da2028a233 | 286 | reply = *link ? link : "I don't know"; // reply wil location link |
mazgch | 19:f022ff746eb8 | 287 | else if (strstr(buf, /*s*/"hutdown")) |
mazgch | 19:f022ff746eb8 | 288 | abort = true, reply = "bye bye"; |
mazgch | 19:f022ff746eb8 | 289 | printf("Send SMS reply \"%s\" to \"%s\"\r\n", reply, num); |
mazgch | 10:d2da2028a233 | 290 | mdm.smsSend(num, reply); |
mazgch | 4:90ab1ec64b0e | 291 | } |
mazgch | 4:90ab1ec64b0e | 292 | } |
mazgch | 9:26f694bc31b4 | 293 | } |
mazgch | 31:a07d0f76dc81 | 294 | #ifdef RTOS_H |
mazgch | 31:a07d0f76dc81 | 295 | Thread::wait(wait); |
mazgch | 31:a07d0f76dc81 | 296 | #else |
mazgch | 31:a07d0f76dc81 | 297 | ::wait_ms(wait); |
mazgch | 31:a07d0f76dc81 | 298 | #endif |
lawliet | 0:4e3cb26f6019 | 299 | } |
mazgch | 19:f022ff746eb8 | 300 | gps.powerOff(); |
mazgch | 10:d2da2028a233 | 301 | mdm.powerOff(); |
lawliet | 0:4e3cb26f6019 | 302 | return 0; |
lawliet | 0:4e3cb26f6019 | 303 | } |