ESP32 SIM800L Issue

heyone
Posts: 1
Joined: Mon Jan 25, 2021 7:31 pm

ESP32 SIM800L Issue

Postby heyone » Mon Jan 25, 2021 8:10 pm

Hello,

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!
  1. //Librairies
  2. #include <SoftwareSerial.h>
  3. #include <String.h>
  4. #define AT_DELAY  3000    // Commmand AT Delay
  5. #define MODEM_RST            5
  6. #define MODEM_PWKEY          4
  7. #define MODEM_POWER_ON       23
  8.  
  9.  
  10. SoftwareSerial sim800l(26, 27);// RX, TX
  11.  
  12. String Message, tampon;
  13. String Latitude, Longitude, Time;
  14. //AT Commands  
  15. String AT_COMMAND[8] = {"AT+CGATT =1", "AT+SAPBR =3,1,\"CONTYPE\",\"GPRS\"", "AT+SAPBR =3,1,\"APN\",\"free\"",
  16.                         "AT+SAPBR =3,1,\"USER\",\"free\"", "AT+SAPBR =3,1,\"PWD\",\"free\"",
  17.                         "AT+SAPBR=1,1", "AT+SAPBR=2,1", "AT+CLBS=1,1"
  18.                        };
  19. void setup() {
  20.   pinMode(MODEM_PWKEY, OUTPUT);
  21.   pinMode(MODEM_RST, OUTPUT);
  22.   pinMode(MODEM_POWER_ON, OUTPUT);
  23.   digitalWrite(MODEM_PWKEY, LOW);
  24.   digitalWrite(MODEM_RST, HIGH);
  25.   digitalWrite(MODEM_POWER_ON, HIGH);
  26.   sim800l.begin(9600);// modem start
  27.   Serial.begin(9600);// Init serial
  28.   Serial.println("start ...");
  29. }
  30.  
  31. void loop() {
  32.   delay(2000);
  33.   for (int k = 0; k < 9; k++)
  34.   {
  35.     sim800l.println(AT_COMMAND[k]);// AT commands loop
  36.     delay(650);//response delay
  37.     Message = sim800l.readString();//read sim800l
  38.     Serial.println(Message);// print response in main serial
  39.     if (k == 8)
  40.     {
  41.      
  42.       Serial.println("##############################################################");
  43.       Serial.print("Latitude: ");
  44.       Latitude = Message.substring(Message.indexOf("0,"), Message.indexOf("0,") + 9);
  45.       Serial.println(Latitude);
  46.      
  47.       Longitude = Message.substring(Message.indexOf(':') + 4, Message.indexOf(',') + 9);
  48.       Serial.print("Longitude: ");
  49.       Serial.println(Longitude);
  50.      
  51.       Serial.println("##############################################################");
  52.       while(sim800l.available()){
  53.         sim800l.print("");
  54.       }
  55.     }
  56.   }
  57.   sim800l.println( "AT+SAPBR =0,1");
  58. }
Image
Image

Who is online

Users browsing this forum: No registered users and 126 guests