C027_Support library test

Dependencies:   C027_Support

Dependents:   C027_SupportTest_xively_location software_test_v1

Fork of Seeed_GPRS_Library_HelloWorld by wei zou

When running this example make sure you have:

  • edited the SIM PIN, APN, USER and PASSWORD for you network operator
  • have inserted a SIM card with enough credits
  • the antennas connected
  • have good reception (especially for GPS)
  • installed the mbed CDC drivers if you run windows
  • connected a terminal program, such as teraterm

The example will connect the modem to the network and attach it. I will place a post request to download a file from mbed website. It will do a USSD request and finally wait for incoming SMS. It will try to answer your SMS (try asking "where are you").

You should see a similar output in your preferred console program:

C027 Support Example
Device Init
Device Status:
  Device:       SARA-G350
  Power Save:   Active
  SIM:          Ready
  CCID:         xxxxxxxxxxxxxxxxxxxxxxxxxxx
  IMEI:         xxxxxxxxxxxxxxxxxxx
  IMSI:         xxxxxxxxxxxxxxxxxxx
  Manufacturer: u-blox
  Model:        SARA-G350
  Version:      08.49
Network Check
Network Status:
  Registration:       Home
  Signal Strength:    -87 dBm
  Operator:           Swisscom
  Phone Number:       +41xxxxxxxxxxx
Network Join
  IP Address: xx.xx.xx.xx
Socket Create
Socket Connect
Make a Http Post Request
Socket Send
Socket Recving
Socket 0: 337 bytes pending
Socket 0: 145 bytes pending
Socket 0: closed by remote host
Socket Recv "HTTP/1.1 200 OK
Server: nginx/1.1.19
Date: Thu, 10 Apr 2014 13:09:02 GMT
Content-Type: text/plain
Connection: close
Last-Modified: Fri, 27 Jul 2012 13:30:34 GMT
Cache-Control: max-age=36000
Expires: Thu, 10 Apr 2014 20:43:53 GMT
Vary: Accept-Encoding
X-Mystery-Header: 260358892
X-be: web0_prod_sjc
Age: 8709

Hello world!
"
Socket Close
Socket Free
Network Disconnect
Send Ussd Command *#134#
Got Ussd Answer: "UNKNOWN APPLICATION"
Checking SMS and GPS
GPS Location: 47.28xxx 8.56xxx
GPS Location: 47.28xxx 8.56xxx
...
GPS Location: 47.28xxx 8.56xxx
GPS Location: 47.28xxx 8.56xxx
Network Status:
  Registration:       Home
  Signal Strength:    -89 dBm
  Operator:           Swisscom
  Phone Number:       +41xxxxxxxxx
