インターフェース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@29:1f18e74ff972, 2014-07-17 (annotated)
- Committer:
- ntaka206
- Date:
- Thu Jul 17 02:52:30 2014 +0000
- Revision:
- 29:1f18e74ff972
- Parent:
- 28:d504a106c124
- Child:
- 30:e6c7827dfbe8
libxively?????Xively HTTP POST???????commit;
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 | 29:1f18e74ff972 | 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 | 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 | 29:1f18e74ff972 | 91 | #if 1 |
ntaka206 | 28:d504a106c124 | 92 | |
mazgch | 20:52f0e5de8c3d | 93 | if (mdmOk) |
mazgch | 20:52f0e5de8c3d | 94 | { |
mazgch | 19:f022ff746eb8 | 95 | // http://www.geckobeach.com/cellular/secrets/gsmcodes.php |
mazgch | 19:f022ff746eb8 | 96 | // http://de.wikipedia.org/wiki/USSD-Codes |
mazgch | 19:f022ff746eb8 | 97 | const char* ussd = "*130#"; // You may get answer "UNKNOWN APPLICATION" |
mazgch | 19:f022ff746eb8 | 98 | printf("Ussd Send Command %s\r\n", ussd); |
mazgch | 19:f022ff746eb8 | 99 | ret = mdm.ussdCommand(ussd, buf); |
mazgch | 19:f022ff746eb8 | 100 | if (ret > 0) |
mazgch | 19:f022ff746eb8 | 101 | printf("Ussd Got Answer: \"%*s\"\r\n", ret, buf); |
mazgch | 19:f022ff746eb8 | 102 | |
mazgch | 4:90ab1ec64b0e | 103 | // join the internet connection |
mazgch | 19:f022ff746eb8 | 104 | MDMParser::IP ip = mdm.join(APN,USERNAME,PASSWORD); |
mazgch | 5:5366d39d3719 | 105 | if (ip != NOIP) |
mazgch | 2:b77151f111a9 | 106 | { |
mazgch | 19:f022ff746eb8 | 107 | mdm.dumpIp(ip); |
mazgch | 19:f022ff746eb8 | 108 | printf("Make a Http Post Request\r\n"); |
mazgch | 4:90ab1ec64b0e | 109 | int socket = mdm.socketSocket(MDMParser::IPPROTO_TCP); |
mazgch | 4:90ab1ec64b0e | 110 | if (socket >= 0) |
mazgch | 2:b77151f111a9 | 111 | { |
mazgch | 16:43f6de7bc38b | 112 | mdm.socketSetBlocking(socket, 10000); |
mazgch | 4:90ab1ec64b0e | 113 | if (mdm.socketConnect(socket, "mbed.org", 80)) |
mazgch | 4:90ab1ec64b0e | 114 | { |
mazgch | 4:90ab1ec64b0e | 115 | const char http[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\r\n\r\n"; |
mazgch | 4:90ab1ec64b0e | 116 | mdm.socketSend(socket, http, sizeof(http)-1); |
mazgch | 4:90ab1ec64b0e | 117 | |
mazgch | 19:f022ff746eb8 | 118 | ret = mdm.socketRecv(socket, buf, sizeof(buf)-1); |
mazgch | 19:f022ff746eb8 | 119 | if (ret > 0) |
mazgch | 19:f022ff746eb8 | 120 | printf("Socket Recv \"%*s\"\r\n", ret, buf); |
mazgch | 4:90ab1ec64b0e | 121 | mdm.socketClose(socket); |
mazgch | 4:90ab1ec64b0e | 122 | } |
mazgch | 4:90ab1ec64b0e | 123 | mdm.socketFree(socket); |
mazgch | 4:90ab1ec64b0e | 124 | } |
mazgch | 2:b77151f111a9 | 125 | |
mazgch | 16:43f6de7bc38b | 126 | int port = 7; |
mazgch | 16:43f6de7bc38b | 127 | const char* host = "echo.u-blox.com"; |
mazgch | 16:43f6de7bc38b | 128 | MDMParser::IP ip = mdm.gethostbyname(host); |
mazgch | 16:43f6de7bc38b | 129 | char data[] = "\r\nxxx Socket Hello World\r\n" |
mazgch | 19:f022ff746eb8 | 130 | #ifdef LARGE_DATA |
mazgch | 17:c293780a40ac | 131 | "00 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 132 | "01 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 133 | "02 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 134 | "03 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 135 | "04 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 136 | |
mazgch | 17:c293780a40ac | 137 | "05 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 138 | "06 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 139 | "07 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 140 | "08 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 141 | "09 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 16:43f6de7bc38b | 142 | |
mazgch | 17:c293780a40ac | 143 | "10 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 144 | "11 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 145 | "12 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 146 | "13 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 147 | "14 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 148 | |
mazgch | 17:c293780a40ac | 149 | "15 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 150 | "16 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 151 | "17 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 152 | "18 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 17:c293780a40ac | 153 | "19 0123456789 0123456789 0123456789 0123456789 0123456789 \r\n" |
mazgch | 16:43f6de7bc38b | 154 | #endif |
mazgch | 17:c293780a40ac | 155 | "End\r\n"; |
mazgch | 16:43f6de7bc38b | 156 | |
mazgch | 19:f022ff746eb8 | 157 | printf("Testing TCP sockets with ECHO server\r\n"); |
mazgch | 16:43f6de7bc38b | 158 | socket = mdm.socketSocket(MDMParser::IPPROTO_TCP); |
mazgch | 16:43f6de7bc38b | 159 | if (socket >= 0) |
mazgch | 16:43f6de7bc38b | 160 | { |
mazgch | 16:43f6de7bc38b | 161 | mdm.socketSetBlocking(socket, 10000); |
mazgch | 16:43f6de7bc38b | 162 | if (mdm.socketConnect(socket, host, port)) { |
mazgch | 16:43f6de7bc38b | 163 | memcpy(data, "\r\nTCP", 5); |
mazgch | 16:43f6de7bc38b | 164 | ret = mdm.socketSend(socket, data, sizeof(data)-1); |
mazgch | 16:43f6de7bc38b | 165 | if (ret == sizeof(data)-1) { |
mazgch | 19:f022ff746eb8 | 166 | printf("Socket Send %d \"%s\"\r\n", ret, data); |
mazgch | 16:43f6de7bc38b | 167 | } |
mazgch | 16:43f6de7bc38b | 168 | ret = mdm.socketRecv(socket, buf, sizeof(buf)-1); |
mazgch | 16:43f6de7bc38b | 169 | if (ret >= 0) { |
mazgch | 19:f022ff746eb8 | 170 | printf("Socket Recv %d \"%.*s\"\r\n", ret, ret, buf); |
mazgch | 16:43f6de7bc38b | 171 | } |
mazgch | 16:43f6de7bc38b | 172 | mdm.socketClose(socket); |
mazgch | 16:43f6de7bc38b | 173 | } |
mazgch | 16:43f6de7bc38b | 174 | mdm.socketFree(socket); |
mazgch | 16:43f6de7bc38b | 175 | } |
mazgch | 16:43f6de7bc38b | 176 | |
mazgch | 19:f022ff746eb8 | 177 | printf("Testing UDP sockets with ECHO server\r\n"); |
mazgch | 16:43f6de7bc38b | 178 | socket = mdm.socketSocket(MDMParser::IPPROTO_UDP, port); |
mazgch | 16:43f6de7bc38b | 179 | if (socket >= 0) |
mazgch | 16:43f6de7bc38b | 180 | { |
mazgch | 16:43f6de7bc38b | 181 | mdm.socketSetBlocking(socket, 10000); |
mazgch | 16:43f6de7bc38b | 182 | memcpy(data, "\r\nUDP", 5); |
mazgch | 16:43f6de7bc38b | 183 | ret = mdm.socketSendTo(socket, ip, port, data, sizeof(data)-1); |
mazgch | 16:43f6de7bc38b | 184 | if (ret == sizeof(data)-1) { |
mazgch | 19:f022ff746eb8 | 185 | printf("Socket SendTo %s:%d " IPSTR " %d \"%s\"\r\n", host, port, IPNUM(ip), ret, data); |
mazgch | 16:43f6de7bc38b | 186 | } |
mazgch | 16:43f6de7bc38b | 187 | ret = mdm.socketRecvFrom(socket, &ip, &port, buf, sizeof(buf)-1); |
mazgch | 16:43f6de7bc38b | 188 | if (ret >= 0) { |
mazgch | 19:f022ff746eb8 | 189 | printf("Socket RecvFrom " IPSTR ":%d %d \"%.*s\" \r\n", IPNUM(ip),port, ret, ret,buf); |
mazgch | 16:43f6de7bc38b | 190 | } |
mazgch | 16:43f6de7bc38b | 191 | mdm.socketFree(socket); |
mazgch | 16:43f6de7bc38b | 192 | } |
mazgch | 16:43f6de7bc38b | 193 | |
mazgch | 4:90ab1ec64b0e | 194 | // disconnect |
mazgch | 4:90ab1ec64b0e | 195 | mdm.disconnect(); |
mazgch | 2:b77151f111a9 | 196 | } |
mazgch | 10:d2da2028a233 | 197 | } |
ntaka206 | 29:1f18e74ff972 | 198 | #endif |
ntaka206 | 29:1f18e74ff972 | 199 | #if 0 |
ntaka206 | 29:1f18e74ff972 | 200 | EthernetInterface eth; |
ntaka206 | 29:1f18e74ff972 | 201 | |
ntaka206 | 29:1f18e74ff972 | 202 | int s = eth.init(); //Use DHCP |
ntaka206 | 29:1f18e74ff972 | 203 | if( s != NULL ) { |
ntaka206 | 29:1f18e74ff972 | 204 | printf( "Could not initialise. Will halt!\n" ); |
ntaka206 | 29:1f18e74ff972 | 205 | exit( 0 ); |
ntaka206 | 29:1f18e74ff972 | 206 | } |
ntaka206 | 29:1f18e74ff972 | 207 | |
ntaka206 | 29:1f18e74ff972 | 208 | s = eth.connect(); |
ntaka206 | 29:1f18e74ff972 | 209 | if( s != NULL ) { |
ntaka206 | 29:1f18e74ff972 | 210 | printf( "Could not connect. Will halt!\n" ); |
ntaka206 | 29:1f18e74ff972 | 211 | exit( 0 ); |
ntaka206 | 29:1f18e74ff972 | 212 | } else { |
ntaka206 | 29:1f18e74ff972 | 213 | printf( "IP: %s\n", eth.getIPAddress() ); |
ntaka206 | 29:1f18e74ff972 | 214 | } |
ntaka206 | 29:1f18e74ff972 | 215 | #endif |
ntaka206 | 29:1f18e74ff972 | 216 | |
ntaka206 | 29:1f18e74ff972 | 217 | // Xively |
ntaka206 | 29:1f18e74ff972 | 218 | xi_feed_t feed; |
ntaka206 | 29:1f18e74ff972 | 219 | memset( &feed, NULL, sizeof( xi_feed_t ) ); |
ntaka206 | 29:1f18e74ff972 | 220 | |
ntaka206 | 29:1f18e74ff972 | 221 | feed.feed_id = XI_FEED_ID; |
ntaka206 | 29:1f18e74ff972 | 222 | feed.datastream_count = 2; |
ntaka206 | 29:1f18e74ff972 | 223 | |
ntaka206 | 29:1f18e74ff972 | 224 | feed.datastreams[0].datapoint_count = 1; |
ntaka206 | 29:1f18e74ff972 | 225 | xi_datastream_t* lat_datastream = &feed.datastreams[0]; |
ntaka206 | 29:1f18e74ff972 | 226 | strcpy( lat_datastream->datastream_id, "lat" ); |
ntaka206 | 29:1f18e74ff972 | 227 | xi_datapoint_t* current_lat = &lat_datastream->datapoints[0]; |
ntaka206 | 29:1f18e74ff972 | 228 | |
ntaka206 | 29:1f18e74ff972 | 229 | feed.datastreams[1].datapoint_count = 1; |
ntaka206 | 29:1f18e74ff972 | 230 | xi_datastream_t* lon_datastream = &feed.datastreams[1]; |
ntaka206 | 29:1f18e74ff972 | 231 | strcpy( lon_datastream->datastream_id, "lon" ); |
ntaka206 | 29:1f18e74ff972 | 232 | xi_datapoint_t* current_lon = &lon_datastream->datapoints[0]; |
ntaka206 | 29:1f18e74ff972 | 233 | |
ntaka206 | 29:1f18e74ff972 | 234 | // create the cosm library context |
ntaka206 | 29:1f18e74ff972 | 235 | xi_context_t* xi_context |
ntaka206 | 29:1f18e74ff972 | 236 | = xi_create_context( XI_HTTP, XI_API_KEY, feed.feed_id ); |
ntaka206 | 29:1f18e74ff972 | 237 | |
ntaka206 | 29:1f18e74ff972 | 238 | // check if everything works |
ntaka206 | 29:1f18e74ff972 | 239 | if( xi_context == NULL ) |
ntaka206 | 29:1f18e74ff972 | 240 | { |
ntaka206 | 29:1f18e74ff972 | 241 | printf("xi_context NULL!\n"); |
ntaka206 | 29:1f18e74ff972 | 242 | return -1; |
ntaka206 | 29:1f18e74ff972 | 243 | } |
ntaka206 | 29:1f18e74ff972 | 244 | |
mazgch | 19:f022ff746eb8 | 245 | printf("SMS and GPS Loop\r\n"); |
mazgch | 10:d2da2028a233 | 246 | char link[128] = ""; |
mazgch | 10:d2da2028a233 | 247 | unsigned int i = 0xFFFFFFFF; |
mazgch | 10:d2da2028a233 | 248 | const int wait = 100; |
mazgch | 10:d2da2028a233 | 249 | bool abort = false; |
mazgch | 11:b8505cbbd55c | 250 | //DigitalOut led(LED1); |
mazgch | 10:d2da2028a233 | 251 | while (!abort) { |
mazgch | 19:f022ff746eb8 | 252 | // led = !led; |
mazgch | 10:d2da2028a233 | 253 | while ((ret = gps.getMessage(buf, sizeof(buf))) > 0) |
mazgch | 10:d2da2028a233 | 254 | { |
mazgch | 10:d2da2028a233 | 255 | int len = LENGTH(ret); |
mazgch | 19:f022ff746eb8 | 256 | //printf("NMEA: %.*s\r\n", len-2, msg); |
mazgch | 19:f022ff746eb8 | 257 | if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6)) |
mazgch | 4:90ab1ec64b0e | 258 | { |
mazgch | 19:f022ff746eb8 | 259 | if (!strncmp("$GPGLL", buf, 6)) { |
mazgch | 19:f022ff746eb8 | 260 | double la = 0, lo = 0; |
mazgch | 19:f022ff746eb8 | 261 | char ch; |
mazgch | 19:f022ff746eb8 | 262 | if (gps.getNmeaAngle(1,buf,len,la) && |
mazgch | 19:f022ff746eb8 | 263 | gps.getNmeaAngle(3,buf,len,lo) && |
mazgch | 19:f022ff746eb8 | 264 | gps.getNmeaItem(6,buf,len,ch) && ch == 'A') |
mazgch | 19:f022ff746eb8 | 265 | { |
mazgch | 19:f022ff746eb8 | 266 | printf("GPS Location: %.5f %.5f\r\n", la, lo); |
mazgch | 19:f022ff746eb8 | 267 | sprintf(link, "I am here!\n" |
mazgch | 19:f022ff746eb8 | 268 | "https://maps.google.com/?q=%.5f,%.5f", la, lo); |
ntaka206 | 29:1f18e74ff972 | 269 | // Xively |
ntaka206 | 29:1f18e74ff972 | 270 | xi_set_value_f32( current_lat, la ); |
ntaka206 | 29:1f18e74ff972 | 271 | xi_set_value_f32( current_lon, lo ); |
ntaka206 | 29:1f18e74ff972 | 272 | xi_feed_update( xi_context, &feed ); |
ntaka206 | 29:1f18e74ff972 | 273 | |
mazgch | 19:f022ff746eb8 | 274 | } |
mazgch | 19:f022ff746eb8 | 275 | } else if (!strncmp("$GPGGA", buf, 6)) { |
mazgch | 19:f022ff746eb8 | 276 | double a = 0; |
mazgch | 19:f022ff746eb8 | 277 | if (gps.getNmeaItem(9,buf,len,a)) // altitude msl [m] |
mazgch | 19:f022ff746eb8 | 278 | printf("GPS Altitude: %.1f\r\n", a); |
mazgch | 19:f022ff746eb8 | 279 | } else if (!strncmp("$GPVTG", buf, 6)) { |
mazgch | 19:f022ff746eb8 | 280 | double s = 0; |
mazgch | 19:f022ff746eb8 | 281 | if (gps.getNmeaItem(7,buf,len,s)) // speed [km/h] |
mazgch | 19:f022ff746eb8 | 282 | printf("GPS Speed: %.1f\r\n", s); |
mazgch | 4:90ab1ec64b0e | 283 | } |
mazgch | 4:90ab1ec64b0e | 284 | } |
mazgch | 10:d2da2028a233 | 285 | } |
mazgch | 19:f022ff746eb8 | 286 | if (mdmOk && (i++ == 5000/wait)) { |
mazgch | 10:d2da2028a233 | 287 | i = 0; |
mazgch | 10:d2da2028a233 | 288 | // check the network status |
mazgch | 15:ea10b6cf8c85 | 289 | if (mdm.checkNetStatus(&netStatus)) { |
mazgch | 19:f022ff746eb8 | 290 | mdm.dumpNetStatus(&netStatus, fprintf, stdout); |
mazgch | 15:ea10b6cf8c85 | 291 | } |
mazgch | 10:d2da2028a233 | 292 | |
mazgch | 10:d2da2028a233 | 293 | // checking unread sms |
mazgch | 10:d2da2028a233 | 294 | int ix[8]; |
mazgch | 10:d2da2028a233 | 295 | int n = mdm.smsList("REC UNREAD", ix, 8); |
mazgch | 10:d2da2028a233 | 296 | if (8 < n) n = 8; |
mazgch | 10:d2da2028a233 | 297 | while (0 < n--) |
mazgch | 10:d2da2028a233 | 298 | { |
mazgch | 10:d2da2028a233 | 299 | char num[32]; |
mazgch | 19:f022ff746eb8 | 300 | printf("Unread SMS at index %d\r\n", ix[n]); |
mazgch | 10:d2da2028a233 | 301 | if (mdm.smsRead(ix[n], num, buf, sizeof(buf))) { |
mazgch | 19:f022ff746eb8 | 302 | printf("Got SMS from \"%s\" with text \"%s\"\r\n", num, buf); |
mazgch | 19:f022ff746eb8 | 303 | printf("Delete SMS at index %d\r\n", ix[n]); |
mazgch | 10:d2da2028a233 | 304 | mdm.smsDelete(ix[n]); |
mazgch | 10:d2da2028a233 | 305 | // provide a reply |
mazgch | 10:d2da2028a233 | 306 | const char* reply = "Hello my friend"; |
mazgch | 10:d2da2028a233 | 307 | if (strstr(buf, /*w*/"here are you")) |
mazgch | 10:d2da2028a233 | 308 | reply = *link ? link : "I don't know"; // reply wil location link |
mazgch | 19:f022ff746eb8 | 309 | else if (strstr(buf, /*s*/"hutdown")) |
mazgch | 19:f022ff746eb8 | 310 | abort = true, reply = "bye bye"; |
mazgch | 19:f022ff746eb8 | 311 | printf("Send SMS reply \"%s\" to \"%s\"\r\n", reply, num); |
mazgch | 10:d2da2028a233 | 312 | mdm.smsSend(num, reply); |
mazgch | 4:90ab1ec64b0e | 313 | } |
mazgch | 4:90ab1ec64b0e | 314 | } |
mazgch | 9:26f694bc31b4 | 315 | } |
mazgch | 10:d2da2028a233 | 316 | wait_ms(wait); |
lawliet | 0:4e3cb26f6019 | 317 | } |
mazgch | 19:f022ff746eb8 | 318 | gps.powerOff(); |
mazgch | 10:d2da2028a233 | 319 | mdm.powerOff(); |
lawliet | 0:4e3cb26f6019 | 320 | return 0; |
lawliet | 0:4e3cb26f6019 | 321 | } |