CONTENT
- What is FONA
- What is this tutorial for
- Receive a SMS message and auto-reply it
- The output
- The parts list
- The parts list
- Recommendation of accessories
- The circuitry
- The code
- FONA-response (full commented)
WHAT IS FONA
In this tutorial, you will use GPS (FONA 808) to receive a short message service(known as SMS) message and auto-reply anything you want! The Adafruit FONA 808 MiniGSM + GPS is an all-in-one cellular phone module. It lets you add location-tracking, voice, text, SMS and data to your project in an adorable little package. It looks like this:
(The front)
(The back)
To receive and auto-reply a SMS message, you will make use of the following features of GPS (FONA 808). Related parameters are shown for reference:
Feature | Related parameter |
· It can connect onto any global GSM network with any 2G SIM in the USA | Quad-band 850/900/1800/1900MHz |
· Send and receive SMS messages | |
· AT command interface with “auto baud” detection |
WHAT IS THIS TUTORIAL FOR
The following tutorial will be useful when you want to set an auto-reply message to any SMS text you receive. If you want to know more about the GPS working part, please refer to Deon Provost’s post.
The result is shown below:
(267)244-5600 is the number coming from the SIM card. You can only use SMS commands on FONA with a SIM card.
“hi” is sent by a mobile phone user, it can be anything. “Hey, I got your text!” is the automatically reply message you can set under codes.
THE PARTS LIST
The parts list goes like this:
PARTS | How it works |
An Arduino Uno | · act as a microcontroller |
A GPS(FONA 808) | · receive, transmit and reset data under codes in Arduino |
A LiPoly/Lilon battery | · power the FONA |
A MicroUSB connector | · charge the Lipoly/Lilon battery |
An external uFL GSM Antenna | · receive and send SMS |
A passive GPS Antenna uFL | · is required to use the SMS commands |
A 2G Mini SIM card | · record data from the cellular network |
Here are recommendations of accessories on Adafruit other than Arduino and GPS(FONA 808):
It fits in FONA like this:
The final set looks like these:
(The front)
(The back)
THE CIRCUITRY
To use the code controlling the FONA, you need to follow the pins’ list:
RX (Receiving) | 2 |
TX (Transmitting) | 3 |
Rst (Resetting) | 4 |
In this tutorial, you are going to power the FONA with wires to Arduino. You should link pins of 5V and GND of both FONA and Arduino on the breadboard. In addition, on FONA and the breadboard, you should link Vio to the positive, and Key to the negative. The final circuit goes like this:
(Correction: It should be 1200mAh on the battery, and the antennas should be different from each other. Due to software limitation, the parts are for reference only.)
Here is what you should have finally:
THE CODE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
#include "Adafruit_FONA.h" #define FONA_RX 2 #define FONA_TX 3 #define FONA_RST 4 // this is a <!--more--> large buffer for replies char replybuffer[255]; // We default to using software serial. If you want to use hardware serial // (because softserial isnt supported) comment out the following three lines // and uncomment the HardwareSerial line #include <SoftwareSerial.h> SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX); SoftwareSerial *fonaSerial = &fonaSS; // Hardware serial is also possible! // HardwareSerial *fonaSerial = &Serial1; // Use this for FONA 800 and 808s Adafruit_FONA fona = Adafruit_FONA(FONA_RST); // Use this one for FONA 3G //Adafruit_FONA_3G fona = Adafruit_FONA_3G(FONA_RST); uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0); void setup() { while (!Serial); Serial.begin(115200); Serial.println(F("FONA SMS caller ID test")); Serial.println(F("Initializing....(May take 3 seconds)")); // make it slow so its easy to read! fonaSerial->begin(4800); if (! fona.begin(*fonaSerial)) { Serial.println(F("Couldn't find FONA")); while(1); } Serial.println(F("FONA is OK")); // Print SIM card IMEI number. char imei[16] = {0}; // MUST use a 16 character buffer for IMEI! uint8_t imeiLen = fona.getIMEI(imei); if (imeiLen > 0) { Serial.print("SIM card IMEI: "); Serial.println(imei); } fonaSerial->print("AT+CNMI=2,1\r\n"); //set up the FONA to send a +CMTI notification when an SMS is received Serial.println("FONA Ready"); } char fonaNotificationBuffer[64]; //for notifications from the FONA char smsBuffer[250]; void loop() { char* bufPtr = fonaNotificationBuffer; //handy buffer pointer if (fona.available()) //any data available from the FONA? { int slot = 0; //this will be the slot number of the SMS int charCount = 0; //Read the notification into fonaInBuffer do { *bufPtr = fona.read(); Serial.write(*bufPtr); delay(1); } while ((*bufPtr++ != '\n') && (fona.available()) && (++charCount < (sizeof(fonaNotificationBuffer)-1))); //Add a terminal NULL to the notification string *bufPtr = 0; //Scan the notification string for an SMS received notification. // If it's an SMS message, we'll get the slot number in 'slot' if (1 == sscanf(fonaNotificationBuffer, "+CMTI: " FONA_PREF_SMS_STORAGE ",%d", &slot)) { Serial.print("slot: "); Serial.println(slot); char callerIDbuffer[32]; //we'll store the SMS sender number in here // Retrieve SMS sender address/phone number. if (! fona.getSMSSender(slot, callerIDbuffer, 31)) { Serial.println("Didn't find SMS message in slot!"); } Serial.print(F("FROM: ")); Serial.println(callerIDbuffer); // Retrieve SMS value. uint16_t smslen; if (fona.readSMS(slot, smsBuffer, 250, &smslen)) { // pass in buffer and max len! Serial.println(smsBuffer); } //Send back an automatic response Serial.println("Sending reponse..."); if (!fona.sendSMS(callerIDbuffer, "Hey, I got your text!")) { Serial.println(F("Failed")); } else { Serial.println(F("Sent!")); } // delete the original msg after it is processed // otherwise, we will fill up all the slots // and then we won't be able to receive SMS anymore if (fona.deleteSMS(slot)) { Serial.println(F("OK!")); } else { Serial.print(F("Couldn't delete SMS in slot ")); Serial.println(slot); fona.print(F("AT+CMGD=?\r\n")); } } } } |
3 replies on “RECEIVE AND AUTO-REPLY A SMS ON GPS(FONA 808)”
Hi, thanks for the post. I am working on a project that requires an auto reply feature. However, I have FONA 3G instead of 800 or 808. Do I just comment out line 23 and uncomment line 25? Unfortunately this method does not really work.
I live in Australia and I’m pretty sure my FONA works as I am able to send SMS’s and make phone calls. However, I cannot read any incoming messages.
legislation that could move in the coming year have maintained their seats, fe acc18 ru and lawmakers from both parties seemed confident
Good post!
I am using FONA to receive SMS and send the message to another microcontroller through serial interface, but there is a lot of text associated with the original message, How do I clean the message such that only the desired text get sent? I don’t want all those AT commands.