ublox SupportTest with temperature response
Fork of C027_SupportTest by
main.cpp@34:a7f205c92059, 2017-05-30 (annotated)
- Committer:
- Adfontes
- Date:
- Tue May 30 11:14:41 2017 +0000
- Revision:
- 34:a7f205c92059
- Parent:
- 33:e27f40fada64
added temperature response
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 | 30:062717f25e41 | 23 | #define SIMPIN "1922" |
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 */ |
Adfontes | 34:a7f205c92059 | 27 | #define APN "internet.mts.ru" |
mazgch | 19:f022ff746eb8 | 28 | //! Set the user name for your APN, or NULL if not needed |
Adfontes | 34:a7f205c92059 | 29 | #define USERNAME "mts" |
mazgch | 19:f022ff746eb8 | 30 | //! Set the password for your APN, or NULL if not needed |
Adfontes | 34:a7f205c92059 | 31 | #define PASSWORD "mts" |
mazgch | 19:f022ff746eb8 | 32 | //------------------------------------------------------------------------------------ |
lawliet | 0:4e3cb26f6019 | 33 | |
msinig | 29:16f1037626e3 | 34 | //#define CELLOCATE |
msinig | 29:16f1037626e3 | 35 | |
Adfontes | 34:a7f205c92059 | 36 | #define LM70_SPI_MOSI PB_5 |
Adfontes | 34:a7f205c92059 | 37 | #define LM70_SPI_MISO PB_4 |
Adfontes | 34:a7f205c92059 | 38 | #define LM70_SPI_SCK PB_3 |
Adfontes | 34:a7f205c92059 | 39 | #define LM70_SPI_CS PA_4 |
Adfontes | 34:a7f205c92059 | 40 | #define LM70_LSB 0.25 |
Adfontes | 34:a7f205c92059 | 41 | |
lawliet | 0:4e3cb26f6019 | 42 | int main(void) |
lawliet | 0:4e3cb26f6019 | 43 | { |
mazgch | 2:b77151f111a9 | 44 | int ret; |
mazgch | 19:f022ff746eb8 | 45 | #ifdef LARGE_DATA |
mazgch | 16:43f6de7bc38b | 46 | char buf[2048] = ""; |
mazgch | 17:c293780a40ac | 47 | #else |
mazgch | 17:c293780a40ac | 48 | char buf[512] = ""; |
mazgch | 17:c293780a40ac | 49 | #endif |
lawliet | 0:4e3cb26f6019 | 50 | |
mazgch | 19:f022ff746eb8 | 51 | // Create the GPS object |
Adfontes | 34:a7f205c92059 | 52 | #if 0 // use GPSI2C class |
mazgch | 19:f022ff746eb8 | 53 | GPSI2C gps; |
mazgch | 19:f022ff746eb8 | 54 | #else // or GPSSerial class |
Adfontes | 34:a7f205c92059 | 55 | GPSSerial gps(PA_11, PA_12); |
mazgch | 10:d2da2028a233 | 56 | #endif |
mazgch | 10:d2da2028a233 | 57 | // Create the modem object |
Adfontes | 34:a7f205c92059 | 58 | MDMSerial mdm(D8, D2); // use mdm(D1,D0) if you connect the cellular shield to a C027 |
mazgch | 28:334263983fcd | 59 | //mdm.setDebug(4); // enable this for debugging issues |
mazgch | 2:b77151f111a9 | 60 | // initialize the modem |
mazgch | 19:f022ff746eb8 | 61 | MDMParser::DevStatus devStatus = {}; |
mazgch | 19:f022ff746eb8 | 62 | MDMParser::NetStatus netStatus = {}; |
mazgch | 10:d2da2028a233 | 63 | bool mdmOk = mdm.init(SIMPIN, &devStatus); |
mazgch | 19:f022ff746eb8 | 64 | mdm.dumpDevStatus(&devStatus); |
mazgch | 19:f022ff746eb8 | 65 | if (mdmOk) { |
mazgch | 20:52f0e5de8c3d | 66 | #if 0 |
mazgch | 20:52f0e5de8c3d | 67 | // file system API |
mazgch | 19:f022ff746eb8 | 68 | const char* filename = "File"; |
mazgch | 19:f022ff746eb8 | 69 | char buf[] = "Hello World"; |
mazgch | 19:f022ff746eb8 | 70 | printf("writeFile \"%s\"\r\n", buf); |
mazgch | 19:f022ff746eb8 | 71 | if (mdm.writeFile(filename, buf, sizeof(buf))) |
mazgch | 19:f022ff746eb8 | 72 | { |
mazgch | 19:f022ff746eb8 | 73 | memset(buf, 0, sizeof(buf)); |
mazgch | 19:f022ff746eb8 | 74 | int len = mdm.readFile(filename, buf, sizeof(buf)); |
mazgch | 24:81f5b43a6585 | 75 | if (len >= 0) |
mazgch | 19:f022ff746eb8 | 76 | printf("readFile %d \"%.*s\"\r\n", len, len, buf); |
mazgch | 19:f022ff746eb8 | 77 | mdm.delFile(filename); |
mazgch | 19:f022ff746eb8 | 78 | } |
mazgch | 20:52f0e5de8c3d | 79 | #endif |
mazgch | 20:52f0e5de8c3d | 80 | |
mazgch | 20:52f0e5de8c3d | 81 | // wait until we are connected |
mazgch | 20:52f0e5de8c3d | 82 | mdmOk = mdm.registerNet(&netStatus); |
mazgch | 20:52f0e5de8c3d | 83 | mdm.dumpNetStatus(&netStatus); |
mazgch | 20:52f0e5de8c3d | 84 | } |
mazgch | 20:52f0e5de8c3d | 85 | if (mdmOk) |
mazgch | 20:52f0e5de8c3d | 86 | { |
mazgch | 4:90ab1ec64b0e | 87 | // join the internet connection |
mazgch | 19:f022ff746eb8 | 88 | MDMParser::IP ip = mdm.join(APN,USERNAME,PASSWORD); |
mazgch | 32:b838fcaba45e | 89 | if (ip == NOIP) |
mazgch | 32:b838fcaba45e | 90 | printf("Not able to join network"); |
mazgch | 32:b838fcaba45e | 91 | else |
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 | 30:062717f25e41 | 183 | |
mazgch | 30:062717f25e41 | 184 | // http://www.geckobeach.com/cellular/secrets/gsmcodes.php |
mazgch | 30:062717f25e41 | 185 | // http://de.wikipedia.org/wiki/USSD-Codes |
mazgch | 30:062717f25e41 | 186 | const char* ussd = "*130#"; // You may get answer "UNKNOWN APPLICATION" |
mazgch | 30:062717f25e41 | 187 | printf("Ussd Send Command %s\r\n", ussd); |
mazgch | 30:062717f25e41 | 188 | ret = mdm.ussdCommand(ussd, buf); |
mazgch | 30:062717f25e41 | 189 | if (ret > 0) |
mazgch | 30:062717f25e41 | 190 | printf("Ussd Got Answer: \"%s\"\r\n", buf); |
mazgch | 10:d2da2028a233 | 191 | } |
mazgch | 30:062717f25e41 | 192 | |
mazgch | 19:f022ff746eb8 | 193 | printf("SMS and GPS Loop\r\n"); |
mazgch | 10:d2da2028a233 | 194 | char link[128] = ""; |
mazgch | 10:d2da2028a233 | 195 | unsigned int i = 0xFFFFFFFF; |
mazgch | 10:d2da2028a233 | 196 | const int wait = 100; |
mazgch | 10:d2da2028a233 | 197 | bool abort = false; |
msinig | 29:16f1037626e3 | 198 | #ifdef CELLOCATE |
msinig | 29:16f1037626e3 | 199 | const int sensorMask = 3; // Hybrid: GNSS + CellLocate |
msinig | 29:16f1037626e3 | 200 | const int timeoutMargin = 5; // seconds |
msinig | 29:16f1037626e3 | 201 | const int submitPeriod = 60; // 1 minutes in seconds |
msinig | 29:16f1037626e3 | 202 | const int targetAccuracy = 1; // meters |
msinig | 29:16f1037626e3 | 203 | unsigned int j = submitPeriod * 1000/wait; |
msinig | 29:16f1037626e3 | 204 | bool cellLocWait = false; |
msinig | 29:16f1037626e3 | 205 | MDMParser::CellLocData loc; |
msinig | 29:16f1037626e3 | 206 | |
msinig | 29:16f1037626e3 | 207 | //Token can be released from u-blox site, when you got one replace "TOKEN" below |
msinig | 29:16f1037626e3 | 208 | if (!mdm.cellLocSrvHttp("TOKEN")) |
msinig | 29:16f1037626e3 | 209 | mdm.cellLocSrvUdp(); |
msinig | 29:16f1037626e3 | 210 | mdm.cellLocConfigSensor(1); // Deep scan mode |
msinig | 29:16f1037626e3 | 211 | //mdm.cellUnsolIndication(1); |
msinig | 29:16f1037626e3 | 212 | #endif |
Adfontes | 34:a7f205c92059 | 213 | |
Adfontes | 34:a7f205c92059 | 214 | SPI lm70_spi(LM70_SPI_MOSI, LM70_SPI_MISO, LM70_SPI_SCK); |
Adfontes | 34:a7f205c92059 | 215 | DigitalOut lm70_cs(LM70_SPI_CS, 1); |
Adfontes | 34:a7f205c92059 | 216 | |
Adfontes | 34:a7f205c92059 | 217 | const int lm70Period = 60; // 1 minutes in seconds |
Adfontes | 34:a7f205c92059 | 218 | unsigned int k = lm70Period * 1000/wait; |
Adfontes | 34:a7f205c92059 | 219 | |
Adfontes | 34:a7f205c92059 | 220 | uint8_t spi_buf[2]; |
Adfontes | 34:a7f205c92059 | 221 | uint16_t* temp = (uint16_t*)spi_buf; |
Adfontes | 34:a7f205c92059 | 222 | float fT = 0.0; |
Adfontes | 34:a7f205c92059 | 223 | char strT[128] = ""; |
Adfontes | 34:a7f205c92059 | 224 | |
Adfontes | 34:a7f205c92059 | 225 | lm70_spi.frequency(125000); |
Adfontes | 34:a7f205c92059 | 226 | |
Adfontes | 34:a7f205c92059 | 227 | DigitalOut led(LED1); |
mazgch | 10:d2da2028a233 | 228 | while (!abort) { |
Adfontes | 34:a7f205c92059 | 229 | led = !led; |
Adfontes | 34:a7f205c92059 | 230 | |
Adfontes | 34:a7f205c92059 | 231 | if( k++ == lm70Period * 1000/wait ) |
Adfontes | 34:a7f205c92059 | 232 | { |
Adfontes | 34:a7f205c92059 | 233 | k = 0; |
Adfontes | 34:a7f205c92059 | 234 | |
Adfontes | 34:a7f205c92059 | 235 | lm70_cs = 0; |
Adfontes | 34:a7f205c92059 | 236 | spi_buf[1] = lm70_spi.write(0x00); |
Adfontes | 34:a7f205c92059 | 237 | spi_buf[0] = lm70_spi.write(0x00); |
Adfontes | 34:a7f205c92059 | 238 | lm70_cs = 1; |
Adfontes | 34:a7f205c92059 | 239 | if( (*temp & 0x001C) != 0x001C ) |
Adfontes | 34:a7f205c92059 | 240 | { |
Adfontes | 34:a7f205c92059 | 241 | printf("T: Error!\r\n"); |
Adfontes | 34:a7f205c92059 | 242 | } |
Adfontes | 34:a7f205c92059 | 243 | else |
Adfontes | 34:a7f205c92059 | 244 | { |
Adfontes | 34:a7f205c92059 | 245 | fT = ((int16_t)(*temp) >> 5) * LM70_LSB; |
Adfontes | 34:a7f205c92059 | 246 | printf("T: %.2f\r\n", fT); |
Adfontes | 34:a7f205c92059 | 247 | } |
Adfontes | 34:a7f205c92059 | 248 | |
Adfontes | 34:a7f205c92059 | 249 | if( mdmOk ) |
Adfontes | 34:a7f205c92059 | 250 | { |
Adfontes | 34:a7f205c92059 | 251 | // join the internet connection |
Adfontes | 34:a7f205c92059 | 252 | MDMParser::IP ip = mdm.join(APN,USERNAME,PASSWORD); |
Adfontes | 34:a7f205c92059 | 253 | if( ip == NOIP ) |
Adfontes | 34:a7f205c92059 | 254 | printf("Not able to join network"); |
Adfontes | 34:a7f205c92059 | 255 | else |
Adfontes | 34:a7f205c92059 | 256 | { |
Adfontes | 34:a7f205c92059 | 257 | mdm.dumpIp(ip); |
Adfontes | 34:a7f205c92059 | 258 | printf("Make a Http Post Request\r\n"); |
Adfontes | 34:a7f205c92059 | 259 | int socket = mdm.socketSocket(MDMParser::IPPROTO_TCP); |
Adfontes | 34:a7f205c92059 | 260 | if( socket >= 0 ) |
Adfontes | 34:a7f205c92059 | 261 | { |
Adfontes | 34:a7f205c92059 | 262 | mdm.socketSetBlocking(socket, 10000); |
Adfontes | 34:a7f205c92059 | 263 | if( mdm.socketConnect(socket, "api.thingspeak.com", 80) ) |
Adfontes | 34:a7f205c92059 | 264 | { |
Adfontes | 34:a7f205c92059 | 265 | char http[128] = ""; |
Adfontes | 34:a7f205c92059 | 266 | sprintf(http, "GET /update?key=55JOP6J3OOKJNO3R&field1=%.1f\r\n\r\n", fT); |
Adfontes | 34:a7f205c92059 | 267 | mdm.socketSend(socket, http, sizeof(http)-1); |
Adfontes | 34:a7f205c92059 | 268 | |
Adfontes | 34:a7f205c92059 | 269 | ret = mdm.socketRecv(socket, buf, sizeof(buf)-1); |
Adfontes | 34:a7f205c92059 | 270 | if( ret > 0 ) |
Adfontes | 34:a7f205c92059 | 271 | printf("Socket Recv \"%*s\"\r\n", ret, buf); |
Adfontes | 34:a7f205c92059 | 272 | mdm.socketClose(socket); |
Adfontes | 34:a7f205c92059 | 273 | } |
Adfontes | 34:a7f205c92059 | 274 | mdm.socketFree(socket); |
Adfontes | 34:a7f205c92059 | 275 | } |
Adfontes | 34:a7f205c92059 | 276 | |
Adfontes | 34:a7f205c92059 | 277 | // disconnect |
Adfontes | 34:a7f205c92059 | 278 | mdm.disconnect(); |
Adfontes | 34:a7f205c92059 | 279 | } |
Adfontes | 34:a7f205c92059 | 280 | } |
Adfontes | 34:a7f205c92059 | 281 | } |
Adfontes | 34:a7f205c92059 | 282 | |
msinig | 29:16f1037626e3 | 283 | #ifndef CELLOCATE |
mazgch | 10:d2da2028a233 | 284 | while ((ret = gps.getMessage(buf, sizeof(buf))) > 0) |
mazgch | 10:d2da2028a233 | 285 | { |
mazgch | 10:d2da2028a233 | 286 | int len = LENGTH(ret); |
mazgch | 19:f022ff746eb8 | 287 | //printf("NMEA: %.*s\r\n", len-2, msg); |
mazgch | 19:f022ff746eb8 | 288 | if ((PROTOCOL(ret) == GPSParser::NMEA) && (len > 6)) |
mazgch | 4:90ab1ec64b0e | 289 | { |
mazgch | 27:fe3b383dd4ec | 290 | // talker is $GA=Galileo $GB=Beidou $GL=Glonass $GN=Combined $GP=GPS |
mazgch | 27:fe3b383dd4ec | 291 | if ((buf[0] == '$') || buf[1] == 'G') { |
mazgch | 27:fe3b383dd4ec | 292 | #define _CHECK_TALKER(s) ((buf[3] == s[0]) && (buf[4] == s[1]) && (buf[5] == s[2])) |
mazgch | 27:fe3b383dd4ec | 293 | if (_CHECK_TALKER("GLL")) { |
mazgch | 27:fe3b383dd4ec | 294 | double la = 0, lo = 0; |
mazgch | 27:fe3b383dd4ec | 295 | char ch; |
mazgch | 27:fe3b383dd4ec | 296 | if (gps.getNmeaAngle(1,buf,len,la) && |
mazgch | 27:fe3b383dd4ec | 297 | gps.getNmeaAngle(3,buf,len,lo) && |
mazgch | 27:fe3b383dd4ec | 298 | gps.getNmeaItem(6,buf,len,ch) && ch == 'A') |
mazgch | 27:fe3b383dd4ec | 299 | { |
mazgch | 27:fe3b383dd4ec | 300 | printf("GPS Location: %.5f %.5f\r\n", la, lo); |
mazgch | 27:fe3b383dd4ec | 301 | sprintf(link, "I am here!\n" |
mazgch | 27:fe3b383dd4ec | 302 | "https://maps.google.com/?q=%.5f,%.5f", la, lo); |
mazgch | 27:fe3b383dd4ec | 303 | } |
mazgch | 27:fe3b383dd4ec | 304 | } else if (_CHECK_TALKER("GGA") || _CHECK_TALKER("GNS") ) { |
mazgch | 27:fe3b383dd4ec | 305 | double a = 0; |
mazgch | 27:fe3b383dd4ec | 306 | if (gps.getNmeaItem(9,buf,len,a)) // altitude msl [m] |
mazgch | 27:fe3b383dd4ec | 307 | printf("GPS Altitude: %.1f\r\n", a); |
mazgch | 27:fe3b383dd4ec | 308 | } else if (_CHECK_TALKER("VTG")) { |
mazgch | 27:fe3b383dd4ec | 309 | double s = 0; |
mazgch | 27:fe3b383dd4ec | 310 | if (gps.getNmeaItem(7,buf,len,s)) // speed [km/h] |
mazgch | 27:fe3b383dd4ec | 311 | printf("GPS Speed: %.1f\r\n", s); |
mazgch | 19:f022ff746eb8 | 312 | } |
mazgch | 4:90ab1ec64b0e | 313 | } |
mazgch | 4:90ab1ec64b0e | 314 | } |
mazgch | 10:d2da2028a233 | 315 | } |
msinig | 29:16f1037626e3 | 316 | #endif |
msinig | 29:16f1037626e3 | 317 | #ifdef CELLOCATE |
msinig | 29:16f1037626e3 | 318 | if (mdmOk && (j++ == submitPeriod * 1000/wait)) { |
msinig | 29:16f1037626e3 | 319 | j=0; |
msinig | 29:16f1037626e3 | 320 | printf("CellLocate Request\r\n"); |
msinig | 29:16f1037626e3 | 321 | mdm.cellLocRequest(sensorMask, submitPeriod-timeoutMargin, targetAccuracy); |
msinig | 29:16f1037626e3 | 322 | cellLocWait = true; |
msinig | 29:16f1037626e3 | 323 | } |
msinig | 29:16f1037626e3 | 324 | if (cellLocWait && mdm.cellLocGet(&loc)){ |
msinig | 29:16f1037626e3 | 325 | cellLocWait = false; |
msinig | 29:16f1037626e3 | 326 | printf("CellLocate position received, sensor_used: %d, \r\n", loc.sensorUsed ); |
msinig | 29:16f1037626e3 | 327 | printf(" latitude: %0.5f, longitude: %0.5f, altitute: %d\r\n", loc.latitue, loc.longitude, loc.altitutude); |
msinig | 29:16f1037626e3 | 328 | if (loc.sensorUsed == 1) |
msinig | 29:16f1037626e3 | 329 | 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 | 330 | if (loc.sensorUsed == 1 || loc.sensorUsed == 2) |
msinig | 29:16f1037626e3 | 331 | sprintf(link, "I am here!\n" |
msinig | 29:16f1037626e3 | 332 | "https://maps.google.com/?q=%.5f,%.5f", loc.latitue, loc.longitude); |
msinig | 29:16f1037626e3 | 333 | } |
msinig | 29:16f1037626e3 | 334 | if (cellLocWait && (j%100 == 0 )) |
msinig | 29:16f1037626e3 | 335 | printf("Waiting for CellLocate...\r\n"); |
msinig | 29:16f1037626e3 | 336 | #endif |
mazgch | 19:f022ff746eb8 | 337 | if (mdmOk && (i++ == 5000/wait)) { |
mazgch | 10:d2da2028a233 | 338 | i = 0; |
mazgch | 10:d2da2028a233 | 339 | // check the network status |
mazgch | 15:ea10b6cf8c85 | 340 | if (mdm.checkNetStatus(&netStatus)) { |
mazgch | 19:f022ff746eb8 | 341 | mdm.dumpNetStatus(&netStatus, fprintf, stdout); |
mazgch | 15:ea10b6cf8c85 | 342 | } |
mazgch | 10:d2da2028a233 | 343 | |
mazgch | 10:d2da2028a233 | 344 | // checking unread sms |
mazgch | 10:d2da2028a233 | 345 | int ix[8]; |
mazgch | 10:d2da2028a233 | 346 | int n = mdm.smsList("REC UNREAD", ix, 8); |
mazgch | 10:d2da2028a233 | 347 | if (8 < n) n = 8; |
mazgch | 10:d2da2028a233 | 348 | while (0 < n--) |
mazgch | 10:d2da2028a233 | 349 | { |
mazgch | 10:d2da2028a233 | 350 | char num[32]; |
mazgch | 19:f022ff746eb8 | 351 | printf("Unread SMS at index %d\r\n", ix[n]); |
mazgch | 10:d2da2028a233 | 352 | if (mdm.smsRead(ix[n], num, buf, sizeof(buf))) { |
mazgch | 19:f022ff746eb8 | 353 | printf("Got SMS from \"%s\" with text \"%s\"\r\n", num, buf); |
mazgch | 19:f022ff746eb8 | 354 | printf("Delete SMS at index %d\r\n", ix[n]); |
mazgch | 10:d2da2028a233 | 355 | mdm.smsDelete(ix[n]); |
mazgch | 10:d2da2028a233 | 356 | // provide a reply |
mazgch | 10:d2da2028a233 | 357 | const char* reply = "Hello my friend"; |
mazgch | 10:d2da2028a233 | 358 | if (strstr(buf, /*w*/"here are you")) |
mazgch | 10:d2da2028a233 | 359 | reply = *link ? link : "I don't know"; // reply wil location link |
mazgch | 19:f022ff746eb8 | 360 | else if (strstr(buf, /*s*/"hutdown")) |
mazgch | 19:f022ff746eb8 | 361 | abort = true, reply = "bye bye"; |
Adfontes | 34:a7f205c92059 | 362 | else |
Adfontes | 34:a7f205c92059 | 363 | if(strstr(buf, /*w*/"hat is the weather today")) |
Adfontes | 34:a7f205c92059 | 364 | { |
Adfontes | 34:a7f205c92059 | 365 | sprintf(strT, "It's %.2f degrees centigrade", fT); |
Adfontes | 34:a7f205c92059 | 366 | reply = strT; |
Adfontes | 34:a7f205c92059 | 367 | } |
mazgch | 19:f022ff746eb8 | 368 | printf("Send SMS reply \"%s\" to \"%s\"\r\n", reply, num); |
mazgch | 10:d2da2028a233 | 369 | mdm.smsSend(num, reply); |
mazgch | 4:90ab1ec64b0e | 370 | } |
mazgch | 4:90ab1ec64b0e | 371 | } |
mazgch | 9:26f694bc31b4 | 372 | } |
mazgch | 31:a07d0f76dc81 | 373 | #ifdef RTOS_H |
mazgch | 31:a07d0f76dc81 | 374 | Thread::wait(wait); |
mazgch | 31:a07d0f76dc81 | 375 | #else |
mazgch | 31:a07d0f76dc81 | 376 | ::wait_ms(wait); |
mazgch | 31:a07d0f76dc81 | 377 | #endif |
lawliet | 0:4e3cb26f6019 | 378 | } |
mazgch | 19:f022ff746eb8 | 379 | gps.powerOff(); |
mazgch | 10:d2da2028a233 | 380 | mdm.powerOff(); |
lawliet | 0:4e3cb26f6019 | 381 | return 0; |
lawliet | 0:4e3cb26f6019 | 382 | } |