Demo for the Adafruit_FONA_Library. This is a port of the FONAtest available here: https://github.com/adafruit/Adafruit_FONA_Library/tree/master/examples/FONAtest .

Dependencies:   Adafruit_FONA_Library BLE_API SoftSerial mbed nRF51822

Demo for the Adafruit_FONA_Library. This is a port of the FONAtest available here: https://github.com/adafruit/Adafruit_FONA_Library/tree/master/examples/FONAtest .

Committer:
marcpl
Date:
Sat Jun 27 09:26:24 2015 +0000
Revision:
0:8230b1071cc9
Child:
2:6cdaadf03837
Port the FONAtest for Adafruit_FONA_Library for mbed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marcpl 0:8230b1071cc9 1 /***************************************************
marcpl 0:8230b1071cc9 2 This is an example for our Adafruit FONA Cellular Module
marcpl 0:8230b1071cc9 3
marcpl 0:8230b1071cc9 4 Designed specifically to work with the Adafruit FONA
marcpl 0:8230b1071cc9 5 ----> http://www.adafruit.com/products/1946
marcpl 0:8230b1071cc9 6 ----> http://www.adafruit.com/products/1963
marcpl 0:8230b1071cc9 7 ----> http://www.adafruit.com/products/2468
marcpl 0:8230b1071cc9 8 ----> http://www.adafruit.com/products/2542
marcpl 0:8230b1071cc9 9
marcpl 0:8230b1071cc9 10 These cellular modules use TTL Serial to communicate, 2 pins are
marcpl 0:8230b1071cc9 11 required to interface
marcpl 0:8230b1071cc9 12 Adafruit invests time and resources providing this open source code,
marcpl 0:8230b1071cc9 13 please support Adafruit and open-source hardware by purchasing
marcpl 0:8230b1071cc9 14 products from Adafruit!
marcpl 0:8230b1071cc9 15
marcpl 0:8230b1071cc9 16 Written by Limor Fried/Ladyada for Adafruit Industries.
marcpl 0:8230b1071cc9 17 BSD license, all text above must be included in any redistribution
marcpl 0:8230b1071cc9 18 ****************************************************/
marcpl 0:8230b1071cc9 19
marcpl 0:8230b1071cc9 20 /*
marcpl 0:8230b1071cc9 21 * Modified by Marc PLOUHINEC 27/06/2015 for use in mbed
marcpl 0:8230b1071cc9 22 */
marcpl 0:8230b1071cc9 23
marcpl 0:8230b1071cc9 24 /*
marcpl 0:8230b1071cc9 25 THIS CODE IS STILL IN PROGRESS!
marcpl 0:8230b1071cc9 26
marcpl 0:8230b1071cc9 27 Open up the serial console on the Arduino at 4800 baud to interact with FONA
marcpl 0:8230b1071cc9 28
marcpl 0:8230b1071cc9 29 Note that if you need to set a GPRS APN, username, and password scroll down to
marcpl 0:8230b1071cc9 30 the commented section below just before the main "while (true)" loop.
marcpl 0:8230b1071cc9 31 */
marcpl 0:8230b1071cc9 32
marcpl 0:8230b1071cc9 33 #include <ctype.h>
marcpl 0:8230b1071cc9 34 #include "SoftSerial.h"
marcpl 0:8230b1071cc9 35 #include "Adafruit_FONA.h"
marcpl 0:8230b1071cc9 36
marcpl 0:8230b1071cc9 37 #define FONA_RST p12
marcpl 0:8230b1071cc9 38 #define FONA_TX p6
marcpl 0:8230b1071cc9 39 #define FONA_RX p5
marcpl 0:8230b1071cc9 40 #define FONA_RI p4
marcpl 0:8230b1071cc9 41
marcpl 0:8230b1071cc9 42 // this is a large buffer for replies
marcpl 0:8230b1071cc9 43 char replybuffer[255];
marcpl 0:8230b1071cc9 44
marcpl 0:8230b1071cc9 45 Serial fonaSerial(FONA_TX, FONA_RX);
marcpl 0:8230b1071cc9 46 SoftSerial pcSerial(USBTX, USBRX);
marcpl 0:8230b1071cc9 47 Adafruit_FONA fona(FONA_RST, FONA_RI);
marcpl 0:8230b1071cc9 48
marcpl 0:8230b1071cc9 49 // Functions defined after main()
marcpl 0:8230b1071cc9 50 uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);
marcpl 0:8230b1071cc9 51 void printMenu(void);
marcpl 0:8230b1071cc9 52 void flushSerial();
marcpl 0:8230b1071cc9 53 char readBlocking();
marcpl 0:8230b1071cc9 54 uint16_t readnumber();
marcpl 0:8230b1071cc9 55 long map(long x, long in_min, long in_max, long out_min, long out_max);
marcpl 0:8230b1071cc9 56
marcpl 0:8230b1071cc9 57 int main() {
marcpl 0:8230b1071cc9 58 pcSerial.baud(4800);
marcpl 0:8230b1071cc9 59 wait(1);
marcpl 0:8230b1071cc9 60 pcSerial.printf("\r\n");
marcpl 0:8230b1071cc9 61
marcpl 0:8230b1071cc9 62 pcSerial.printf("FONA basic test\r\n");
marcpl 0:8230b1071cc9 63 pcSerial.printf("Initializing....(May take 3 seconds)\r\n");
marcpl 0:8230b1071cc9 64
marcpl 0:8230b1071cc9 65 // make it slow so its easy to read!
marcpl 0:8230b1071cc9 66 fonaSerial.baud(9600);
marcpl 0:8230b1071cc9 67
marcpl 0:8230b1071cc9 68 // See if the FONA is responding
marcpl 0:8230b1071cc9 69 if (! fona.begin(fonaSerial)) {
marcpl 0:8230b1071cc9 70 pcSerial.printf("Couldn't find FONA\r\n");
marcpl 0:8230b1071cc9 71 while (1);
marcpl 0:8230b1071cc9 72 }
marcpl 0:8230b1071cc9 73 pcSerial.printf("FONA is OK\r\n");
marcpl 0:8230b1071cc9 74
marcpl 0:8230b1071cc9 75 // Print SIM card IMEI number.
marcpl 0:8230b1071cc9 76 char imei[15] = {0}; // MUST use a 16 character buffer for IMEI!
marcpl 0:8230b1071cc9 77 uint8_t imeiLen = fona.getIMEI(imei);
marcpl 0:8230b1071cc9 78 if (imeiLen > 0) {
marcpl 0:8230b1071cc9 79 pcSerial.printf("SIM card IMEI: %s\r\n", imei);
marcpl 0:8230b1071cc9 80 }
marcpl 0:8230b1071cc9 81
marcpl 0:8230b1071cc9 82 // Optionally configure a GPRS APN, username, and password.
marcpl 0:8230b1071cc9 83 // You might need to do this to access your network's GPRS/data
marcpl 0:8230b1071cc9 84 // network. Contact your provider for the exact APN, username,
marcpl 0:8230b1071cc9 85 // and password values. Username and password are optional and
marcpl 0:8230b1071cc9 86 // can be removed, but APN is required.
marcpl 0:8230b1071cc9 87 //fona.setGPRSNetworkSettings("your APN", "your username", "your password");
marcpl 0:8230b1071cc9 88 fona.setGPRSNetworkSettings("web.pt.lu", "", "");
marcpl 0:8230b1071cc9 89
marcpl 0:8230b1071cc9 90 // Optionally configure HTTP gets to follow redirects over SSL.
marcpl 0:8230b1071cc9 91 // Default is not to follow SSL redirects, however if you uncomment
marcpl 0:8230b1071cc9 92 // the following line then redirects over SSL will be followed.
marcpl 0:8230b1071cc9 93 //fona.setHTTPSRedirect(true);
marcpl 0:8230b1071cc9 94
marcpl 0:8230b1071cc9 95 printMenu();
marcpl 0:8230b1071cc9 96
marcpl 0:8230b1071cc9 97 while (true) {
marcpl 0:8230b1071cc9 98 pcSerial.printf("FONA> ");
marcpl 0:8230b1071cc9 99 while (! pcSerial.readable() ) {
marcpl 0:8230b1071cc9 100 if (fonaSerial.readable()) {
marcpl 0:8230b1071cc9 101 pcSerial.putc(fonaSerial.getc());
marcpl 0:8230b1071cc9 102 }
marcpl 0:8230b1071cc9 103 }
marcpl 0:8230b1071cc9 104
marcpl 0:8230b1071cc9 105 char command = pcSerial.getc();
marcpl 0:8230b1071cc9 106 pcSerial.printf("%c\r\n", command);
marcpl 0:8230b1071cc9 107
marcpl 0:8230b1071cc9 108
marcpl 0:8230b1071cc9 109 switch (command) {
marcpl 0:8230b1071cc9 110 case '?': {
marcpl 0:8230b1071cc9 111 printMenu();
marcpl 0:8230b1071cc9 112 break;
marcpl 0:8230b1071cc9 113 }
marcpl 0:8230b1071cc9 114
marcpl 0:8230b1071cc9 115 case 'a': {
marcpl 0:8230b1071cc9 116 // read the ADC
marcpl 0:8230b1071cc9 117 uint16_t adc;
marcpl 0:8230b1071cc9 118 if (! fona.getADCVoltage(&adc)) {
marcpl 0:8230b1071cc9 119 pcSerial.printf("Failed to read ADC\r\n");
marcpl 0:8230b1071cc9 120 } else {
marcpl 0:8230b1071cc9 121 pcSerial.printf("ADC = %d mV\r\n", adc);
marcpl 0:8230b1071cc9 122 }
marcpl 0:8230b1071cc9 123 break;
marcpl 0:8230b1071cc9 124 }
marcpl 0:8230b1071cc9 125
marcpl 0:8230b1071cc9 126 case 'b': {
marcpl 0:8230b1071cc9 127 // read the battery voltage and percentage
marcpl 0:8230b1071cc9 128 uint16_t vbat;
marcpl 0:8230b1071cc9 129 if (! fona.getBattVoltage(&vbat)) {
marcpl 0:8230b1071cc9 130 pcSerial.printf("Failed to read Batt\r\n");
marcpl 0:8230b1071cc9 131 } else {
marcpl 0:8230b1071cc9 132 pcSerial.printf("VBat = %d mV\r\n", vbat);
marcpl 0:8230b1071cc9 133 }
marcpl 0:8230b1071cc9 134
marcpl 0:8230b1071cc9 135 if (! fona.getBattPercent(&vbat)) {
marcpl 0:8230b1071cc9 136 pcSerial.printf("Failed to read Batt\r\n");
marcpl 0:8230b1071cc9 137 } else {
marcpl 0:8230b1071cc9 138 pcSerial.printf("VPct = %d%%\r\n", vbat);
marcpl 0:8230b1071cc9 139 }
marcpl 0:8230b1071cc9 140
marcpl 0:8230b1071cc9 141 break;
marcpl 0:8230b1071cc9 142 }
marcpl 0:8230b1071cc9 143
marcpl 0:8230b1071cc9 144 case 'U': {
marcpl 0:8230b1071cc9 145 // Unlock the SIM with a PIN code
marcpl 0:8230b1071cc9 146 char PIN[5];
marcpl 0:8230b1071cc9 147 flushSerial();
marcpl 0:8230b1071cc9 148 pcSerial.printf("Enter 4-digit PIN\r\n");
marcpl 0:8230b1071cc9 149 readline(PIN, 3);
marcpl 0:8230b1071cc9 150 pcSerial.printf("%s\r\n", PIN);
marcpl 0:8230b1071cc9 151 pcSerial.printf("Unlocking SIM card: ");
marcpl 0:8230b1071cc9 152 if (! fona.unlockSIM(PIN)) {
marcpl 0:8230b1071cc9 153 pcSerial.printf("Failed\r\n");
marcpl 0:8230b1071cc9 154 } else {
marcpl 0:8230b1071cc9 155 pcSerial.printf("OK!\r\n");
marcpl 0:8230b1071cc9 156 }
marcpl 0:8230b1071cc9 157 break;
marcpl 0:8230b1071cc9 158 }
marcpl 0:8230b1071cc9 159
marcpl 0:8230b1071cc9 160 case 'C': {
marcpl 0:8230b1071cc9 161 // read the CCID
marcpl 0:8230b1071cc9 162 fona.getSIMCCID(replybuffer); // make sure replybuffer is at least 21 bytes!
marcpl 0:8230b1071cc9 163 pcSerial.printf("SIM CCID = %s\r\n", replybuffer);
marcpl 0:8230b1071cc9 164 break;
marcpl 0:8230b1071cc9 165 }
marcpl 0:8230b1071cc9 166
marcpl 0:8230b1071cc9 167 case 'i': {
marcpl 0:8230b1071cc9 168 // read the RSSI
marcpl 0:8230b1071cc9 169 uint8_t n = fona.getRSSI();
marcpl 0:8230b1071cc9 170 int8_t r = 0;
marcpl 0:8230b1071cc9 171
marcpl 0:8230b1071cc9 172 pcSerial.printf("RSSI = %d: ", n);
marcpl 0:8230b1071cc9 173 if (n == 0) r = -115;
marcpl 0:8230b1071cc9 174 if (n == 1) r = -111;
marcpl 0:8230b1071cc9 175 if (n == 31) r = -52;
marcpl 0:8230b1071cc9 176 if ((n >= 2) && (n <= 30)) {
marcpl 0:8230b1071cc9 177 r = map(n, 2, 30, -110, -54);
marcpl 0:8230b1071cc9 178 }
marcpl 0:8230b1071cc9 179 pcSerial.printf("%d dBm\r\n", r);
marcpl 0:8230b1071cc9 180
marcpl 0:8230b1071cc9 181 break;
marcpl 0:8230b1071cc9 182 }
marcpl 0:8230b1071cc9 183
marcpl 0:8230b1071cc9 184 case 'n': {
marcpl 0:8230b1071cc9 185 // read the network/cellular status
marcpl 0:8230b1071cc9 186 uint8_t n = fona.getNetworkStatus();
marcpl 0:8230b1071cc9 187 pcSerial.printf("Network status %d: ", n);
marcpl 0:8230b1071cc9 188 if (n == 0) pcSerial.printf("Not registered\r\n");
marcpl 0:8230b1071cc9 189 if (n == 1) pcSerial.printf("Registered (home)\r\n");
marcpl 0:8230b1071cc9 190 if (n == 2) pcSerial.printf("Not registered (searching)\r\n");
marcpl 0:8230b1071cc9 191 if (n == 3) pcSerial.printf("Denied\r\n");
marcpl 0:8230b1071cc9 192 if (n == 4) pcSerial.printf("Unknown\r\n");
marcpl 0:8230b1071cc9 193 if (n == 5) pcSerial.printf("Registered roaming\r\n");
marcpl 0:8230b1071cc9 194 break;
marcpl 0:8230b1071cc9 195 }
marcpl 0:8230b1071cc9 196
marcpl 0:8230b1071cc9 197 /*** Audio ***/
marcpl 0:8230b1071cc9 198 case 'v': {
marcpl 0:8230b1071cc9 199 // set volume
marcpl 0:8230b1071cc9 200 flushSerial();
marcpl 0:8230b1071cc9 201 pcSerial.printf("Set Vol %%");
marcpl 0:8230b1071cc9 202 uint8_t vol = readnumber();
marcpl 0:8230b1071cc9 203 pcSerial.printf("\r\n");
marcpl 0:8230b1071cc9 204 if (! fona.setVolume(vol)) {
marcpl 0:8230b1071cc9 205 pcSerial.printf("Failed\r\n");
marcpl 0:8230b1071cc9 206 } else {
marcpl 0:8230b1071cc9 207 pcSerial.printf("OK!\r\n");
marcpl 0:8230b1071cc9 208 }
marcpl 0:8230b1071cc9 209 break;
marcpl 0:8230b1071cc9 210 }
marcpl 0:8230b1071cc9 211
marcpl 0:8230b1071cc9 212 case 'V': {
marcpl 0:8230b1071cc9 213 uint8_t v = fona.getVolume();
marcpl 0:8230b1071cc9 214 pcSerial.printf("%d%%\r\n", v);
marcpl 0:8230b1071cc9 215
marcpl 0:8230b1071cc9 216 break;
marcpl 0:8230b1071cc9 217 }
marcpl 0:8230b1071cc9 218
marcpl 0:8230b1071cc9 219 case 'H': {
marcpl 0:8230b1071cc9 220 // Set Headphone output
marcpl 0:8230b1071cc9 221 if (! fona.setAudio(FONA_HEADSETAUDIO)) {
marcpl 0:8230b1071cc9 222 pcSerial.printf("Failed\r\n");
marcpl 0:8230b1071cc9 223 } else {
marcpl 0:8230b1071cc9 224 pcSerial.printf("OK!\r\n");
marcpl 0:8230b1071cc9 225 }
marcpl 0:8230b1071cc9 226 fona.setMicVolume(FONA_HEADSETAUDIO, 15);
marcpl 0:8230b1071cc9 227 break;
marcpl 0:8230b1071cc9 228 }
marcpl 0:8230b1071cc9 229 case 'e': {
marcpl 0:8230b1071cc9 230 // Set External output
marcpl 0:8230b1071cc9 231 if (! fona.setAudio(FONA_EXTAUDIO)) {
marcpl 0:8230b1071cc9 232 pcSerial.printf("Failed\r\n");
marcpl 0:8230b1071cc9 233 } else {
marcpl 0:8230b1071cc9 234 pcSerial.printf("OK!\r\n");
marcpl 0:8230b1071cc9 235 }
marcpl 0:8230b1071cc9 236
marcpl 0:8230b1071cc9 237 fona.setMicVolume(FONA_EXTAUDIO, 10);
marcpl 0:8230b1071cc9 238 break;
marcpl 0:8230b1071cc9 239 }
marcpl 0:8230b1071cc9 240
marcpl 0:8230b1071cc9 241 case 'T': {
marcpl 0:8230b1071cc9 242 // play tone
marcpl 0:8230b1071cc9 243 flushSerial();
marcpl 0:8230b1071cc9 244 pcSerial.printf("Play tone #");
marcpl 0:8230b1071cc9 245 uint8_t kittone = readnumber();
marcpl 0:8230b1071cc9 246 pcSerial.printf("\r\n");
marcpl 0:8230b1071cc9 247 // play for 1 second (1000 ms)
marcpl 0:8230b1071cc9 248 if (! fona.playToolkitTone(kittone, 1000)) {
marcpl 0:8230b1071cc9 249 pcSerial.printf("Failed\r\n");
marcpl 0:8230b1071cc9 250 } else {
marcpl 0:8230b1071cc9 251 pcSerial.printf("OK!\r\n");
marcpl 0:8230b1071cc9 252 }
marcpl 0:8230b1071cc9 253 break;
marcpl 0:8230b1071cc9 254 }
marcpl 0:8230b1071cc9 255
marcpl 0:8230b1071cc9 256 /*** FM Radio ***/
marcpl 0:8230b1071cc9 257
marcpl 0:8230b1071cc9 258 case 'f': {
marcpl 0:8230b1071cc9 259 // get freq
marcpl 0:8230b1071cc9 260 flushSerial();
marcpl 0:8230b1071cc9 261 pcSerial.printf("FM Freq (eg 1011 == 101.1 MHz): ");
marcpl 0:8230b1071cc9 262 uint16_t station = readnumber();
marcpl 0:8230b1071cc9 263 pcSerial.printf("\r\n");
marcpl 0:8230b1071cc9 264 // FM radio ON using headset
marcpl 0:8230b1071cc9 265 if (fona.FMradio(true, FONA_HEADSETAUDIO)) {
marcpl 0:8230b1071cc9 266 pcSerial.printf("Opened\r\n");
marcpl 0:8230b1071cc9 267 }
marcpl 0:8230b1071cc9 268 if (! fona.tuneFMradio(station)) {
marcpl 0:8230b1071cc9 269 pcSerial.printf("Failed\r\n");
marcpl 0:8230b1071cc9 270 } else {
marcpl 0:8230b1071cc9 271 pcSerial.printf("Tuned\r\n");
marcpl 0:8230b1071cc9 272 }
marcpl 0:8230b1071cc9 273 break;
marcpl 0:8230b1071cc9 274 }
marcpl 0:8230b1071cc9 275 case 'F': {
marcpl 0:8230b1071cc9 276 // FM radio off
marcpl 0:8230b1071cc9 277 if (! fona.FMradio(false)) {
marcpl 0:8230b1071cc9 278 pcSerial.printf("Failed\r\n");
marcpl 0:8230b1071cc9 279 } else {
marcpl 0:8230b1071cc9 280 pcSerial.printf("OK!\r\n");
marcpl 0:8230b1071cc9 281 }
marcpl 0:8230b1071cc9 282 break;
marcpl 0:8230b1071cc9 283 }
marcpl 0:8230b1071cc9 284 case 'm': {
marcpl 0:8230b1071cc9 285 // Set FM volume.
marcpl 0:8230b1071cc9 286 flushSerial();
marcpl 0:8230b1071cc9 287 pcSerial.printf("Set FM Vol [0-6]:");
marcpl 0:8230b1071cc9 288 uint8_t vol = readnumber();
marcpl 0:8230b1071cc9 289 pcSerial.printf("\r\n");
marcpl 0:8230b1071cc9 290 if (!fona.setFMVolume(vol)) {
marcpl 0:8230b1071cc9 291 pcSerial.printf("Failed\r\n");
marcpl 0:8230b1071cc9 292 } else {
marcpl 0:8230b1071cc9 293 pcSerial.printf("OK!\r\n");
marcpl 0:8230b1071cc9 294 }
marcpl 0:8230b1071cc9 295 break;
marcpl 0:8230b1071cc9 296 }
marcpl 0:8230b1071cc9 297 case 'M': {
marcpl 0:8230b1071cc9 298 // Get FM volume.
marcpl 0:8230b1071cc9 299 int8_t fmvol = fona.getFMVolume();
marcpl 0:8230b1071cc9 300 if (fmvol < 0) {
marcpl 0:8230b1071cc9 301 pcSerial.printf("Failed\r\n");
marcpl 0:8230b1071cc9 302 } else {
marcpl 0:8230b1071cc9 303 pcSerial.printf("FM volume: %d\r\n", fmvol);
marcpl 0:8230b1071cc9 304 }
marcpl 0:8230b1071cc9 305 break;
marcpl 0:8230b1071cc9 306 }
marcpl 0:8230b1071cc9 307 case 'q': {
marcpl 0:8230b1071cc9 308 // Get FM station signal level (in decibels).
marcpl 0:8230b1071cc9 309 flushSerial();
marcpl 0:8230b1071cc9 310 pcSerial.printf("FM Freq (eg 1011 == 101.1 MHz): ");
marcpl 0:8230b1071cc9 311 uint16_t station = readnumber();
marcpl 0:8230b1071cc9 312 pcSerial.printf("\r\n");
marcpl 0:8230b1071cc9 313 int8_t level = fona.getFMSignalLevel(station);
marcpl 0:8230b1071cc9 314 if (level < 0) {
marcpl 0:8230b1071cc9 315 pcSerial.printf("Failed! Make sure FM radio is on (tuned to station).\r\n");
marcpl 0:8230b1071cc9 316 } else {
marcpl 0:8230b1071cc9 317 pcSerial.printf("Signal level (dB): %d\r\n", level);
marcpl 0:8230b1071cc9 318 }
marcpl 0:8230b1071cc9 319 break;
marcpl 0:8230b1071cc9 320 }
marcpl 0:8230b1071cc9 321
marcpl 0:8230b1071cc9 322 /*** PWM ***/
marcpl 0:8230b1071cc9 323
marcpl 0:8230b1071cc9 324 case 'P': {
marcpl 0:8230b1071cc9 325 // PWM Buzzer output @ 2KHz max
marcpl 0:8230b1071cc9 326 flushSerial();
marcpl 0:8230b1071cc9 327 pcSerial.printf("PWM Freq, 0 = Off, (1-2000): ");
marcpl 0:8230b1071cc9 328 uint16_t freq = readnumber();
marcpl 0:8230b1071cc9 329 pcSerial.printf("\r\n");
marcpl 0:8230b1071cc9 330 if (! fona.setPWM(freq)) {
marcpl 0:8230b1071cc9 331 pcSerial.printf("Failed\r\n");
marcpl 0:8230b1071cc9 332 } else {
marcpl 0:8230b1071cc9 333 pcSerial.printf("OK!\r\n");
marcpl 0:8230b1071cc9 334 }
marcpl 0:8230b1071cc9 335 break;
marcpl 0:8230b1071cc9 336 }
marcpl 0:8230b1071cc9 337
marcpl 0:8230b1071cc9 338 /*** Call ***/
marcpl 0:8230b1071cc9 339 case 'c': {
marcpl 0:8230b1071cc9 340 // call a phone!
marcpl 0:8230b1071cc9 341 char number[30];
marcpl 0:8230b1071cc9 342 flushSerial();
marcpl 0:8230b1071cc9 343 pcSerial.printf("Call #");
marcpl 0:8230b1071cc9 344 readline(number, 30);
marcpl 0:8230b1071cc9 345 pcSerial.printf("\r\n");
marcpl 0:8230b1071cc9 346 pcSerial.printf("Calling %s\r\n", number);
marcpl 0:8230b1071cc9 347 if (!fona.callPhone(number)) {
marcpl 0:8230b1071cc9 348 pcSerial.printf("Failed\r\n");
marcpl 0:8230b1071cc9 349 } else {
marcpl 0:8230b1071cc9 350 pcSerial.printf("Sent!\r\n");
marcpl 0:8230b1071cc9 351 }
marcpl 0:8230b1071cc9 352
marcpl 0:8230b1071cc9 353 break;
marcpl 0:8230b1071cc9 354 }
marcpl 0:8230b1071cc9 355 case 'h': {
marcpl 0:8230b1071cc9 356 // hang up!
marcpl 0:8230b1071cc9 357 if (! fona.hangUp()) {
marcpl 0:8230b1071cc9 358 pcSerial.printf("Failed\r\n");
marcpl 0:8230b1071cc9 359 } else {
marcpl 0:8230b1071cc9 360 pcSerial.printf("OK!\r\n");
marcpl 0:8230b1071cc9 361 }
marcpl 0:8230b1071cc9 362 break;
marcpl 0:8230b1071cc9 363 }
marcpl 0:8230b1071cc9 364
marcpl 0:8230b1071cc9 365 case 'p': {
marcpl 0:8230b1071cc9 366 // pick up!
marcpl 0:8230b1071cc9 367 if (! fona.pickUp()) {
marcpl 0:8230b1071cc9 368 pcSerial.printf("Failed\r\n");
marcpl 0:8230b1071cc9 369 } else {
marcpl 0:8230b1071cc9 370 pcSerial.printf("OK!\r\n");
marcpl 0:8230b1071cc9 371 }
marcpl 0:8230b1071cc9 372 break;
marcpl 0:8230b1071cc9 373 }
marcpl 0:8230b1071cc9 374
marcpl 0:8230b1071cc9 375 /*** SMS ***/
marcpl 0:8230b1071cc9 376
marcpl 0:8230b1071cc9 377 case 'N': {
marcpl 0:8230b1071cc9 378 // read the number of SMS's!
marcpl 0:8230b1071cc9 379 int8_t smsnum = fona.getNumSMS();
marcpl 0:8230b1071cc9 380 if (smsnum < 0) {
marcpl 0:8230b1071cc9 381 pcSerial.printf("Could not read # SMS\r\n");
marcpl 0:8230b1071cc9 382 } else {
marcpl 0:8230b1071cc9 383 pcSerial.printf("%d SMS's on SIM card!\r\n", smsnum);
marcpl 0:8230b1071cc9 384 }
marcpl 0:8230b1071cc9 385 break;
marcpl 0:8230b1071cc9 386 }
marcpl 0:8230b1071cc9 387 case 'r': {
marcpl 0:8230b1071cc9 388 // read an SMS
marcpl 0:8230b1071cc9 389 flushSerial();
marcpl 0:8230b1071cc9 390 pcSerial.printf("Read #");
marcpl 0:8230b1071cc9 391 uint8_t smsn = readnumber();
marcpl 0:8230b1071cc9 392 pcSerial.printf("\r\nReading SMS #%d\r\n", smsn);
marcpl 0:8230b1071cc9 393
marcpl 0:8230b1071cc9 394 // Retrieve SMS sender address/phone number.
marcpl 0:8230b1071cc9 395 if (! fona.getSMSSender(smsn, replybuffer, 250)) {
marcpl 0:8230b1071cc9 396 pcSerial.printf("Failed!\r\n");
marcpl 0:8230b1071cc9 397 break;
marcpl 0:8230b1071cc9 398 }
marcpl 0:8230b1071cc9 399 pcSerial.printf("FROM: %s\r\n", replybuffer);
marcpl 0:8230b1071cc9 400
marcpl 0:8230b1071cc9 401 // Retrieve SMS value.
marcpl 0:8230b1071cc9 402 uint16_t smslen;
marcpl 0:8230b1071cc9 403 if (! fona.readSMS(smsn, replybuffer, 250, &smslen)) { // pass in buffer and max len!
marcpl 0:8230b1071cc9 404 pcSerial.printf("Failed!\r\n");
marcpl 0:8230b1071cc9 405 break;
marcpl 0:8230b1071cc9 406 }
marcpl 0:8230b1071cc9 407 pcSerial.printf("***** SMS #%d (%d) bytes *****\r\n", smsn, smslen);
marcpl 0:8230b1071cc9 408 pcSerial.printf("%s\r\n", replybuffer);
marcpl 0:8230b1071cc9 409 pcSerial.printf("*****\r\n");
marcpl 0:8230b1071cc9 410
marcpl 0:8230b1071cc9 411 break;
marcpl 0:8230b1071cc9 412 }
marcpl 0:8230b1071cc9 413 case 'R': {
marcpl 0:8230b1071cc9 414 // read all SMS
marcpl 0:8230b1071cc9 415 int8_t smsnum = fona.getNumSMS();
marcpl 0:8230b1071cc9 416 uint16_t smslen;
marcpl 0:8230b1071cc9 417 for (int8_t smsn=1; smsn<=smsnum; smsn++) {
marcpl 0:8230b1071cc9 418 pcSerial.printf("\r\nReading SMS #%d\r\n", smsn);
marcpl 0:8230b1071cc9 419 if (!fona.readSMS(smsn, replybuffer, 250, &smslen)) { // pass in buffer and max len!
marcpl 0:8230b1071cc9 420 pcSerial.printf("Failed!\r\n");
marcpl 0:8230b1071cc9 421 break;
marcpl 0:8230b1071cc9 422 }
marcpl 0:8230b1071cc9 423 // if the length is zero, its a special case where the index number is higher
marcpl 0:8230b1071cc9 424 // so increase the max we'll look at!
marcpl 0:8230b1071cc9 425 if (smslen == 0) {
marcpl 0:8230b1071cc9 426 pcSerial.printf("[empty slot]\r\n");
marcpl 0:8230b1071cc9 427 smsnum++;
marcpl 0:8230b1071cc9 428 continue;
marcpl 0:8230b1071cc9 429 }
marcpl 0:8230b1071cc9 430
marcpl 0:8230b1071cc9 431 pcSerial.printf("***** SMS #%d (%d) bytes *****\r\n", smsn, smslen);
marcpl 0:8230b1071cc9 432 pcSerial.printf("%s\r\n", replybuffer);
marcpl 0:8230b1071cc9 433 pcSerial.printf("*****\r\n");
marcpl 0:8230b1071cc9 434 }
marcpl 0:8230b1071cc9 435 break;
marcpl 0:8230b1071cc9 436 }
marcpl 0:8230b1071cc9 437
marcpl 0:8230b1071cc9 438 case 'd': {
marcpl 0:8230b1071cc9 439 // delete an SMS
marcpl 0:8230b1071cc9 440 flushSerial();
marcpl 0:8230b1071cc9 441 pcSerial.printf("Delete #");
marcpl 0:8230b1071cc9 442 uint8_t smsn = readnumber();
marcpl 0:8230b1071cc9 443
marcpl 0:8230b1071cc9 444 pcSerial.printf("\r\nDeleting SMS #%d\r\n", smsn);
marcpl 0:8230b1071cc9 445 if (fona.deleteSMS(smsn)) {
marcpl 0:8230b1071cc9 446 pcSerial.printf("OK!\r\n");
marcpl 0:8230b1071cc9 447 } else {
marcpl 0:8230b1071cc9 448 pcSerial.printf("Couldn't delete\r\n");
marcpl 0:8230b1071cc9 449 }
marcpl 0:8230b1071cc9 450 break;
marcpl 0:8230b1071cc9 451 }
marcpl 0:8230b1071cc9 452
marcpl 0:8230b1071cc9 453 case 's': {
marcpl 0:8230b1071cc9 454 // send an SMS!
marcpl 0:8230b1071cc9 455 char sendto[21], message[141];
marcpl 0:8230b1071cc9 456 flushSerial();
marcpl 0:8230b1071cc9 457 pcSerial.printf("Send to #");
marcpl 0:8230b1071cc9 458 readline(sendto, 20);
marcpl 0:8230b1071cc9 459 pcSerial.printf("%s\r\n", sendto);
marcpl 0:8230b1071cc9 460 pcSerial.printf("Type out one-line message (140 char): ");
marcpl 0:8230b1071cc9 461 readline(message, 140);
marcpl 0:8230b1071cc9 462 pcSerial.printf("%s\r\n", message);
marcpl 0:8230b1071cc9 463 if (!fona.sendSMS(sendto, message)) {
marcpl 0:8230b1071cc9 464 pcSerial.printf("Failed\r\n");
marcpl 0:8230b1071cc9 465 } else {
marcpl 0:8230b1071cc9 466 pcSerial.printf("Sent!\r\n");
marcpl 0:8230b1071cc9 467 }
marcpl 0:8230b1071cc9 468
marcpl 0:8230b1071cc9 469 break;
marcpl 0:8230b1071cc9 470 }
marcpl 0:8230b1071cc9 471
marcpl 0:8230b1071cc9 472 /*** Time ***/
marcpl 0:8230b1071cc9 473
marcpl 0:8230b1071cc9 474 case 'y': {
marcpl 0:8230b1071cc9 475 // enable network time sync
marcpl 0:8230b1071cc9 476 if (!fona.enableNetworkTimeSync(true))
marcpl 0:8230b1071cc9 477 pcSerial.printf("Failed to enable\r\n");
marcpl 0:8230b1071cc9 478 break;
marcpl 0:8230b1071cc9 479 }
marcpl 0:8230b1071cc9 480
marcpl 0:8230b1071cc9 481 case 'Y': {
marcpl 0:8230b1071cc9 482 // enable NTP time sync
marcpl 0:8230b1071cc9 483 if (!fona.enableNTPTimeSync(true, "pool.ntp.org"))
marcpl 0:8230b1071cc9 484 pcSerial.printf("Failed to enable\r\n");
marcpl 0:8230b1071cc9 485 break;
marcpl 0:8230b1071cc9 486 }
marcpl 0:8230b1071cc9 487
marcpl 0:8230b1071cc9 488 case 't': {
marcpl 0:8230b1071cc9 489 // read the time
marcpl 0:8230b1071cc9 490 char buffer[23];
marcpl 0:8230b1071cc9 491
marcpl 0:8230b1071cc9 492 fona.getTime(buffer, 23); // make sure replybuffer is at least 23 bytes!
marcpl 0:8230b1071cc9 493 pcSerial.printf("Time = %s\r\n", buffer);
marcpl 0:8230b1071cc9 494 break;
marcpl 0:8230b1071cc9 495 }
marcpl 0:8230b1071cc9 496
marcpl 0:8230b1071cc9 497 /*********************************** GPS (SIM808 only) */
marcpl 0:8230b1071cc9 498
marcpl 0:8230b1071cc9 499 case 'o': {
marcpl 0:8230b1071cc9 500 // turn GPS off
marcpl 0:8230b1071cc9 501 if (!fona.enableGPS(false))
marcpl 0:8230b1071cc9 502 pcSerial.printf("Failed to turn off\r\n");
marcpl 0:8230b1071cc9 503 break;
marcpl 0:8230b1071cc9 504 }
marcpl 0:8230b1071cc9 505 case 'O': {
marcpl 0:8230b1071cc9 506 // turn GPS on
marcpl 0:8230b1071cc9 507 if (!fona.enableGPS(true))
marcpl 0:8230b1071cc9 508 pcSerial.printf("Failed to turn on\r\n");
marcpl 0:8230b1071cc9 509 break;
marcpl 0:8230b1071cc9 510 }
marcpl 0:8230b1071cc9 511 case 'x': {
marcpl 0:8230b1071cc9 512 int8_t stat;
marcpl 0:8230b1071cc9 513 // check GPS fix
marcpl 0:8230b1071cc9 514 stat = fona.GPSstatus();
marcpl 0:8230b1071cc9 515 if (stat < 0)
marcpl 0:8230b1071cc9 516 pcSerial.printf("Failed to query\r\n");
marcpl 0:8230b1071cc9 517 if (stat == 0) pcSerial.printf("GPS off\r\n");
marcpl 0:8230b1071cc9 518 if (stat == 1) pcSerial.printf("No fix\r\n");
marcpl 0:8230b1071cc9 519 if (stat == 2) pcSerial.printf("2D fix\r\n");
marcpl 0:8230b1071cc9 520 if (stat == 3) pcSerial.printf("3D fix\r\n");
marcpl 0:8230b1071cc9 521 break;
marcpl 0:8230b1071cc9 522 }
marcpl 0:8230b1071cc9 523
marcpl 0:8230b1071cc9 524 case 'L': {
marcpl 0:8230b1071cc9 525 // check for GPS location
marcpl 0:8230b1071cc9 526 char gpsdata[80];
marcpl 0:8230b1071cc9 527 fona.getGPS(0, gpsdata, 80);
marcpl 0:8230b1071cc9 528 pcSerial.printf("Reply in format: mode,longitude,latitude,altitude,utctime(yyyymmddHHMMSS),ttff,satellites,speed,course\r\n");
marcpl 0:8230b1071cc9 529 pcSerial.printf("%s\r\n", gpsdata);
marcpl 0:8230b1071cc9 530
marcpl 0:8230b1071cc9 531 break;
marcpl 0:8230b1071cc9 532 }
marcpl 0:8230b1071cc9 533
marcpl 0:8230b1071cc9 534 case 'E': {
marcpl 0:8230b1071cc9 535 flushSerial();
marcpl 0:8230b1071cc9 536 pcSerial.printf("GPS NMEA output sentences (0 = off, 34 = RMC+GGA, 255 = all)\r\n");
marcpl 0:8230b1071cc9 537 uint8_t nmeaout = readnumber();
marcpl 0:8230b1071cc9 538
marcpl 0:8230b1071cc9 539 // turn on NMEA output
marcpl 0:8230b1071cc9 540 fona.enableGPSNMEA(nmeaout);
marcpl 0:8230b1071cc9 541
marcpl 0:8230b1071cc9 542 break;
marcpl 0:8230b1071cc9 543 }
marcpl 0:8230b1071cc9 544
marcpl 0:8230b1071cc9 545 /*********************************** GPRS */
marcpl 0:8230b1071cc9 546
marcpl 0:8230b1071cc9 547 case 'g': {
marcpl 0:8230b1071cc9 548 // turn GPRS off
marcpl 0:8230b1071cc9 549 if (!fona.enableGPRS(false))
marcpl 0:8230b1071cc9 550 pcSerial.printf("Failed to turn off\r\n");
marcpl 0:8230b1071cc9 551 break;
marcpl 0:8230b1071cc9 552 }
marcpl 0:8230b1071cc9 553 case 'G': {
marcpl 0:8230b1071cc9 554 // turn GPRS on
marcpl 0:8230b1071cc9 555 if (!fona.enableGPRS(true))
marcpl 0:8230b1071cc9 556 pcSerial.printf("Failed to turn on\r\n");
marcpl 0:8230b1071cc9 557 break;
marcpl 0:8230b1071cc9 558 }
marcpl 0:8230b1071cc9 559 case 'l': {
marcpl 0:8230b1071cc9 560 // check for GSMLOC (requires GPRS)
marcpl 0:8230b1071cc9 561 uint16_t returncode;
marcpl 0:8230b1071cc9 562
marcpl 0:8230b1071cc9 563 if (!fona.getGSMLoc(&returncode, replybuffer, 250))
marcpl 0:8230b1071cc9 564 pcSerial.printf("Failed!\r\n");
marcpl 0:8230b1071cc9 565 if (returncode == 0) {
marcpl 0:8230b1071cc9 566 pcSerial.printf("%s\r\n", replybuffer);
marcpl 0:8230b1071cc9 567 } else {
marcpl 0:8230b1071cc9 568 pcSerial.printf("Fail code #%d\r\n", returncode);
marcpl 0:8230b1071cc9 569 }
marcpl 0:8230b1071cc9 570
marcpl 0:8230b1071cc9 571 break;
marcpl 0:8230b1071cc9 572 }
marcpl 0:8230b1071cc9 573 case 'w': {
marcpl 0:8230b1071cc9 574 // read website URL
marcpl 0:8230b1071cc9 575 uint16_t statuscode;
marcpl 0:8230b1071cc9 576 int16_t length;
marcpl 0:8230b1071cc9 577 char url[80];
marcpl 0:8230b1071cc9 578
marcpl 0:8230b1071cc9 579 flushSerial();
marcpl 0:8230b1071cc9 580 pcSerial.printf("NOTE: in beta! Use small webpages to read!\r\n");
marcpl 0:8230b1071cc9 581 pcSerial.printf("URL to read (e.g. www.adafruit.com/testwifi/index.html):\r\n");
marcpl 0:8230b1071cc9 582 pcSerial.printf("http://"); readline(url, 79);
marcpl 0:8230b1071cc9 583 pcSerial.printf("%s\r\n", url);
marcpl 0:8230b1071cc9 584
marcpl 0:8230b1071cc9 585 pcSerial.printf("****\r\n");
marcpl 0:8230b1071cc9 586 if (!fona.HTTP_GET_start(url, &statuscode, (uint16_t *)&length)) {
marcpl 0:8230b1071cc9 587 pcSerial.printf("Failed!\r\n");
marcpl 0:8230b1071cc9 588 break;
marcpl 0:8230b1071cc9 589 }
marcpl 0:8230b1071cc9 590 while (length > 0) {
marcpl 0:8230b1071cc9 591 while (fonaSerial.readable()) {
marcpl 0:8230b1071cc9 592 char c = fonaSerial.getc();
marcpl 0:8230b1071cc9 593 pcSerial.putc(c);
marcpl 0:8230b1071cc9 594 length--;
marcpl 0:8230b1071cc9 595 if (! length) break;
marcpl 0:8230b1071cc9 596 }
marcpl 0:8230b1071cc9 597 }
marcpl 0:8230b1071cc9 598 pcSerial.printf("\r\n****\r\n");
marcpl 0:8230b1071cc9 599 fona.HTTP_GET_end();
marcpl 0:8230b1071cc9 600 break;
marcpl 0:8230b1071cc9 601 }
marcpl 0:8230b1071cc9 602
marcpl 0:8230b1071cc9 603 case 'W': {
marcpl 0:8230b1071cc9 604 // Post data to website
marcpl 0:8230b1071cc9 605 uint16_t statuscode;
marcpl 0:8230b1071cc9 606 int16_t length;
marcpl 0:8230b1071cc9 607 char url[80];
marcpl 0:8230b1071cc9 608 char data[80];
marcpl 0:8230b1071cc9 609
marcpl 0:8230b1071cc9 610 flushSerial();
marcpl 0:8230b1071cc9 611 pcSerial.printf("NOTE: in beta! Use simple websites to post!\r\n");
marcpl 0:8230b1071cc9 612 pcSerial.printf("URL to post (e.g. httpbin.org/post):\r\n");
marcpl 0:8230b1071cc9 613 pcSerial.printf("http://"); readline(url, 79);
marcpl 0:8230b1071cc9 614 pcSerial.printf("%s\r\n", url);
marcpl 0:8230b1071cc9 615 pcSerial.printf("Data to post (e.g. \"foo\" or \"{\"simple\":\"json\"}\"):\r\n");
marcpl 0:8230b1071cc9 616 readline(data, 79);
marcpl 0:8230b1071cc9 617 pcSerial.printf("%s\r\n", data);
marcpl 0:8230b1071cc9 618
marcpl 0:8230b1071cc9 619 pcSerial.printf("****\r\n");
marcpl 0:8230b1071cc9 620 if (!fona.HTTP_POST_start(url, "text/plain", (uint8_t *) data, strlen(data), &statuscode, (uint16_t *)&length)) {
marcpl 0:8230b1071cc9 621 pcSerial.printf("Failed!\r\n");
marcpl 0:8230b1071cc9 622 break;
marcpl 0:8230b1071cc9 623 }
marcpl 0:8230b1071cc9 624 while (length > 0) {
marcpl 0:8230b1071cc9 625 while (fonaSerial.readable()) {
marcpl 0:8230b1071cc9 626 char c = fonaSerial.getc();
marcpl 0:8230b1071cc9 627 pcSerial.putc(c);
marcpl 0:8230b1071cc9 628 length--;
marcpl 0:8230b1071cc9 629 if (! length) break;
marcpl 0:8230b1071cc9 630 }
marcpl 0:8230b1071cc9 631 }
marcpl 0:8230b1071cc9 632 pcSerial.printf("\r\n****\r\n");
marcpl 0:8230b1071cc9 633 fona.HTTP_POST_end();
marcpl 0:8230b1071cc9 634 break;
marcpl 0:8230b1071cc9 635 }
marcpl 0:8230b1071cc9 636 /*****************************************/
marcpl 0:8230b1071cc9 637
marcpl 0:8230b1071cc9 638 case 'S': {
marcpl 0:8230b1071cc9 639 pcSerial.printf("Creating SERIAL TUBE\r\n");
marcpl 0:8230b1071cc9 640 while (1) {
marcpl 0:8230b1071cc9 641 while (pcSerial.readable()) {
marcpl 0:8230b1071cc9 642 wait_ms(1);
marcpl 0:8230b1071cc9 643 fonaSerial.putc(pcSerial.getc());
marcpl 0:8230b1071cc9 644 }
marcpl 0:8230b1071cc9 645 if (fonaSerial.readable()) {
marcpl 0:8230b1071cc9 646 pcSerial.putc(fonaSerial.getc());
marcpl 0:8230b1071cc9 647 }
marcpl 0:8230b1071cc9 648 }
marcpl 0:8230b1071cc9 649 }
marcpl 0:8230b1071cc9 650
marcpl 0:8230b1071cc9 651 default: {
marcpl 0:8230b1071cc9 652 pcSerial.printf("Unknown command\r\n");
marcpl 0:8230b1071cc9 653 printMenu();
marcpl 0:8230b1071cc9 654 break;
marcpl 0:8230b1071cc9 655 }
marcpl 0:8230b1071cc9 656 }
marcpl 0:8230b1071cc9 657 // flush input
marcpl 0:8230b1071cc9 658 flushSerial();
marcpl 0:8230b1071cc9 659 while (fonaSerial.readable()) {
marcpl 0:8230b1071cc9 660 pcSerial.putc(fonaSerial.getc());
marcpl 0:8230b1071cc9 661 }
marcpl 0:8230b1071cc9 662 }
marcpl 0:8230b1071cc9 663 }
marcpl 0:8230b1071cc9 664
marcpl 0:8230b1071cc9 665 void printMenu(void) {
marcpl 0:8230b1071cc9 666 pcSerial.printf("-------------------------------------\r\n");
marcpl 0:8230b1071cc9 667 pcSerial.printf("[?] Print this menu\r\n");
marcpl 0:8230b1071cc9 668 pcSerial.printf("[a] read the ADC (2.8V max)\r\n");
marcpl 0:8230b1071cc9 669 pcSerial.printf("[b] read the Battery V and %% charged\r\n");
marcpl 0:8230b1071cc9 670 pcSerial.printf("[C] read the SIM CCID\r\n");
marcpl 0:8230b1071cc9 671 pcSerial.printf("[U] Unlock SIM with PIN code\r\n");
marcpl 0:8230b1071cc9 672 pcSerial.printf("[i] read RSSI\r\n");
marcpl 0:8230b1071cc9 673 pcSerial.printf("[n] get Network status\r\n");
marcpl 0:8230b1071cc9 674 pcSerial.printf("[v] set audio Volume\r\n");
marcpl 0:8230b1071cc9 675 pcSerial.printf("[V] get Volume\r\n");
marcpl 0:8230b1071cc9 676 pcSerial.printf("[H] set Headphone audio\r\n");
marcpl 0:8230b1071cc9 677 pcSerial.printf("[e] set External audio\r\n");
marcpl 0:8230b1071cc9 678 pcSerial.printf("[T] play audio Tone\r\n");
marcpl 0:8230b1071cc9 679 pcSerial.printf("[P] PWM/Buzzer out\r\n");
marcpl 0:8230b1071cc9 680
marcpl 0:8230b1071cc9 681 // FM (SIM800 only)
marcpl 0:8230b1071cc9 682 pcSerial.printf("[f] tune FM radio\r\n");
marcpl 0:8230b1071cc9 683 pcSerial.printf("[F] turn off FM\r\n");
marcpl 0:8230b1071cc9 684 pcSerial.printf("[m] set FM volume\r\n");
marcpl 0:8230b1071cc9 685 pcSerial.printf("[M] get FM volume\r\n");
marcpl 0:8230b1071cc9 686 pcSerial.printf("[q] get FM station signal level\r\n");
marcpl 0:8230b1071cc9 687
marcpl 0:8230b1071cc9 688 // Phone
marcpl 0:8230b1071cc9 689 pcSerial.printf("[c] make phone Call\r\n");
marcpl 0:8230b1071cc9 690 pcSerial.printf("[h] Hang up phone\r\n");
marcpl 0:8230b1071cc9 691 pcSerial.printf("[p] Pick up phone\r\n");
marcpl 0:8230b1071cc9 692
marcpl 0:8230b1071cc9 693 // SMS
marcpl 0:8230b1071cc9 694 pcSerial.printf("[N] Number of SMSs\r\n");
marcpl 0:8230b1071cc9 695 pcSerial.printf("[r] Read SMS #\r\n");
marcpl 0:8230b1071cc9 696 pcSerial.printf("[R] Read All SMS\r\n");
marcpl 0:8230b1071cc9 697 pcSerial.printf("[d] Delete SMS #\r\n");
marcpl 0:8230b1071cc9 698 pcSerial.printf("[s] Send SMS\r\n");
marcpl 0:8230b1071cc9 699
marcpl 0:8230b1071cc9 700 // Time
marcpl 0:8230b1071cc9 701 pcSerial.printf("[y] Enable network time sync\r\n");
marcpl 0:8230b1071cc9 702 pcSerial.printf("[Y] Enable NTP time sync (GPRS)\r\n");
marcpl 0:8230b1071cc9 703 pcSerial.printf("[t] Get network time\r\n");
marcpl 0:8230b1071cc9 704
marcpl 0:8230b1071cc9 705 // GPRS
marcpl 0:8230b1071cc9 706 pcSerial.printf("[G] Enable GPRS\r\n");
marcpl 0:8230b1071cc9 707 pcSerial.printf("[g] Disable GPRS\r\n");
marcpl 0:8230b1071cc9 708 pcSerial.printf("[l] Query GSMLOC (GPRS)\r\n");
marcpl 0:8230b1071cc9 709 pcSerial.printf("[w] Read webpage (GPRS)\r\n");
marcpl 0:8230b1071cc9 710 pcSerial.printf("[W] Post to website (GPRS)\r\n");
marcpl 0:8230b1071cc9 711
marcpl 0:8230b1071cc9 712 // GPS
marcpl 0:8230b1071cc9 713 pcSerial.printf("[O] Turn GPS on (SIM808)\r\n");
marcpl 0:8230b1071cc9 714 pcSerial.printf("[o] Turn GPS off (SIM808)\r\n");
marcpl 0:8230b1071cc9 715 pcSerial.printf("[x] GPS fix status (SIM808)\r\n");
marcpl 0:8230b1071cc9 716 pcSerial.printf("[L] Query GPS location (SIM808)\r\n");
marcpl 0:8230b1071cc9 717 pcSerial.printf("[E] Raw NMEA out (SIM808)\r\n");
marcpl 0:8230b1071cc9 718
marcpl 0:8230b1071cc9 719 pcSerial.printf("[S] create Serial passthru tunnel\r\n");
marcpl 0:8230b1071cc9 720 pcSerial.printf("-------------------------------------\r\n");
marcpl 0:8230b1071cc9 721 pcSerial.printf("\r\n");
marcpl 0:8230b1071cc9 722 }
marcpl 0:8230b1071cc9 723
marcpl 0:8230b1071cc9 724 void flushSerial() {
marcpl 0:8230b1071cc9 725 while (pcSerial.readable())
marcpl 0:8230b1071cc9 726 pcSerial.getc();
marcpl 0:8230b1071cc9 727 }
marcpl 0:8230b1071cc9 728
marcpl 0:8230b1071cc9 729 char readBlocking() {
marcpl 0:8230b1071cc9 730 while (!pcSerial.readable());
marcpl 0:8230b1071cc9 731 return pcSerial.getc();
marcpl 0:8230b1071cc9 732 }
marcpl 0:8230b1071cc9 733
marcpl 0:8230b1071cc9 734 uint16_t readnumber() {
marcpl 0:8230b1071cc9 735 uint16_t x = 0;
marcpl 0:8230b1071cc9 736 char c;
marcpl 0:8230b1071cc9 737 while (! isdigit(c = readBlocking())) {
marcpl 0:8230b1071cc9 738 //pcSerial.putc(c);
marcpl 0:8230b1071cc9 739 }
marcpl 0:8230b1071cc9 740 pcSerial.putc(c);
marcpl 0:8230b1071cc9 741 x = c - '0';
marcpl 0:8230b1071cc9 742 while (isdigit(c = readBlocking())) {
marcpl 0:8230b1071cc9 743 pcSerial.putc(c);
marcpl 0:8230b1071cc9 744 x *= 10;
marcpl 0:8230b1071cc9 745 x += c - '0';
marcpl 0:8230b1071cc9 746 }
marcpl 0:8230b1071cc9 747 return x;
marcpl 0:8230b1071cc9 748 }
marcpl 0:8230b1071cc9 749
marcpl 0:8230b1071cc9 750 uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout) {
marcpl 0:8230b1071cc9 751 uint16_t buffidx = 0;
marcpl 0:8230b1071cc9 752 bool timeoutvalid = true;
marcpl 0:8230b1071cc9 753 if (timeout == 0) timeoutvalid = false;
marcpl 0:8230b1071cc9 754
marcpl 0:8230b1071cc9 755 while (true) {
marcpl 0:8230b1071cc9 756 if (buffidx > maxbuff) {
marcpl 0:8230b1071cc9 757 //pcSerial.printf("SPACE\r\n");
marcpl 0:8230b1071cc9 758 break;
marcpl 0:8230b1071cc9 759 }
marcpl 0:8230b1071cc9 760
marcpl 0:8230b1071cc9 761 while(pcSerial.readable()) {
marcpl 0:8230b1071cc9 762 char c = pcSerial.getc();
marcpl 0:8230b1071cc9 763
marcpl 0:8230b1071cc9 764 //pcSerial.printf("%02x#%c\r\n", c, c);
marcpl 0:8230b1071cc9 765
marcpl 0:8230b1071cc9 766 if (c == '\r') continue;
marcpl 0:8230b1071cc9 767 if (c == 0xA) {
marcpl 0:8230b1071cc9 768 if (buffidx == 0) // the first 0x0A is ignored
marcpl 0:8230b1071cc9 769 continue;
marcpl 0:8230b1071cc9 770
marcpl 0:8230b1071cc9 771 timeout = 0; // the second 0x0A is the end of the line
marcpl 0:8230b1071cc9 772 timeoutvalid = true;
marcpl 0:8230b1071cc9 773 break;
marcpl 0:8230b1071cc9 774 }
marcpl 0:8230b1071cc9 775 buff[buffidx] = c;
marcpl 0:8230b1071cc9 776 buffidx++;
marcpl 0:8230b1071cc9 777 }
marcpl 0:8230b1071cc9 778
marcpl 0:8230b1071cc9 779 if (timeoutvalid && timeout == 0) {
marcpl 0:8230b1071cc9 780 //pcSerial.printf("TIMEOUT\r\n");
marcpl 0:8230b1071cc9 781 break;
marcpl 0:8230b1071cc9 782 }
marcpl 0:8230b1071cc9 783 wait_ms(1);
marcpl 0:8230b1071cc9 784 }
marcpl 0:8230b1071cc9 785 buff[buffidx] = 0; // null term
marcpl 0:8230b1071cc9 786 return buffidx;
marcpl 0:8230b1071cc9 787 }
marcpl 0:8230b1071cc9 788
marcpl 0:8230b1071cc9 789 long map(long x, long in_min, long in_max, long out_min, long out_max)
marcpl 0:8230b1071cc9 790 {
marcpl 0:8230b1071cc9 791 return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
marcpl 0:8230b1071cc9 792 }