Arduino AT commads GSM HTTP send data to server error using arduino

I'm using Arduino uno to send AT commands to HTTP server using SIMCOM gsm module when i send string to the HTTP server using USB to TTL then i will able to successfully send string but when i do use Arduino uno then i will able to perform all commands but only problem is i'm unable to successfully send string to the server.

Show your code - use the <CODE/> button to post it

What debugging have you done so far?

It's not clear whether your problem is with sending the AT commands to the GSM module, or with sending the HTTP requests through the GSM module - or both?

#include <SoftwareSerial.h>

SoftwareSerial gsmSerial(2, 3); 

int8_t sendATcommand(const char* ATcommand, const char* expected_answer, unsigned long timeout)
{
  uint8_t x = 0, answer = 1;
  char response[100];
  unsigned long previous = millis();

  memset(response, '\0', sizeof(response));

  while (gsmSerial.available() > 0)
    gsmSerial.read(); 

  gsmSerial.println(ATcommand); 

  x = 0;
  
  do
  {
  
    if (gsmSerial.available() != 0)
    {
      response[x] = gsmSerial.read();
      Serial.print(response[x]);
      x++;
   
      if (strstr(response, expected_answer) != NULL)
      {
        answer = 0;
      }
    }
    
    if ((millis() - previous) >= timeout)
    {
      break;
    }
  } while (answer == 1);

  return answer;
}

void setup()
{
  Serial.begin(115200);
  gsmSerial.begin(115200);
 
}

void loop()
{
  while (sendATcommand("AT", "OK" , 1000));
  delay(1000);
  while (sendATcommand("AT+CPIN?", "OK" , 1000));
  delay(1000);
  while (sendATcommand("AT+CSQ", "OK" ,1000));
  delay(1000);
  // while (sendATcommand("AT+CREG?", "OK") == 0);
  // while (sendATcommand("AT+CGREG?", "OK") == 0);
  // while (sendATcommand("AT+CPSI?", "OK") == 0);
  // while (sendATcommand("AT+CGDCONT?", "OK") == 0);
  // while (sendATcommand("AT+CGACT=0,1", "OK") == 0);
  // while (sendATcommand("AT+CGPADDR", "OK") == 0);

  // Initialize HTTP
   sendATcommand("AT+HTTPTERM", "OK",1000);
   sendATcommand("AT+HTTPINIT", "OK",100);
  delay(1000);
  //sir usko terminate karna padta hai AT+HTTPTERM se fir uske bad woh initialize hoga
  //oky

  while (sendATcommand("AT+HTTPPARA=\"URL\",\"http://43.204.234.166:8000/v1/telemetry/ongc/data/write\"", "OK",1000));
  delay(1000);
  
  while (sendATcommand("AT+HTTPPARA=\"CONTENT\",\"application/json\"", "OK",1000));
  delay(1000);
  

  while (sendATcommand("AT+HTTPPARA=\"ACCEPT\",\"*/*\"", "OK",1000));
  delay(1000);
  
  // Send JSON data
  while (sendATcommand("AT+HTTPDATA=154,2000", "OK" , 1000));

  
  gsmSerial.println("{\"id\":{\"sr_id\":\"SR03\",\"ip\":\"12\"},\"dps\":[{\"ts\":\"2023-07-12T11:11:00.000Z\",\"data\":{\"P1\":15,\"P2\":15,\"P4\":15,\"P5\":15,\"P6\":15}}]}");
  // Wait for response
  while (sendATcommand("AT+HTTPACTION=1", "OK" , 300));
  delay(30000);
  sendATcommand("AT+HTTPHEAD", "OK" , 3000);
  delay(1000);
  while (sendATcommand("AT+HTTPREAD=0,180", "OK",1000));

  while(1);
}
// time and date aaj ka karek k e request dalo na me server per check karta hu change time too T again


This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.