インターフェース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 13:47:03 2014 +0000
Revision:
31:22a4e87217f8
Parent:
30:e6c7827dfbe8
Child:
32:2ad9c1d1afd0
JSON???location?update???????; picojson??;

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