Im writing a program for an arduino to communicate with a sim808 GPS/GSM module using AT commands over a soft serial port. I can send commands and read the response in the serial monitor window but I need a way to be able to read in the response to a variable so that I can check the contents of the variable to run an “if” or “switch” function.
I need to check the response of the “GPSstatus” functions so that is it responds with AT message “+CGPSSTATUS: Location 3D Fix OK” then I can send a function to get the GPS location/co-ordinates.
Any help is greatly appreciated and would be happy to return the favour.
This is the code so far: (attached)
// Connect RX (data into SIM808) to Digital 11
// Connect TX (data out from SIM808) to Digital 10
#include <SoftwareSerial.h>
#include "Timer.h"
#include <string.h>
SoftwareSerial mySerial(10, 11); // RX, TX
const int buttonPin = 7;
Timer t;
void setup()
{
pinMode(buttonPin, INPUT);
Serial.begin(9600);
mySerial.begin(9600);
Serial.print("STARTING DEVICE");
digitalWrite(3,HIGH); //Pull high for 2 seconds to boot sim808 device
delay(2000);
digitalWrite(3,LOW);
delay(7000);
mySerial.write("AT+CGPSPWR=1\r"); //Turn on GPS
delay(800);
t.every(10000, CheckBattery); //Check battery every 10 seconds
delay(1000);
t.every(1000, GPSstatus); //Check GPS status every 10 seconds
}
void CheckBattery()
{
mySerial.print("AT+CBC\r"); //AT code for battery status
}
void GPSstatus()
{
mySerial.print("AT+CGPSSTATUS?");
}
void SendTextMessage()
{
mySerial.print("AT+CMGF=1\r");
delay(800);
mySerial.print("AT+CMGS=\"+61400223399\"\r"); //Number of recipient
delay(800);
mySerial.print("Testing."); //Text for message
mySerial.print("\r");
delay(800);
mySerial.println((char)26);
mySerial.println();
}
void ReadSerial()
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
{
while(Serial.available())
{
mySerial.write(Serial.read());
}
mySerial.println();
}
}
void loop() // run over and over
{
ReadSerial();
t.update();
}
sketch_sep03a.ino.ino (1.46 KB)