I have a problem with my project and I hope you can help
The code doesn't work and I don't understand why #include <SoftwareSerial.h>
SoftwareSerial sim808(11,10);
char phone_no[] = "053366****"; // replace with your phone no.
String data[5]; #define DEBUG true
String state,timegps,latitude,longitude;
void setup() {
sim808.begin(9600);
Serial.begin(9600);
delay(50); //sim808.print("AT+CSMP=17,167,0,0"); // set this parameter if empty SMS received
//delay(100);
sim808.print("AT+CMGF=1\r");
delay(400);
sendData("AT+CGNSPWR=1",1000,DEBUG);
delay(50);
sendData("AT+CGNSSEQ=RMC",1000,DEBUG);
delay(150);
}
void loop()
{
sendTabData("AT+CGNSINF",1000,DEBUG);
if (state !=0) {
Serial.println("State :"+state);
Serial.println("Time :"+timegps);
Serial.println("Latitude :"+latitude);
Serial.println("Longitude :"+longitude);
sim808.print("AT+CMGS="");
sim808.print(phone_no);
sim808.println(""");
delay(300);
sim808.print("Google Maps");
sim808.print(latitude);
sim808.print(",");
sim808.print (longitude);
delay(200);
sim808.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(200);
sim808.println();
delay(20000);
sim808.flush();
} else {
Serial.println("GPS Initializing…");
}
}
void sendTabData(String command , const int timeout , boolean debug){
sim808.println(command);
long int time = millis();
int i = 0;
while((time+timeout) > millis()){
while(sim808.available()){
char c = sim808.read();
if (c != ',') {
data[i] +=c;delay(100);
} else {
i++;
}
if (i == 5) {
delay(100);
goto exitL;
}
}
}exitL:
if (debug) {
state = data[1];
timegps = data[2];
latitude = data[3];
longitude =data[4];
}
}
String sendData (String command , const int timeout ,boolean debug){
String response = "";
sim808.println(command);
long int time = millis();
int i = 0;
while ( (time+timeout ) > millis()){
while (sim808.available()){
char c = sim808.read();
response +=c;
}
}
if (debug)
{Serial.print(response);}
return response;
}
I moved your topic to an appropriate forum category @farouksho.
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
try this simple send/receive character test using AltSoftSerial which works OK with SIM800 and SIM900
// UNO SIM800l AltSoftSerial basic AT commands test
#include <AltSoftSerial.h>
// UNO SIM800l connection for basic AT command test
// use external power supply for transmit/receive communications
//SIM800L 5V POWER to UNO 5V
//SIM800L GND POWER to UNO GND
//SIM800L VDD to UNO 5V
//SIM800L TXD to UNO RX pin 8
//SIM800L RXD to UNO TX pin 9
//SIM800L UART TTL GND and RST not connected
// Mega SIM800 test - note preferable to use a hardware serial port
//SIM800L TXD to Mega RX pin 48
//SIM800L RXD to Mega TX pin 46
// taking the RST pin to GND for a couple of seconds which will reset the device
// RS232 shield
// RS232 TXD to UNO pin 9
// RS232 RXD to UNO pin 8
// basic AT commands
// AT returns OK
// AT+CGMI returns the manufacturer's name
// AT+CGMM returns the MODEM model number
// AT+CGMR returns details of the software and model revision level
// AT+CGSN returns the MODEM's serial number
AltSoftSerial simSerial;
void setup() {
Serial.begin(115200);
Serial.println("AltSoftSerial test");
//Begin serial communication with Arduino and SIM800L
simSerial.begin(9600); // set to default baudrate
Serial.println("SIM module intialized");
}
void loop() {
if (Serial.available()) {
char command = Serial.read();
//Serial.println(command);
simSerial.print(command);
}
while (simSerial.available()) {
char reponse = simSerial.read();
Serial.print(reponse);
}
}
connected to a UNO the SIM800 response to AT commands
AT
OK
AT+CGMI
SIMCOM_Ltd
OK
AT+CGMM
SIMCOM_SIM800L