Problem to read the http get response with GSM A7670

Naznee

Newbie level 6
Joined
Mar 21, 2024
Messages
13
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
90
this is my code

C:
#include <HardwareSerial.h>
#if defined(CONFIG_IDF_TARGET_ESP32)
    #define mySerial Serial2
#elif defined(CONFIG_IDF_TARGET_ESP32S2)
    #define mySerial Serial1
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
   #define mySerial Serial2
#endif
String msg="";

void setup()
{
  Serial.begin(115200);
  delay(500);
 
  #if defined(CONFIG_IDF_TARGET_ESP32)
    mySerial.begin(115200);
 #elif defined(CONFIG_IDF_TARGET_ESP32S2)
    mySerial.begin(115200);
 #elif defined(CONFIG_IDF_TARGET_ESP32S3)
   mySerial.begin(115200, SERIAL_8N1, 18, 17);
 #endif
 mySerial.println("AT+CICCID");delay(500);
  update_serial();
  mySerial.println("AT+CREG?");delay(500);
  update_serial();
  mySerial.println("AT+CGATT=1");delay(500);
  update_serial();
  mySerial.println("AT+CGACT?");delay(500);
  update_serial();
  mySerial.println("AT+CGDCONT=1,\"IP\",\"jionet\"");delay(500);
  update_serial();

 mySerial.println("AT+HTTPINIT\r\n");delay(500);
  update_serial();
 mySerial.println("AT+HTTPPARA=\"URL\",\"http://api.timezonedb.com/v2.1/get-time-zone?key=KXXXXXXXXX&format=json&by=zone&zone=Asia/Kolkata\"");
delay(500);
  update_serial();
   mySerial.println("AT+HTTPACTION=0\r\n");delay(2000);
  update_serial();
  mySerial.println("AT+HTTPREAD?");delay(2000);
  update_serial();
  mySerial.println("AT+HTTPTERM\r\n");delay(2000);
  update_serial();

}
void loop()
{
 update_serial();
}

 void update_serial()
{
    if (mySerial.available()) {
     
       msg = mySerial.readStringUntil('\n');
      Serial.println(msg);
       
    }
}

and this is an output

when I add the line to add the response or data

C:
#include <HardwareSerial.h>
#if defined(CONFIG_IDF_TARGET_ESP32)
    #define mySerial Serial2
#elif defined(CONFIG_IDF_TARGET_ESP32S2)
    #define mySerial Serial1
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
   #define mySerial Serial2
#endif
String msg="";

void setup()
{
  Serial.begin(115200);
  delay(500);
 
  #if defined(CONFIG_IDF_TARGET_ESP32)
    mySerial.begin(115200);
 #elif defined(CONFIG_IDF_TARGET_ESP32S2)
    mySerial.begin(115200);
 #elif defined(CONFIG_IDF_TARGET_ESP32S3)
   mySerial.begin(115200, SERIAL_8N1, 18, 17);
 #endif
 mySerial.println("AT+CICCID");delay(500);
  update_serial();
  mySerial.println("AT+CREG?");delay(500);
  update_serial();
  mySerial.println("AT+CGATT=1");delay(500);
  update_serial();
  mySerial.println("AT+CGACT?");delay(500);
  update_serial();
  mySerial.println("AT+CGDCONT=1,\"IP\",\"jionet\"");delay(500);
  update_serial();

 mySerial.println("AT+HTTPINIT\r\n");delay(500);
  update_serial();
 mySerial.println("AT+HTTPPARA=\"URL\",\"http://api.timezonedb.com/v2.1/get-time-zone?key=KXXXXXXXXXX&format=json&by=zone&zone=Asia/Kolkata\"");
delay(500);
  update_serial();
   mySerial.println("AT+HTTPACTION=0\r\n");delay(2000);
  update_serial();
 
  mySerial.println("AT+HTTPREAD=0,385");delay(2000);
  update_serial();
  mySerial.println("AT+HTTPTERM\r\n");delay(2000);
  update_serial();
}
void loop()
{
 update_serial();
}

 void update_serial()
{
    if (mySerial.available()) {
     
       msg = mySerial.readStringUntil('\n');
      Serial.println(msg);
       
    }
}

this is the ouput


please help me to read the payload from the server
 
Last edited by a moderator:

Hi,

in "update_serial"
Code:
void update_serial()
{
    if (mySerial.available()) {
     
       msg = mySerial.readStringUntil('\n');
      Serial.println(msg);
       
    }
You only read until "\n".
What if there is additional text?

My ideas:
* Why (all at once) not read the whole content of the UART buffer?
* or (line-by-line) why not use a "WHILE" loop to read all available lines (multiple " \n")?

Klaus
 

this is the ouput after whole data read upto my serial is available

 
Last edited by a moderator:

now I get the response
thank you for responses
.
.
.
.
can you please tell me how to get the time from NTP server with GSM module
i read the AT commands from manual and try to do it but can't set the time.
Test Command
AT+CNTP=? response +CNTP:255,(-96~96)
OK
Read Command
AT+CNTP? Response +CNTP:,
OK
Write Command
AT+CNTP=””[,] Response OK or ERROR
Execution Command
AT+CNTP Response +CNTP:,
OK or ERROR

i tried with many server but can't get the time
 

now i get the time from ntp there is a buffer overflow issue
 

there is a buffer overflow issue
impossible for us to see ... with the snippet of post#6

Additionally: On buffer overflow you usually get incomplete messages. You gave no information how your modem response looked like.

****

If you want fast and good feedback .. next time better post complete code and complete error description.
It saves yourself from a week long delay.

Klaus
 

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…