I'm new to this forum so i hope i'm posting in the right place...
I curently have a problem with a test programm in order to get the position from the AT+CLBS command. (triangulation of the position).
The issue is when the substring is getting the data from the sim800l serial. The first time when i upload the code that's work and then on the second loop the variable Longitude and Latitude are empty.. i think that have something to do with the two serials but i'm not shure why..
thank for your help!
- //Librairies
- #include <SoftwareSerial.h>
- #include <String.h>
- #define AT_DELAY 3000 // Commmand AT Delay
- #define MODEM_RST 5
- #define MODEM_PWKEY 4
- #define MODEM_POWER_ON 23
- SoftwareSerial sim800l(26, 27);// RX, TX
- String Message, tampon;
- String Latitude, Longitude, Time;
- //AT Commands
- String AT_COMMAND[8] = {"AT+CGATT =1", "AT+SAPBR =3,1,\"CONTYPE\",\"GPRS\"", "AT+SAPBR =3,1,\"APN\",\"free\"",
- "AT+SAPBR =3,1,\"USER\",\"free\"", "AT+SAPBR =3,1,\"PWD\",\"free\"",
- "AT+SAPBR=1,1", "AT+SAPBR=2,1", "AT+CLBS=1,1"
- };
- void setup() {
- pinMode(MODEM_PWKEY, OUTPUT);
- pinMode(MODEM_RST, OUTPUT);
- pinMode(MODEM_POWER_ON, OUTPUT);
- digitalWrite(MODEM_PWKEY, LOW);
- digitalWrite(MODEM_RST, HIGH);
- digitalWrite(MODEM_POWER_ON, HIGH);
- sim800l.begin(9600);// modem start
- Serial.begin(9600);// Init serial
- Serial.println("start ...");
- }
- void loop() {
- delay(2000);
- for (int k = 0; k < 9; k++)
- {
- sim800l.println(AT_COMMAND[k]);// AT commands loop
- delay(650);//response delay
- Message = sim800l.readString();//read sim800l
- Serial.println(Message);// print response in main serial
- if (k == 8)
- {
- Serial.println("##############################################################");
- Serial.print("Latitude: ");
- Latitude = Message.substring(Message.indexOf("0,"), Message.indexOf("0,") + 9);
- Serial.println(Latitude);
- Longitude = Message.substring(Message.indexOf(':') + 4, Message.indexOf(',') + 9);
- Serial.print("Longitude: ");
- Serial.println(Longitude);
- Serial.println("##############################################################");
- while(sim800l.available()){
- sim800l.print("");
- }
- }
- }
- sim800l.println( "AT+SAPBR =0,1");
- }