インターフェース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
インターフェース2014年10月号のu-blox C027で3G通信する記事で使用したプログラムです。
main.cpp@28:d504a106c124, 2014-07-16 (annotated)
- Committer:
- ntaka206
- Date:
- Wed Jul 16 12:56:24 2014 +0000
- Revision:
- 28:d504a106c124
- Parent:
- 26:712544e993ff
- Child:
- 29:1f18e74ff972
Xively datastream?context???
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 | 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 | 28:d504a106c124 | 37 | #define XI_FEED_ID 128488 // set Xively Feed ID (numerical, no quoutes) |
ntaka206 | 28:d504a106c124 | 38 | #define XI_API_KEY "T4KXAH_dasgw1PWBPc3fdsfsdgsdy-dUc4ND0g" // set Xively API key (double-quoted string) |
ntaka206 | 28:d504a106c124 | 39 | |
ntaka206 | 28:d504a106c124 | 40 | #include "xively.h" |
ntaka206 | 28:d504a106c124 | 41 | #include "xi_err.h" |
ntaka206 | 28:d504a106c124 | 42 | |
mazgch | 19:f022ff746eb8 | 43 | //------------------------------------------------------------------------------------ |
lawliet | 0:4e3cb26f6019 | 44 | |
lawliet | 0:4e3cb26f6019 | 45 | int main(void) |
lawliet | 0:4e3cb26f6019 | 46 | { |
mazgch | 2:b77151f111a9 | 47 | int ret; |
mazgch | 19:f022ff746eb8 | 48 | #ifdef LARGE_DATA |
mazgch | 16:43f6de7bc38b | 49 | char buf[2048] = ""; |
mazgch | 17:c293780a40ac | 50 | #else |
mazgch | 17:c293780a40ac | 51 | char buf[512] = ""; |
mazgch | 17:c293780a40ac | 52 | #endif |
ntaka206 | 26:712544e993ff | 53 | // ntaka |
ntaka206 | 26:712544e993ff | 54 | Serial pc(USBTX,USBRX); |
ntaka206 | 26:712544e993ff | 55 | pc.baud(115200); |
lawliet | 0:4e3cb26f6019 | 56 | |
mazgch | 19:f022ff746eb8 | 57 | // Create the GPS object |
mazgch | 19:f022ff746eb8 | 58 | #if 1 // use GPSI2C class |
mazgch | 19:f022ff746eb8 | 59 | GPSI2C gps; |
mazgch | 19:f022ff746eb8 | 60 | #else // or GPSSerial class |
mazgch | 19:f022ff746eb8 | 61 | GPSSerial gps; |
mazgch | 10:d2da2028a233 | 62 | #endif |
mazgch | 10:d2da2028a233 | 63 | // Create the modem object |
mazgch | 19:f022ff746eb8 | 64 | MDMSerial mdm; |
mazgch | 22:078f410ef2c7 | 65 | //mdm.setDebug(4); // enable this for debugging issues |
mazgch | 2:b77151f111a9 | 66 | // initialize the modem |
mazgch | 19:f022ff746eb8 | 67 | MDMParser::DevStatus devStatus = {}; |
mazgch | 19:f022ff746eb8 | 68 | MDMParser::NetStatus netStatus = {}; |
mazgch | 10:d2da2028a233 | 69 | bool mdmOk = mdm.init(SIMPIN, &devStatus); |
mazgch | 19:f022ff746eb8 | 70 | mdm.dumpDevStatus(&devStatus); |
mazgch | 19:f022ff746eb8 | 71 | if (mdmOk) { |
mazgch | 20:52f0e5de8c3d | 72 | #if 0 |
mazgch | 20:52f0e5de8c3d | 73 | // file system API |
mazgch | 19:f022ff746eb8 | 74 | const char* filename = "File"; |
mazgch | 19:f022ff746eb8 | 75 | char buf[] = "Hello World"; |
mazgch | 19:f022ff746eb8 | 76 | printf("writeFile \"%s\"\r\n", buf); |
mazgch | 19:f022ff746eb8 | 77 | if (mdm.writeFile(filename, buf, sizeof(buf))) |
mazgch | 19:f022ff746eb8 | 78 | { |
mazgch | 19:f022ff746eb8 | 79 | memset(buf, 0, sizeof(buf)); |
mazgch | 19:f022ff746eb8 | 80 | int len = mdm.readFile(filename, buf, sizeof(buf)); |
mazgch | 24:81f5b43a6585 | 81 | if (len >= 0) |
mazgch | 19:f022ff746eb8 | 82 | printf("readFile %d \"%.*s\"\r\n", len, len, buf); |
mazgch | 19:f022ff746eb8 | 83 | mdm.delFile(filename); |
mazgch | 19:f022ff746eb8 | 84 | } |
mazgch | 20:52f0e5de8c3d | 85 | #endif |
mazgch | 20:52f0e5de8c3d | 86 | |
mazgch | 20:52f0e5de8c3d | 87 | // wait until we are connected |
mazgch | 20:52f0e5de8c3d | 88 | mdmOk = mdm.registerNet(&netStatus); |
mazgch | 20:52f0e5de8c3d | 89 | mdm.dumpNetStatus(&netStatus); |
mazgch | 20:52f0e5de8c3d | 90 | } |
ntaka206 | 28:d504a106c124 | 91 | // Xively |
ntaka206 | 28:d504a106c124 | 92 | xi_feed_t feed; |
ntaka206 | 28:d504a106c124 | 93 | memset( &feed, NULL, sizeof( xi_feed_t ) ); |
ntaka206 | 28:d504a106c124 | 94 | |
ntaka206 | 28:d504a106c124 | 95 | feed.feed_id = XI_FEED_ID; |
ntaka206 | 28:d504a106c124 | 96 | feed.datastream_count = 2; |
ntaka206 | 28:d504a106c124 | 97 | |
ntaka206 | 28:d504a106c124 | 98 | feed.datastreams[0].datapoint_count = 1; |
ntaka206 | 28:d504a106c124 | 99 | xi_datastream_t* lat_datastream = &feed.datastreams[0]; |
ntaka206 | 28:d504a106c124 | 100 | strcpy( lat_datastream->datastream_id, "lat" ); |
ntaka206 | 28:d504a106c124 | 101 | xi_datapoint_t* current_lat = &lat_datastream->datapoints[0]; |
ntaka206 | 28:d504a106c124 | 102 | |
ntaka206 | 28:d504a106c124 | 103 | feed.datastreams[1].datapoint_count = 1; |
ntaka206 | 28:d504a106c124 | 104 | xi_datastream_t* lon_datastream = &feed.datastreams[1]; |
ntaka206 | 28:d504a106c124 | 105 | strcpy( lon_datastream->datastream_id, "lon" ); |
ntaka206 | 28:d504a106c124 | 106 | xi_datapoint_t* current_lon = &lon_datastream->datapoints[0]; |
ntaka206 | 28:d504a106c124 | 107 | |
ntaka206 | 28:d504a106c124 | 108 | // create the cosm library context |
ntaka206 | 28:d504a106c124 | 109 | xi_context_t* xi_context |
ntaka206 | 28:d504a106c124 | 110 | = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id ); |
ntaka206 | 28:d504a106c124 | 111 | |
ntaka206 | 28:d504a106c124 | 112 | // check if everything works |
ntaka206 | 28:d504a106c124 | 113 | if( xi_context == NULL ) |
ntaka206 | 28:d504a106c124 | 114 | { |
ntaka206 | 28:d504a106c124 | 115 | return -1; |
ntaka206 | 28:d504a106c124 | 116 | } |
ntaka206 | 28:d504a106c124 | 117 | |
mazgch | 20:52f0e5de8c3d | 118 | if (mdmOk) |
mazgch | 20:52f0e5de8c3d | 119 | { |
mazgch | 19:f022ff746eb8 | 120 | // http://www.geckobeach.com/cellular/secrets/gsmcodes.php |
mazgch | 19:f022ff746eb8 | 121 | // http://de.wikipedia.org/wiki/USSD-Codes |
mazgch | 19:f022ff746eb8 | 122 | const char* ussd = "*130#"; // You may get answer "UNKNOWN APPLICATION" |
mazgch | 19:f022ff746eb8 | 123 | printf("Ussd Send Command %s\r\n", ussd); |
mazgch | 19:f022ff746eb8 | 124 | ret = mdm.ussdCommand(ussd, buf); |
mazgch | 19:f022ff746eb8 | 125 | if (ret > 0) |
mazgch | 19:f022ff746eb8 | 126 | printf("Ussd Got Answer: \"%*s\"\r\n", ret, buf); |
mazgch | 19:f022ff746eb8 | 127 | |
mazgch | 4:90ab1ec64b0e | 128 | // join the internet connection |
mazgch | 19:f022ff746eb8 | 129 | MDMParser::IP ip = mdm.join(APN,USERNAME,PASSWORD); |
mazgch | 5:5366d39d3719 | 130 | if (ip != NOIP) |
mazgch | 2:b77151f111a9 | 131 | { |
mazgch | 19:f022ff746eb8 | 132 | mdm.dumpIp(ip); |
mazgch | 19:f022ff746eb8 | 133 | printf("Make a Http Post Request\r\n"); |
mazgch | 4:90ab1ec64b0e | 134 | int socket = mdm.socketSocket(MDMParser::IPPROTO_TCP); |
mazgch | 4:90ab1ec64b0e | 135 | if (socket >= 0) |
mazgch | 2:b77151f111a9 | 136 | { |
mazgch | 16:43f6de7bc38b | 137 | mdm.socketSetBlocking(socket, 10000); |
mazgch | 4:90ab1ec64b0e | 138 | if (mdm.socketConnect(socket, "mbed.org", 80)) |
mazgch | 4:90ab1ec64b0e | 139 | { |
mazgch | 4:90ab1ec64b0e | 140 | const char http[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\r\n\r\n"; |
mazgch | 4:90ab1ec64b0e | 141 | mdm.socketSend(socket, http, sizeof(http)-1); |
mazgch | 4:90ab1ec64b0e | 142 | |
mazgch | 19:f022ff746eb8 | 143 | ret = mdm.socketRecv(socket, buf, sizeof(buf)-1); |
mazgch | 19:f022ff746eb8 | 144 | if (ret > 0) |
mazgch | 19:f022ff746eb8 | 145 | printf("Socket Recv \"%*s\"\r\n", ret, buf); |
mazgch | 4:90ab1ec64b0e | 146 | mdm.socketClose(socket); |
mazgch | 4:90ab1ec64b0e | 147 | } |
mazgch | 4:90ab1ec64b0e | 148 | mdm.socketFree(socket); |
mazgch | 4:90ab1ec64b0e | 149 | } |
mazgch | 2:b77151f111a9 | 150 | |
mazgch | 16:43f6de7bc38b | 151 | int port = 7; |
mazgch | 16:43f6de7bc38b | 152 | const char* host = "echo.u-blox.com"; |
mazgch | 16:43f6de7bc38b | 153 | MDMParser::IP ip = mdm.gethostbyname(host); |
mazgch | 16:43f6de7bc38b | 154 | char data[] = "\r\nxxx Socket Hello World\r\n" |
mazgch | 19:f022ff746eb8 | 155 | #ifdef LARGE_DATA |
mazgch | 17:c293780a40ac | 156 | "00 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 157 | "01 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 158 | "02 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 159 | "03 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 160 | "04 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 161 | |
mazgch | 17:c293780a40ac | 162 | "05 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 163 | "06 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 164 | "07 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 165 | "08 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 166 | "09 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 16:43f6de7bc38b | 167 | |
mazgch | 17:c293780a40ac | 168 | "10 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 169 | "11 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 170 | "12 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 171 | "13 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 172 | "14 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 173 | |
mazgch | 17:c293780a40ac | 174 | "15 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 175 | "16 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 176 | "17 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 177 | "18 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 178 | "19 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 16:43f6de7bc38b | 179 | #endif |
mazgch | 17:c293780a40ac | 180 | "End\r\n"; |
mazgch | 16:43f6de7bc38b | 181 | |
mazgch | 19:f022ff746eb8 | 182 | printf("Testing TCP sockets with ECHO server\r\n"); |
mazgch | 16:43f6de7bc38b | 183 | socket = mdm.socketSocket(MDMParser::IPPROTO_TCP); |
mazgch | 16:43f6de7bc38b | 184 | if (socket >= 0) |
mazgch | 16:43f6de7bc38b | 185 | { |
mazgch | 16:43f6de7bc38b | 186 | mdm.socketSetBlocking(socket, 10000); |
mazgch | 16:43f6de7bc38b | 187 | if (mdm.socketConnect(socket, host, port)) { |
mazgch | 16:43f6de7bc38b | 188 | memcpy(data, "\r\nTCP", 5); |
mazgch | 16:43f6de7bc38b | 189 | ret = mdm.socketSend(socket, data, sizeof(data)-1); |
mazgch | 16:43f6de7bc38b | 190 | if (ret == sizeof(data)-1) { |
mazgch | 19:f022ff746eb8 | 191 | printf("Socket Send %d \"%s\"\r\n", ret, data); |
mazgch | 16:43f6de7bc38b | 192 | } |
mazgch | 16:43f6de7bc38b | 193 | ret = mdm.socketRecv(socket, buf, sizeof(buf)-1); |
mazgch | 16:43f6de7bc38b | 194 | if (ret >= 0) { |
mazgch | 19:f022ff746eb8 | 195 | printf("Socket Recv %d \"%.*s\"\r\n", ret, ret, buf); |
mazgch | 16:43f6de7bc38b | 196 | } |
mazgch | 16:43f6de7bc38b | 197 | mdm.socketClose(socket); |
mazgch | 16:43f6de7bc38b | 198 | } |
mazgch | 16:43f6de7bc38b | 199 | mdm.socketFree(socket); |
mazgch | 16:43f6de7bc38b | 200 | } |
mazgch | 16:43f6de7bc38b | 201 | |
mazgch | 19:f022ff746eb8 | 202 | printf("Testing UDP sockets with ECHO server\r\n"); |
mazgch | 16:43f6de7bc38b | 203 | socket = mdm.socketSocket(MDMParser::IPPROTO_UDP, port); |
mazgch | 16:43f6de7bc38b | 204 | if (socket >= 0) |
mazgch | 16:43f6de7bc38b | 205 | { |
mazgch | 16:43f6de7bc38b | 206 | mdm.socketSetBlocking(socket, 10000); |
mazgch | 16:43f6de7bc38b | 207 | memcpy(data, "\r\nUDP", 5); |
mazgch | 16:43f6de7bc38b | 208 | ret = mdm.socketSendTo(socket, ip, port, data, sizeof(data)-1); |
mazgch | 16:43f6de7bc38b | 209 | if (ret == sizeof(data)-1) { |
mazgch | 19:f022ff746eb8 | 210 | printf("Socket SendTo %s:%d " IPSTR " %d \"%s\"\r\n", host, port, IPNUM(ip), ret, data); |
mazgch | 16:43f6de7bc38b | 211 | } |
mazgch | 16:43f6de7bc38b | 212 | ret = mdm.socketRecvFrom(socket, &ip, &port, buf, sizeof(buf)-1); |
mazgch | 16:43f6de7bc38b | 213 | if (ret >= 0) { |
mazgch | 19:f022ff746eb8 | 214 | printf("Socket RecvFrom " IPSTR ":%d %d \"%.*s\" \r\n", IPNUM(ip),port, ret, ret,buf); |
mazgch | 16:43f6de7bc38b | 215 | } |
mazgch | 16:43f6de7bc38b | 216 | mdm.socketFree(socket); |
mazgch | 16:43f6de7bc38b | 217 | } |
mazgch | 16:43f6de7bc38b | 218 | |
mazgch | 4:90ab1ec64b0e | 219 | // disconnect |
mazgch | 4:90ab1ec64b0e | 220 | mdm.disconnect(); |
mazgch | 2:b77151f111a9 | 221 | } |
mazgch | 10:d2da2028a233 | 222 | } |
mazgch | 19:f022ff746eb8 | 223 | printf("SMS and GPS Loop\r\n"); |
mazgch | 10:d2da2028a233 | 224 | char link[128] = ""; |
mazgch | 10:d2da2028a233 | 225 | unsigned int i = 0xFFFFFFFF; |
mazgch | 10:d2da2028a233 | 226 | const int wait = 100; |
mazgch | 10:d2da2028a233 | 227 | bool abort = false; |
mazgch | 11:b8505cbbd55c | 228 | //DigitalOut led(LED1); |
mazgch | 10:d2da2028a233 | 229 | while (!abort) { |
mazgch | 19:f022ff746eb8 | 230 | // led = !led; |
mazgch | 10:d2da2028a233 | 231 | while ((ret = gps.getMessage(buf, sizeof(buf))) > 0) |
mazgch | 10:d2da2028a233 | 232 | { |
mazgch | 10:d2da2028a233 | 233 | int len = LENGTH(ret); |
mazgch | 19:f022ff746eb8 | 234 | //printf("NMEA: %.*s\r\n", len-2, msg); |
mazgch | 19:f022ff746eb8 | 235 | if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6)) |
mazgch | 4:90ab1ec64b0e | 236 | { |
mazgch | 19:f022ff746eb8 | 237 | if (!strncmp("$GPGLL", buf, 6)) { |
mazgch | 19:f022ff746eb8 | 238 | double la = 0, lo = 0; |
mazgch | 19:f022ff746eb8 | 239 | char ch; |
mazgch | 19:f022ff746eb8 | 240 | if (gps.getNmeaAngle(1,buf,len,la) && |
mazgch | 19:f022ff746eb8 | 241 | gps.getNmeaAngle(3,buf,len,lo) && |
mazgch | 19:f022ff746eb8 | 242 | gps.getNmeaItem(6,buf,len,ch) && ch == 'A') |
mazgch | 19:f022ff746eb8 | 243 | { |
mazgch | 19:f022ff746eb8 | 244 | printf("GPS Location: %.5f %.5f\r\n", la, lo); |
mazgch | 19:f022ff746eb8 | 245 | sprintf(link, "I am here!\n" |
mazgch | 19:f022ff746eb8 | 246 | "https://maps.google.com/?q=%.5f,%.5f", la, lo); |
mazgch | 19:f022ff746eb8 | 247 | } |
mazgch | 19:f022ff746eb8 | 248 | } else if (!strncmp("$GPGGA", buf, 6)) { |
mazgch | 19:f022ff746eb8 | 249 | double a = 0; |
mazgch | 19:f022ff746eb8 | 250 | if (gps.getNmeaItem(9,buf,len,a)) // altitude msl [m] |
mazgch | 19:f022ff746eb8 | 251 | printf("GPS Altitude: %.1f\r\n", a); |
mazgch | 19:f022ff746eb8 | 252 | } else if (!strncmp("$GPVTG", buf, 6)) { |
mazgch | 19:f022ff746eb8 | 253 | double s = 0; |
mazgch | 19:f022ff746eb8 | 254 | if (gps.getNmeaItem(7,buf,len,s)) // speed [km/h] |
mazgch | 19:f022ff746eb8 | 255 | printf("GPS Speed: %.1f\r\n", s); |
mazgch | 4:90ab1ec64b0e | 256 | } |
mazgch | 4:90ab1ec64b0e | 257 | } |
mazgch | 10:d2da2028a233 | 258 | } |
mazgch | 19:f022ff746eb8 | 259 | if (mdmOk && (i++ == 5000/wait)) { |
mazgch | 10:d2da2028a233 | 260 | i = 0; |
mazgch | 10:d2da2028a233 | 261 | // check the network status |
mazgch | 15:ea10b6cf8c85 | 262 | if (mdm.checkNetStatus(&netStatus)) { |
mazgch | 19:f022ff746eb8 | 263 | mdm.dumpNetStatus(&netStatus, fprintf, stdout); |
mazgch | 15:ea10b6cf8c85 | 264 | } |
mazgch | 10:d2da2028a233 | 265 | |
mazgch | 10:d2da2028a233 | 266 | // checking unread sms |
mazgch | 10:d2da2028a233 | 267 | int ix[8]; |
mazgch | 10:d2da2028a233 | 268 | int n = mdm.smsList("REC UNREAD", ix, 8); |
mazgch | 10:d2da2028a233 | 269 | if (8 < n) n = 8; |
mazgch | 10:d2da2028a233 | 270 | while (0 < n--) |
mazgch | 10:d2da2028a233 | 271 | { |
mazgch | 10:d2da2028a233 | 272 | char num[32]; |
mazgch | 19:f022ff746eb8 | 273 | printf("Unread SMS at index %d\r\n", ix[n]); |
mazgch | 10:d2da2028a233 | 274 | if (mdm.smsRead(ix[n], num, buf, sizeof(buf))) { |
mazgch | 19:f022ff746eb8 | 275 | printf("Got SMS from \"%s\" with text \"%s\"\r\n", num, buf); |
mazgch | 19:f022ff746eb8 | 276 | printf("Delete SMS at index %d\r\n", ix[n]); |
mazgch | 10:d2da2028a233 | 277 | mdm.smsDelete(ix[n]); |
mazgch | 10:d2da2028a233 | 278 | // provide a reply |
mazgch | 10:d2da2028a233 | 279 | const char* reply = "Hello my friend"; |
mazgch | 10:d2da2028a233 | 280 | if (strstr(buf, /*w*/"here are you")) |
mazgch | 10:d2da2028a233 | 281 | reply = *link ? link : "I don't know"; // reply wil location link |
mazgch | 19:f022ff746eb8 | 282 | else if (strstr(buf, /*s*/"hutdown")) |
mazgch | 19:f022ff746eb8 | 283 | abort = true, reply = "bye bye"; |
mazgch | 19:f022ff746eb8 | 284 | printf("Send SMS reply \"%s\" to \"%s\"\r\n", reply, num); |
mazgch | 10:d2da2028a233 | 285 | mdm.smsSend(num, reply); |
mazgch | 4:90ab1ec64b0e | 286 | } |
mazgch | 4:90ab1ec64b0e | 287 | } |
mazgch | 9:26f694bc31b4 | 288 | } |
mazgch | 10:d2da2028a233 | 289 | wait_ms(wait); |
lawliet | 0:4e3cb26f6019 | 290 | } |
mazgch | 19:f022ff746eb8 | 291 | gps.powerOff(); |
mazgch | 10:d2da2028a233 | 292 | mdm.powerOff(); |
lawliet | 0:4e3cb26f6019 | 293 | return 0; |
lawliet | 0:4e3cb26f6019 | 294 | } |