GPS Location: 47.28xxx 8.56xxx
GPS Location: 47.28xxx 8.56xxx
...
Committer:
mazgch
Date:
Thu Aug 11 07:04:52 2016 +0000
Revision:
31:a07d0f76dc81
Parent:
29:16f1037626e3
Child:
32:b838fcaba45e
import mbed 5.1

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 */
mazgch 21:a090a5043e23 27 #define APN NULL
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 31:a07d0f76dc81 52 MDMSerial mdm; // use mdm(D1,D0) if you connect the cellular shield to 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 19:f022ff746eb8 81 // http://www.geckobeach.com/cellular/secrets/gsmcodes.php
mazgch 19:f022ff746eb8 82 // http://de.wikipedia.org/wiki/USSD-Codes
mazgch 19:f022ff746eb8 83 const char* ussd = "*130#"; // You may get answer "UNKNOWN APPLICATION"
mazgch 19:f022ff746eb8 84 printf("Ussd Send Command %s\r\n", ussd);
mazgch 19:f022ff746eb8 85 ret = mdm.ussdCommand(ussd, buf);
mazgch 19:f022ff746eb8 86 if (ret > 0)
mazgch 19:f022ff746eb8 87 printf("Ussd Got Answer: \"%*s\"\r\n", ret, buf);
mazgch 19:f022ff746eb8 88
mazgch 4:90ab1ec64b0e 89 // join the internet connection
mazgch 19:f022ff746eb8 90 MDMParser::IP ip = mdm.join(APN,USERNAME,PASSWORD);
mazgch 28:334263983fcd 91 if (ip != NOIP)
mazgch 2:b77151f111a9 92 {
mazgch 19:f022ff746eb8 93 mdm.dumpIp(ip);
mazgch 19:f022ff746eb8 94 printf("Make a Http Post Request\r\n");
mazgch 4:90ab1ec64b0e 95 int socket = mdm.socketSocket(MDMParser::IPPROTO_TCP);
mazgch 4:90ab1ec64b0e 96 if (socket >= 0)
mazgch 2:b77151f111a9 97 {
mazgch 16:43f6de7bc38b 98 mdm.socketSetBlocking(socket, 10000);
mazgch 4:90ab1ec64b0e 99 if (mdm.socketConnect(socket, "mbed.org", 80))
mazgch 4:90ab1ec64b0e 100 {
mazgch 4:90ab1ec64b0e 101 const char http[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\r\n\r\n";
mazgch 4:90ab1ec64b0e 102 mdm.socketSend(socket, http, sizeof(http)-1);
mazgch 4:90ab1ec64b0e 103
mazgch 19:f022ff746eb8 104 ret = mdm.socketRecv(socket, buf, sizeof(buf)-1);
mazgch 19:f022ff746eb8 105 if (ret > 0)
mazgch 19:f022ff746eb8 106 printf("Socket Recv \"%*s\"\r\n", ret, buf);
mazgch 4:90ab1ec64b0e 107 mdm.socketClose(socket);
mazgch 4:90ab1ec64b0e 108 }
mazgch 4:90ab1ec64b0e 109 mdm.socketFree(socket);
mazgch 4:90ab1ec64b0e 110 }
mazgch 2:b77151f111a9 111
mazgch 16:43f6de7bc38b 112 int port = 7;
mazgch 16:43f6de7bc38b 113 const char* host = "echo.u-blox.com";
mazgch 16:43f6de7bc38b 114 MDMParser::IP ip = mdm.gethostbyname(host);
mazgch 16:43f6de7bc38b 115 char data[] = "\r\nxxx Socket Hello World\r\n"
mazgch 19:f022ff746eb8 116 #ifdef LARGE_DATA
mazgch 17:c293780a40ac 117 "00 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 118 "01 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 119 "02 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 120 "03 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 121 "04 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 122
mazgch 17:c293780a40ac 123 "05 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 124 "06 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 125 "07 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 126 "08 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 127 "09 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 16:43f6de7bc38b 128
mazgch 17:c293780a40ac 129 "10 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 130 "11 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 131 "12 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 132 "13 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 133 "14 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 134
mazgch 17:c293780a40ac 135 "15 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 136 "16 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 137 "17 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 138 "18 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 17:c293780a40ac 139 "19 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n"
mazgch 16:43f6de7bc38b 140 #endif
mazgch 17:c293780a40ac 141 "End\r\n";
mazgch 16:43f6de7bc38b 142
mazgch 19:f022ff746eb8 143 printf("Testing TCP sockets with ECHO server\r\n");
mazgch 16:43f6de7bc38b 144 socket = mdm.socketSocket(MDMParser::IPPROTO_TCP);
mazgch 16:43f6de7bc38b 145 if (socket >= 0)
mazgch 16:43f6de7bc38b 146 {
mazgch 16:43f6de7bc38b 147 mdm.socketSetBlocking(socket, 10000);
mazgch 16:43f6de7bc38b 148 if (mdm.socketConnect(socket, host, port)) {
mazgch 16:43f6de7bc38b 149 memcpy(data, "\r\nTCP", 5);
mazgch 16:43f6de7bc38b 150 ret = mdm.socketSend(socket, data, sizeof(data)-1);
mazgch 16:43f6de7bc38b 151 if (ret == sizeof(data)-1) {
mazgch 19:f022ff746eb8 152 printf("Socket Send %d \"%s\"\r\n", ret, data);
mazgch 16:43f6de7bc38b 153 }
mazgch 16:43f6de7bc38b 154 ret = mdm.socketRecv(socket, buf, sizeof(buf)-1);
mazgch 16:43f6de7bc38b 155 if (ret >= 0) {
mazgch 19:f022ff746eb8 156 printf("Socket Recv %d \"%.*s\"\r\n", ret, ret, buf);
mazgch 16:43f6de7bc38b 157 }
mazgch 16:43f6de7bc38b 158 mdm.socketClose(socket);
mazgch 16:43f6de7bc38b 159 }
mazgch 16:43f6de7bc38b 160 mdm.socketFree(socket);
mazgch 16:43f6de7bc38b 161 }
mazgch 16:43f6de7bc38b 162
mazgch 19:f022ff746eb8 163 printf("Testing UDP sockets with ECHO server\r\n");
mazgch 16:43f6de7bc38b 164 socket = mdm.socketSocket(MDMParser::IPPROTO_UDP, port);
mazgch 16:43f6de7bc38b 165 if (socket >= 0)
mazgch 16:43f6de7bc38b 166 {
mazgch 16:43f6de7bc38b 167 mdm.socketSetBlocking(socket, 10000);
mazgch 16:43f6de7bc38b 168 memcpy(data, "\r\nUDP", 5);
mazgch 16:43f6de7bc38b 169 ret = mdm.socketSendTo(socket, ip, port, data, sizeof(data)-1);
mazgch 16:43f6de7bc38b 170 if (ret == sizeof(data)-1) {
mazgch 19:f022ff746eb8 171 printf("Socket SendTo %s:%d " IPSTR " %d \"%s\"\r\n", host, port, IPNUM(ip), ret, data);
mazgch 16:43f6de7bc38b 172 }
mazgch 16:43f6de7bc38b 173 ret = mdm.socketRecvFrom(socket, &ip, &port, buf, sizeof(buf)-1);
mazgch 16:43f6de7bc38b 174 if (ret >= 0) {
mazgch 19:f022ff746eb8 175 printf("Socket RecvFrom " IPSTR ":%d %d \"%.*s\" \r\n", IPNUM(ip),port, ret, ret,buf);
mazgch 16:43f6de7bc38b 176 }
mazgch 16:43f6de7bc38b 177 mdm.socketFree(socket);
mazgch 16:43f6de7bc38b 178 }
mazgch 16:43f6de7bc38b 179
mazgch 4:90ab1ec64b0e 180 // disconnect
mazgch 4:90ab1ec64b0e 181 mdm.disconnect();
mazgch 2:b77151f111a9 182 }
mazgch 10:d2da2028a233 183 }
mazgch 19:f022ff746eb8 184 printf("SMS and GPS Loop\r\n");
mazgch 10:d2da2028a233 185 char link[128] = "";
mazgch 10:d2da2028a233 186 unsigned int i = 0xFFFFFFFF;
mazgch 10:d2da2028a233 187 const int wait = 100;
mazgch 10:d2da2028a233 188 bool abort = false;
msinig 29:16f1037626e3 189 #ifdef CELLOCATE
msinig 29:16f1037626e3 190 const int sensorMask = 3; // Hybrid: GNSS + CellLocate
msinig 29:16f1037626e3 191 const int timeoutMargin = 5; // seconds
msinig 29:16f1037626e3 192 const int submitPeriod = 60; // 1 minutes in seconds
msinig 29:16f1037626e3 193 const int targetAccuracy = 1; // meters
msinig 29:16f1037626e3 194 unsigned int j = submitPeriod * 1000/wait;
msinig 29:16f1037626e3 195 bool cellLocWait = false;
msinig 29:16f1037626e3 196 MDMParser::CellLocData loc;
msinig 29:16f1037626e3 197
msinig 29:16f1037626e3 198 //Token can be released from u-blox site, when you got one replace "TOKEN" below
msinig 29:16f1037626e3 199 if (!mdm.cellLocSrvHttp("TOKEN"))
msinig 29:16f1037626e3 200 mdm.cellLocSrvUdp();
msinig 29:16f1037626e3 201 mdm.cellLocConfigSensor(1); // Deep scan mode
msinig 29:16f1037626e3 202 //mdm.cellUnsolIndication(1);
msinig 29:16f1037626e3 203 #endif
mazgch 11:b8505cbbd55c 204 //DigitalOut led(LED1);
mazgch 10:d2da2028a233 205 while (!abort) {
mazgch 19:f022ff746eb8 206 // led = !led;
msinig 29:16f1037626e3 207 #ifndef CELLOCATE
mazgch 10:d2da2028a233 208 while ((ret = gps.getMessage(buf, sizeof(buf))) > 0)
mazgch 10:d2da2028a233 209 {
mazgch 10:d2da2028a233 210 int len = LENGTH(ret);
mazgch 19:f022ff746eb8 211 //printf("NMEA: %.*s\r\n", len-2, msg);
mazgch 19:f022ff746eb8 212 if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6))
mazgch 4:90ab1ec64b0e 213 {
mazgch 27:fe3b383dd4ec 214 // talker is $GA=Galileo $GB=Beidou $GL=Glonass $GN=Combined $GP=GPS
mazgch 27:fe3b383dd4ec 215 if ((buf[0] == '$') || buf[1] == 'G') {
mazgch 27:fe3b383dd4ec 216 #define _CHECK_TALKER(s) ((buf[3] == s[0]) && (buf[4] == s[1]) && (buf[5] == s[2]))
mazgch 27:fe3b383dd4ec 217 if (_CHECK_TALKER("GLL")) {
mazgch 27:fe3b383dd4ec 218 double la = 0, lo = 0;
mazgch 27:fe3b383dd4ec 219 char ch;
mazgch 27:fe3b383dd4ec 220 if (gps.getNmeaAngle(1,buf,len,la) &&
mazgch 27:fe3b383dd4ec 221 gps.getNmeaAngle(3,buf,len,lo) &&
mazgch 27:fe3b383dd4ec 222 gps.getNmeaItem(6,buf,len,ch) && ch == 'A')
mazgch 27:fe3b383dd4ec 223 {
mazgch 27:fe3b383dd4ec 224 printf("GPS Location: %.5f %.5f\r\n", la, lo);
mazgch 27:fe3b383dd4ec 225 sprintf(link, "I am here!\n"
mazgch 27:fe3b383dd4ec 226 "https://maps.google.com/?q=%.5f,%.5f", la, lo);
mazgch 27:fe3b383dd4ec 227 }
mazgch 27:fe3b383dd4ec 228 } else if (_CHECK_TALKER("GGA") || _CHECK_TALKER("GNS") ) {
mazgch 27:fe3b383dd4ec 229 double a = 0;
mazgch 27:fe3b383dd4ec 230 if (gps.getNmeaItem(9,buf,len,a)) // altitude msl [m]
mazgch 27:fe3b383dd4ec 231 printf("GPS Altitude: %.1f\r\n", a);
mazgch 27:fe3b383dd4ec 232 } else if (_CHECK_TALKER("VTG")) {
mazgch 27:fe3b383dd4ec 233 double s = 0;
mazgch 27:fe3b383dd4ec 234 if (gps.getNmeaItem(7,buf,len,s)) // speed [km/h]
mazgch 27:fe3b383dd4ec 235 printf("GPS Speed: %.1f\r\n", s);
mazgch 19:f022ff746eb8 236 }
mazgch 4:90ab1ec64b0e 237 }
mazgch 4:90ab1ec64b0e 238 }
mazgch 10:d2da2028a233 239 }
msinig 29:16f1037626e3 240 #endif
msinig 29:16f1037626e3 241 #ifdef CELLOCATE
msinig 29:16f1037626e3 242 if (mdmOk && (j++ == submitPeriod * 1000/wait)) {
msinig 29:16f1037626e3 243 j=0;
msinig 29:16f1037626e3 244 printf("CellLocate Request\r\n");
msinig 29:16f1037626e3 245 mdm.cellLocRequest(sensorMask, submitPeriod-timeoutMargin, targetAccuracy);
msinig 29:16f1037626e3 246 cellLocWait = true;
msinig 29:16f1037626e3 247 }
msinig 29:16f1037626e3 248 if (cellLocWait && mdm.cellLocGet(&loc)){
msinig 29:16f1037626e3 249 cellLocWait = false;
msinig 29:16f1037626e3 250 printf("CellLocate position received, sensor_used: %d, \r\n", loc.sensorUsed );
msinig 29:16f1037626e3 251 printf(" latitude: %0.5f, longitude: %0.5f, altitute: %d\r\n", loc.latitue, loc.longitude, loc.altitutude);
msinig 29:16f1037626e3 252 if (loc.sensorUsed == 1)
msinig 29:16f1037626e3 253 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 254 if (loc.sensorUsed == 1 || loc.sensorUsed == 2)
msinig 29:16f1037626e3 255 sprintf(link, "I am here!\n"
msinig 29:16f1037626e3 256 "https://maps.google.com/?q=%.5f,%.5f", loc.latitue, loc.longitude);
msinig 29:16f1037626e3 257 }
msinig 29:16f1037626e3 258 if (cellLocWait && (j%100 == 0 ))
msinig 29:16f1037626e3 259 printf("Waiting for CellLocate...\r\n");
msinig 29:16f1037626e3 260 #endif
mazgch 19:f022ff746eb8 261 if (mdmOk && (i++ == 5000/wait)) {
mazgch 10:d2da2028a233 262 i = 0;
mazgch 10:d2da2028a233 263 // check the network status
mazgch 15:ea10b6cf8c85 264 if (mdm.checkNetStatus(&netStatus)) {
mazgch 19:f022ff746eb8 265 mdm.dumpNetStatus(&netStatus, fprintf, stdout);
mazgch 15:ea10b6cf8c85 266 }
mazgch 10:d2da2028a233 267
mazgch 10:d2da2028a233 268 // checking unread sms
mazgch 10:d2da2028a233 269 int ix[8];
mazgch 10:d2da2028a233 270 int n = mdm.smsList("REC UNREAD", ix, 8);
mazgch 10:d2da2028a233 271 if (8 < n) n = 8;
mazgch 10:d2da2028a233 272 while (0 < n--)
mazgch 10:d2da2028a233 273 {
mazgch 10:d2da2028a233 274 char num[32];
mazgch 19:f022ff746eb8 275 printf("Unread SMS at index %d\r\n", ix[n]);
mazgch 10:d2da2028a233 276 if (mdm.smsRead(ix[n], num, buf, sizeof(buf))) {
mazgch 19:f022ff746eb8 277 printf("Got SMS from \"%s\" with text \"%s\"\r\n", num, buf);
mazgch 19:f022ff746eb8 278 printf("Delete SMS at index %d\r\n", ix[n]);
mazgch 10:d2da2028a233 279 mdm.smsDelete(ix[n]);
mazgch 10:d2da2028a233 280 // provide a reply
mazgch 10:d2da2028a233 281 const char* reply = "Hello my friend";
mazgch 10:d2da2028a233 282 if (strstr(buf, /*w*/"here are you"))
mazgch 10:d2da2028a233 283 reply = *link ? link : "I don't know"; // reply wil location link
mazgch 19:f022ff746eb8 284 else if (strstr(buf, /*s*/"hutdown"))
mazgch 19:f022ff746eb8 285 abort = true, reply = "bye bye";
mazgch 19:f022ff746eb8 286 printf("Send SMS reply \"%s\" to \"%s\"\r\n", reply, num);
mazgch 10:d2da2028a233 287 mdm.smsSend(num, reply);
mazgch 4:90ab1ec64b0e 288 }
mazgch 4:90ab1ec64b0e 289 }
mazgch 9:26f694bc31b4 290 }
mazgch 31:a07d0f76dc81 291 #ifdef RTOS_H
mazgch 31:a07d0f76dc81 292 Thread::wait(wait);
mazgch 31:a07d0f76dc81 293 #else
mazgch 31:a07d0f76dc81 294 ::wait_ms(wait);
mazgch 31:a07d0f76dc81 295 #endif
lawliet 0:4e3cb26f6019 296 }
mazgch 19:f022ff746eb8 297 gps.powerOff();
mazgch 10:d2da2028a233 298 mdm.powerOff();
lawliet 0:4e3cb26f6019 299 return 0;
lawliet 0:4e3cb26f6019 300 }