インターフェース2014年10月号のu-blox C027で3G通信する記事で使用したプログラム。   CQ publishing Interface 2014.10 issue, C027 3G test program.

Dependencies:   C027_Support C027_SupportTest mbed picojson

Fork of C027_SupportTest by u-blox

インターフェース2014年10月号のu-blox C027で3G通信する記事で使用したプログラムです。

Committer:
ntaka206
Date:
Thu Jul 17 10:06:02 2014 +0000
Revision:
30:e6c7827dfbe8
Parent:
29:1f18e74ff972
Child:
31:22a4e87217f8
Xively?3G?lat,lon?POST?????????

Who changed what in which revision?

UserRevisionLine numberNew 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 19:f022ff746eb8 23 #define SIMPIN NULL
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 */
ntaka206 26:712544e993ff 27 //#define APN NULL
ntaka206 26:712544e993ff 28 #define APN "3g-d-2.ocn.ne.jp"
mazgch 19:f022ff746eb8 29 //! Set the user name for your APN, or NULL if not needed
ntaka206 26:712544e993ff 30 //#define USERNAME NULL
ntaka206 26:712544e993ff 31 #define USERNAME "a743mcx2@one.ocn.ne.jp"
mazgch 19:f022ff746eb8 32 //! Set the password for your APN, or NULL if not needed
ntaka206 26:712544e993ff 33 //#define PASSWORD NULL
ntaka206 26:712544e993ff 34 #define PASSWORD "nnku62"
ntaka206 26:712544e993ff 35
ntaka206 28:d504a106c124 36 //---- Xively --------------------------------------------------------------
ntaka206 30:e6c7827dfbe8 37 #define XI_FEED_ID "1016719601" // set Xively Feed ID (numerical, no quoutes)
ntaka206 29:1f18e74ff972 38 #define XI_API_KEY "Y1mN05SzFgxjwiB9xFj42KYaTzdhohBLaKN8a9juznDrGsvK" // set Xively API key (double-quoted string)
ntaka206 28:d504a106c124 39
ntaka206 30:e6c7827dfbe8 40 #define XI_SERVER "api.xively.com"
ntaka206 30:e6c7827dfbe8 41 //#define XI_PATH "POST /v2/feeds/" XI_FEED_ID ".csv?_method=put "
ntaka206 30:e6c7827dfbe8 42 //#define XI_HEADER "X-ApiKey: " XI_API_KEY "\r\nContent-Type: text/csv\r\n"
ntaka206 28:d504a106c124 43
ntaka206 30:e6c7827dfbe8 44 #define XI_PATH "/v2/feeds/" XI_FEED_ID ".csv"
ntaka206 30:e6c7827dfbe8 45 #define XI_HEADER "X-ApiKey: " XI_API_KEY
ntaka206 30:e6c7827dfbe8 46
ntaka206 30:e6c7827dfbe8 47 #define XI_UPLOAD_INTERVAL 30 // sec
mazgch 19:f022ff746eb8 48 //------------------------------------------------------------------------------------
lawliet 0:4e3cb26f6019 49
lawliet 0:4e3cb26f6019 50 int main(void)
lawliet 0:4e3cb26f6019 51 {
mazgch 2:b77151f111a9 52 int ret;
mazgch 19:f022ff746eb8 53 #ifdef LARGE_DATA
mazgch 16:43f6de7bc38b 54 char buf[2048] = "";
mazgch 17:c293780a40ac 55 #else
mazgch 17:c293780a40ac 56 char buf[512] = "";
mazgch 17:c293780a40ac 57 #endif
ntaka206 26:712544e993ff 58 // ntaka
ntaka206 26:712544e993ff 59 Serial pc(USBTX,USBRX);
ntaka206 26:712544e993ff 60 pc.baud(115200);
lawliet 0:4e3cb26f6019 61
mazgch 19:f022ff746eb8 62 // Create the GPS object
mazgch 19:f022ff746eb8 63 #if 1 // use GPSI2C class
mazgch 19:f022ff746eb8 64 GPSI2C gps;
mazgch 19:f022ff746eb8 65 #else // or GPSSerial class
mazgch 19:f022ff746eb8 66 GPSSerial gps;
mazgch 10:d2da2028a233 67 #endif
mazgch 10:d2da2028a233 68 // Create the modem object
mazgch 19:f022ff746eb8 69 MDMSerial mdm;
mazgch 22:078f410ef2c7 70 //mdm.setDebug(4); // enable this for debugging issues
mazgch 2:b77151f111a9 71 // initialize the modem
mazgch 19:f022ff746eb8 72 MDMParser::DevStatus devStatus = {};
mazgch 19:f022ff746eb8 73 MDMParser::NetStatus netStatus = {};
mazgch 10:d2da2028a233 74 bool mdmOk = mdm.init(SIMPIN, &devStatus);
mazgch 19:f022ff746eb8 75 mdm.dumpDevStatus(&devStatus);
mazgch 19:f022ff746eb8 76 if (mdmOk) {
mazgch 20:52f0e5de8c3d 77 #if 0
mazgch 20:52f0e5de8c3d 78 // file system API
mazgch 19:f022ff746eb8 79 const char* filename = "File";
mazgch 19:f022ff746eb8 80 char buf[] = "Hello World";
mazgch 19:f022ff746eb8 81 printf("writeFile \"%s\"\r\n", buf);
mazgch 19:f022ff746eb8 82 if (mdm.writeFile(filename, buf, sizeof(buf)))
mazgch 19:f022ff746eb8 83 {
mazgch 19:f022ff746eb8 84 memset(buf, 0, sizeof(buf));
mazgch 19:f022ff746eb8 85 int len = mdm.readFile(filename, buf, sizeof(buf));
mazgch 24:81f5b43a6585 86 if (len >= 0)
mazgch 19:f022ff746eb8 87 printf("readFile %d \"%.*s\"\r\n", len, len, buf);
mazgch 19:f022ff746eb8 88 mdm.delFile(filename);
mazgch 19:f022ff746eb8 89 }
mazgch 20:52f0e5de8c3d 90 #endif
mazgch 20:52f0e5de8c3d 91
mazgch 20:52f0e5de8c3d 92 // wait until we are connected
mazgch 20:52f0e5de8c3d 93 mdmOk = mdm.registerNet(&netStatus);
mazgch 20:52f0e5de8c3d 94 mdm.dumpNetStatus(&netStatus);
mazgch 20:52f0e5de8c3d 95 }
ntaka206 29:1f18e74ff972 96 #if 1
ntaka206 28:d504a106c124 97
mazgch 20:52f0e5de8c3d 98 if (mdmOk)
mazgch 20:52f0e5de8c3d 99 {
mazgch 19:f022ff746eb8 100 // http://www.geckobeach.com/cellular/secrets/gsmcodes.php
mazgch 19:f022ff746eb8 101 // http://de.wikipedia.org/wiki/USSD-Codes
mazgch 19:f022ff746eb8 102 const char* ussd = "*130#"; // You may get answer "UNKNOWN APPLICATION"
mazgch 19:f022ff746eb8 103 printf("Ussd Send Command %s\r\n", ussd);
mazgch 19:f022ff746eb8 104 ret = mdm.ussdCommand(ussd, buf);
mazgch 19:f022ff746eb8 105 if (ret > 0)
mazgch 19:f022ff746eb8 106 printf("Ussd Got Answer: \"%*s\"\r\n", ret, buf);
mazgch 19:f022ff746eb8 107
mazgch 4:90ab1ec64b0e 108 // join the internet connection
mazgch 19:f022ff746eb8 109 MDMParser::IP ip = mdm.join(APN,USERNAME,PASSWORD);
mazgch 5:5366d39d3719 110 if (ip != NOIP)
mazgch 2:b77151f111a9 111 {
mazgch 19:f022ff746eb8 112 mdm.dumpIp(ip);
mazgch 19:f022ff746eb8 113 printf("Make a Http Post Request\r\n");
mazgch 4:90ab1ec64b0e 114 int socket = mdm.socketSocket(MDMParser::IPPROTO_TCP);
mazgch 4:90ab1ec64b0e 115 if (socket >= 0)
mazgch 2:b77151f111a9 116 {
mazgch 16:43f6de7bc38b 117 mdm.socketSetBlocking(socket, 10000);
mazgch 4:90ab1ec64b0e 118 if (mdm.socketConnect(socket, "mbed.org", 80))
mazgch 4:90ab1ec64b0e 119 {
mazgch 4:90ab1ec64b0e 120 const char http[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\r\n\r\n";
mazgch 4:90ab1ec64b0e 121 mdm.socketSend(socket, http, sizeof(http)-1);
mazgch 4:90ab1ec64b0e 122
mazgch 19:f022ff746eb8 123 ret = mdm.socketRecv(socket, buf, sizeof(buf)-1);
mazgch 19:f022ff746eb8 124 if (ret > 0)
mazgch 19:f022ff746eb8 125 printf("Socket Recv \"%*s\"\r\n", ret, buf);
mazgch 4:90ab1ec64b0e 126 mdm.socketClose(socket);
mazgch 4:90ab1ec64b0e 127 }
mazgch 4:90ab1ec64b0e 128 mdm.socketFree(socket);
mazgch 4:90ab1ec64b0e 129 }
ntaka206 30:e6c7827dfbe8 130 #if 0
mazgch 2:b77151f111a9 131
mazgch 16:43f6de7bc38b 132 int port = 7;
mazgch 16:43f6de7bc38b 133 const char* host = "echo.u-blox.com";
mazgch 16:43f6de7bc38b 134 MDMParser::IP ip = mdm.gethostbyname(host);
mazgch 16:43f6de7bc38b 135 char data[] = "\r\nxxx Socket Hello World\r\n"
mazgch 19:f022ff746eb8 136 #ifdef LARGE_DATA
mazgch 17:c293780a40ac 137 "00 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 138 "01 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 139 "02 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 140 "03 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 141 "04 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 142
mazgch 17:c293780a40ac 143 "05 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 144 "06 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 145 "07 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 146 "08 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 147 "09 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 16:43f6de7bc38b 148
mazgch 17:c293780a40ac 149 "10 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 150 "11 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 151 "12 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 152 "13 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 153 "14 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 154
mazgch 17:c293780a40ac 155 "15 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 156 "16 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 157 "17 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 158 "18 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 159 "19 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 16:43f6de7bc38b 160 #endif
mazgch 17:c293780a40ac 161 "End\r\n";
mazgch 16:43f6de7bc38b 162
mazgch 19:f022ff746eb8 163 printf("Testing TCP sockets with ECHO server\r\n");
mazgch 16:43f6de7bc38b 164 socket = mdm.socketSocket(MDMParser::IPPROTO_TCP);
mazgch 16:43f6de7bc38b 165 if (socket >= 0)
mazgch 16:43f6de7bc38b 166 {
mazgch 16:43f6de7bc38b 167 mdm.socketSetBlocking(socket, 10000);
mazgch 16:43f6de7bc38b 168 if (mdm.socketConnect(socket, host, port)) {
mazgch 16:43f6de7bc38b 169 memcpy(data, "\r\nTCP", 5);
mazgch 16:43f6de7bc38b 170 ret = mdm.socketSend(socket, data, sizeof(data)-1);
mazgch 16:43f6de7bc38b 171 if (ret == sizeof(data)-1) {
mazgch 19:f022ff746eb8 172 printf("Socket Send %d \"%s\"\r\n", ret, data);
mazgch 16:43f6de7bc38b 173 }
mazgch 16:43f6de7bc38b 174 ret = mdm.socketRecv(socket, buf, sizeof(buf)-1);
mazgch 16:43f6de7bc38b 175 if (ret >= 0) {
mazgch 19:f022ff746eb8 176 printf("Socket Recv %d \"%.*s\"\r\n", ret, ret, buf);
mazgch 16:43f6de7bc38b 177 }
mazgch 16:43f6de7bc38b 178 mdm.socketClose(socket);
mazgch 16:43f6de7bc38b 179 }
mazgch 16:43f6de7bc38b 180 mdm.socketFree(socket);
mazgch 16:43f6de7bc38b 181 }
mazgch 16:43f6de7bc38b 182
mazgch 19:f022ff746eb8 183 printf("Testing UDP sockets with ECHO server\r\n");
mazgch 16:43f6de7bc38b 184 socket = mdm.socketSocket(MDMParser::IPPROTO_UDP, port);
mazgch 16:43f6de7bc38b 185 if (socket >= 0)
mazgch 16:43f6de7bc38b 186 {
mazgch 16:43f6de7bc38b 187 mdm.socketSetBlocking(socket, 10000);
mazgch 16:43f6de7bc38b 188 memcpy(data, "\r\nUDP", 5);
mazgch 16:43f6de7bc38b 189 ret = mdm.socketSendTo(socket, ip, port, data, sizeof(data)-1);
mazgch 16:43f6de7bc38b 190 if (ret == sizeof(data)-1) {
mazgch 19:f022ff746eb8 191 printf("Socket SendTo %s:%d " IPSTR " %d \"%s\"\r\n", host, port, IPNUM(ip), ret, data);
mazgch 16:43f6de7bc38b 192 }
mazgch 16:43f6de7bc38b 193 ret = mdm.socketRecvFrom(socket, &ip, &port, buf, sizeof(buf)-1);
mazgch 16:43f6de7bc38b 194 if (ret >= 0) {
mazgch 19:f022ff746eb8 195 printf("Socket RecvFrom " IPSTR ":%d %d \"%.*s\" \r\n", IPNUM(ip),port, ret, ret,buf);
mazgch 16:43f6de7bc38b 196 }
mazgch 16:43f6de7bc38b 197 mdm.socketFree(socket);
mazgch 16:43f6de7bc38b 198 }
ntaka206 30:e6c7827dfbe8 199 #endif
ntaka206 30:e6c7827dfbe8 200
ntaka206 30:e6c7827dfbe8 201 // no disconnect
mazgch 4:90ab1ec64b0e 202 // disconnect
ntaka206 30:e6c7827dfbe8 203 // mdm.disconnect();
mazgch 2:b77151f111a9 204 }
mazgch 10:d2da2028a233 205 }
ntaka206 29:1f18e74ff972 206 #endif
ntaka206 29:1f18e74ff972 207
ntaka206 29:1f18e74ff972 208 // Xively
ntaka206 29:1f18e74ff972 209
mazgch 19:f022ff746eb8 210 printf("SMS and GPS Loop\r\n");
mazgch 10:d2da2028a233 211 char link[128] = "";
mazgch 10:d2da2028a233 212 unsigned int i = 0xFFFFFFFF;
mazgch 10:d2da2028a233 213 const int wait = 100;
mazgch 10:d2da2028a233 214 bool abort = false;
ntaka206 30:e6c7827dfbe8 215 int xv_upload_cnt = XI_UPLOAD_INTERVAL;
mazgch 11:b8505cbbd55c 216 //DigitalOut led(LED1);
mazgch 10:d2da2028a233 217 while (!abort) {
mazgch 19:f022ff746eb8 218 // led = !led;
mazgch 10:d2da2028a233 219 while ((ret = gps.getMessage(buf, sizeof(buf))) > 0)
mazgch 10:d2da2028a233 220 {
mazgch 10:d2da2028a233 221 int len = LENGTH(ret);
mazgch 19:f022ff746eb8 222 //printf("NMEA: %.*s\r\n", len-2, msg);
mazgch 19:f022ff746eb8 223 if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6))
mazgch 4:90ab1ec64b0e 224 {
mazgch 19:f022ff746eb8 225 if (!strncmp("$GPGLL", buf, 6)) {
mazgch 19:f022ff746eb8 226 double la = 0, lo = 0;
mazgch 19:f022ff746eb8 227 char ch;
mazgch 19:f022ff746eb8 228 if (gps.getNmeaAngle(1,buf,len,la) &&
mazgch 19:f022ff746eb8 229 gps.getNmeaAngle(3,buf,len,lo) &&
mazgch 19:f022ff746eb8 230 gps.getNmeaItem(6,buf,len,ch) && ch == 'A')
mazgch 19:f022ff746eb8 231 {
mazgch 19:f022ff746eb8 232 printf("GPS Location: %.5f %.5f\r\n", la, lo);
mazgch 19:f022ff746eb8 233 sprintf(link, "I am here!\n"
mazgch 19:f022ff746eb8 234 "https://maps.google.com/?q=%.5f,%.5f", la, lo);
ntaka206 30:e6c7827dfbe8 235 // Xively
ntaka206 30:e6c7827dfbe8 236 if (xv_upload_cnt++ >= XI_UPLOAD_INTERVAL) {
ntaka206 30:e6c7827dfbe8 237 xv_upload_cnt = 0;
ntaka206 30:e6c7827dfbe8 238 int socket = mdm.socketSocket(MDMParser::IPPROTO_TCP);
ntaka206 30:e6c7827dfbe8 239 if (socket >= 0)
ntaka206 30:e6c7827dfbe8 240 {
ntaka206 30:e6c7827dfbe8 241 mdm.socketSetBlocking(socket, 10000);
ntaka206 30:e6c7827dfbe8 242 if (mdm.socketConnect(socket, XI_SERVER, 80))
ntaka206 30:e6c7827dfbe8 243 {
ntaka206 30:e6c7827dfbe8 244
ntaka206 30:e6c7827dfbe8 245 // const char http[] = "POST /media/uploads/mbed_official/hello.txt HTTP/1.0\r\n\r\n";
ntaka206 30:e6c7827dfbe8 246 // mdm.socketSend(socket, XI_PATH, sizeof(XI_PATH)-1);
ntaka206 30:e6c7827dfbe8 247 // mdm.socketSend(socket, XI_HEADER, sizeof(XI_HEADER)-1);
ntaka206 30:e6c7827dfbe8 248 char http[512];
ntaka206 30:e6c7827dfbe8 249 char data[128];
ntaka206 30:e6c7827dfbe8 250 sprintf(data, "lat,%f\r\nlon,%f\r\n", la, lo);
ntaka206 30:e6c7827dfbe8 251 sprintf(http, "PUT %s HTTP/1.1\r\nHost: %s\r\n%s\r\nContent-Length: %d\r\n\r\n%s", XI_PATH, XI_SERVER, XI_HEADER, strlen(data), data);
ntaka206 30:e6c7827dfbe8 252 printf(http);
ntaka206 30:e6c7827dfbe8 253 mdm.socketSend(socket, http, strlen(http));
ntaka206 29:1f18e74ff972 254
ntaka206 30:e6c7827dfbe8 255 ret = mdm.socketRecv(socket, buf, sizeof(buf)-1);
ntaka206 30:e6c7827dfbe8 256 if (ret > 0)
ntaka206 30:e6c7827dfbe8 257 printf("Socket Recv \"%*s\"\r\n", ret, buf);
ntaka206 30:e6c7827dfbe8 258 mdm.socketClose(socket);
ntaka206 30:e6c7827dfbe8 259 }
ntaka206 30:e6c7827dfbe8 260 mdm.socketFree(socket);
ntaka206 30:e6c7827dfbe8 261 }
ntaka206 30:e6c7827dfbe8 262 }
mazgch 19:f022ff746eb8 263 }
mazgch 19:f022ff746eb8 264 } else if (!strncmp("$GPGGA", buf, 6)) {
mazgch 19:f022ff746eb8 265 double a = 0;
mazgch 19:f022ff746eb8 266 if (gps.getNmeaItem(9,buf,len,a)) // altitude msl [m]
mazgch 19:f022ff746eb8 267 printf("GPS Altitude: %.1f\r\n", a);
mazgch 19:f022ff746eb8 268 } else if (!strncmp("$GPVTG", buf, 6)) {
mazgch 19:f022ff746eb8 269 double s = 0;
mazgch 19:f022ff746eb8 270 if (gps.getNmeaItem(7,buf,len,s)) // speed [km/h]
mazgch 19:f022ff746eb8 271 printf("GPS Speed: %.1f\r\n", s);
mazgch 4:90ab1ec64b0e 272 }
mazgch 4:90ab1ec64b0e 273 }
mazgch 10:d2da2028a233 274 }
mazgch 19:f022ff746eb8 275 if (mdmOk && (i++ == 5000/wait)) {
mazgch 10:d2da2028a233 276 i = 0;
mazgch 10:d2da2028a233 277 // check the network status
mazgch 15:ea10b6cf8c85 278 if (mdm.checkNetStatus(&netStatus)) {
mazgch 19:f022ff746eb8 279 mdm.dumpNetStatus(&netStatus, fprintf, stdout);
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 19:f022ff746eb8 289 printf("Unread SMS at index %d\r\n", ix[n]);
mazgch 10:d2da2028a233 290 if (mdm.smsRead(ix[n], num, buf, sizeof(buf))) {
mazgch 19:f022ff746eb8 291 printf("Got SMS from \"%s\" with text \"%s\"\r\n", num, buf);
mazgch 19:f022ff746eb8 292 printf("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 19:f022ff746eb8 298 else if (strstr(buf, /*s*/"hutdown"))
mazgch 19:f022ff746eb8 299 abort = true, reply = "bye bye";
mazgch 19:f022ff746eb8 300 printf("Send SMS reply \"%s\" to \"%s\"\r\n", reply, num);
mazgch 10:d2da2028a233 301 mdm.smsSend(num, reply);
mazgch 4:90ab1ec64b0e 302 }
mazgch 4:90ab1ec64b0e 303 }
mazgch 9:26f694bc31b4 304 }
mazgch 10:d2da2028a233 305 wait_ms(wait);
lawliet 0:4e3cb26f6019 306 }
mazgch 19:f022ff746eb8 307 gps.powerOff();
mazgch 10:d2da2028a233 308 mdm.powerOff();
lawliet 0:4e3cb26f6019 309 return 0;
lawliet 0:4e3cb26f6019 310 }