AT Commands HTTP request to JSON source with status 200 but response that I get is incomplete (just some part of Response I received)

30 views Asked by At

AT Commands HTTP request to JSON source with status 200 but response that I get is incomplete (just some part of Response I received).

#include <SoftwareSerial.h>

#define RX_PIN 2
#define TX_PIN 3

SoftwareSerial gsmSerial(RX_PIN, TX_PIN);

void setup() {
  Serial.begin(9600);
  gsmSerial.begin(9600);
  configureAPN();
  Serial.println("Start Actual Communication:---->");

  // Additional setup code for your SIM800L module, if required
  // Ensure that the SIM800L module is configured and connected to the network
}

void loop() {
  // Make HTTP GET request to the specified API endpoint

  another_function("https://just_normal_server.com/user/heartbeat");

  // Adjust the delay based on your application requirements
  delay(2000);
}



void another_function(String url) {
  // Buffer to store the HTTP response data
  char buffer[512];
  int index = 0;

  // Helper function to read and append data to the buffer
  auto readAndAppendToBuffer = [&buffer, &index](int timeout) {
    long startTime = millis();
    while (millis() - startTime < timeout && gsmSerial.available()) {
      char c = gsmSerial.read();
      buffer[index++] = c;
      // Add additional conditions for handling specific characters or patterns if needed
    }
  };

  gsmSerial.println("AT+HTTPINIT");
  delay(1000);
  Serial.println("HTTP INITIALIZATION: " + get_data());

  gsmSerial.println("AT+HTTPPARA=\"CID\",1");
  delay(1000);
  Serial.println("CID PARA: " + get_data());

  gsmSerial.println("AT+HTTPPARA=\"URL\",\"" + url + "\"");
  delay(2000);
  Serial.println("URL Called: " + get_data());

  gsmSerial.println("\"CONTENT\",\"application/json\"");
  delay(2000);
  Serial.println("JSON PARA: " + get_data());

  gsmSerial.println("AT+HTTPPARA=\"REDIR\",1");
  delay(1000);
  Serial.println("REDIR PARA: " + get_data());

  gsmSerial.println("AT+HTTPSSL=1");
  delay(10000);
  Serial.println("SSL PARA: " + get_data());

  gsmSerial.println("AT+HTTPACTION=0");
  delay(10000);
  Serial.println("HTTP ACTION: " + get_data());

  gsmSerial.println("AT+HTTPREAD");
  delay(10000);
  Serial.println("HTTP Read DATA: " + get_data());
  /*
  readAndAppendToBuffer(30000);  // Adjust the timeout based on your server's response time

  // Null-terminate the buffer
  buffer[index] = '\0';

  // Print the entire response data
  Serial.println(buffer);
  */

  gsmSerial.println("AT+HTTPTERM");
  delay(1000);
  Serial.println("HTTP Termination: " + get_data());
}


String get_data() {
  String response = "";  // Initialize an empty string

  while (gsmSerial.available() > 0) {
    char character = gsmSerial.read();
    response += character;  // Append the character to the string
  }

  return response;
}


void configureAPN() {
  gsmSerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"\r");
  delay(1000);
  Serial.println("APN-1: " + get_data());
  gsmSerial.println("AT+SAPBR=3,1,\"APN\",\"airtelgprs.com\"\r");
  delay(1000);
  Serial.println("APN-2: " + get_data());
  gsmSerial.println("AT+SAPBR=1,1\r");
  delay(1000);
  Serial.println("APN-3: " + get_data());
}

This is my program, and I using Arduino UNO with SIM800L Module....

Got the response like:

HTTP ACTION: AT+HTTPACTION=0

OK

+HTTPACTION: 0,200,57

HTTP Read DATA: AT+HTTPREAD

+HTTPREAD: 57
{"status":"alive","timestamp":"202
HTTP Termination: AT+HTTPTERM

OK

I want the full response from that API. I test this API on Postman. On that response was correctly received, but in Arduino terminal, I am unable to get.

0

There are 0 answers