Go Down

Topic: Using compareto if the received message from GSM800Lis equal to specific value? (Read 449 times) previous topic - next topic

EElive

  I am trying to write a code that will compare if the incoming message from GSM is equal to a value, if so it response back. When I open the serial monitor even (still I did not send a message to the GSM) I see -1 -1 (infinite series of -1).

How to make GSM wait for a new live message and then after it checks the message it responds back.

Can someone help me with the code?

Code: [Select]

#include "Adafruit_FONA.h"

#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4

#include <SoftwareSerial.h>
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;

// Hardware serial is also possible!
//  HardwareSerial *fonaSerial = &Serial1;

Adafruit_FONA fona = Adafruit_FONA(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[15] = {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);
  }
 
  Serial.println("FONA Ready");
}

 
char fonaInBuffer[64];          //for notifications from the FONA

void loop() {
 
  String c="";

  if (fona.available())      //any data available from the FONA?
  {
fona.println(c="AT+CNMI=2,2,0,0,0");
while (c = fona.read()) {
      Serial.print(c);
    }
        Serial.println("\nEND OF MESSAGE");
       
 if(c.compareTo("A") == 0)
        {
         fona.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  fona.println("AT+CMGS=\"+xx\"\r"); // Replace x with mobile number
  delay(1000);
  fona.print("The Hear Rate is: ");
  fona.print(50);
  fona.print(" BPM ");
  fona.print("\r"); //the content of the message
  delay(500);
  fona.print((char)26);//the ASCII code of the ctrl+z is 26 (required according to the datasheet)
  delay(1000); ;
        }
    fona.flush();
    Serial.println("MESSAGE DELETED");
 
      }
}
   
 

   
 

Go Up