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:
Mon Jun 29 20:48:35 2015 +0000
Revision:
3:4f4c3b4a35b3
Parent:
2:6cdaadf03837
Minor change

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