1

I want to send HTTP post requests to a server in JSON Format using a SIM900 module. But the code is not posting the data and have an error.Can someone help me to solved the error 1,603,0 since I cannot solve , I already try to use http instead of https cause I read from other QnA channel that AT+HTTPPARA="URL can only be read in http .. But nothing happen the error still there. I know the error is about the DNS but I do not know how to solve it.. Sorry it was my first time to use the sim900a

Here is my code:

#include <SoftwareSerial.h>
#include <ArduinoJson.h>

SoftwareSerial SIM900(10, 11);
StaticJsonBuffer<200> jsonBuffer; 


char t[32];
char deviceID[12] = "TESTING";
char Name[12] = "Irsyad";
char Place[12] = "JB";

 
void setup()
{
  SIM900.begin(9600);       // the GPRS baud rate
  Serial.begin(9600);
  Serial.println("Initializing..");
  
  DynamicJsonBuffer jsonBuffer;

}
 
void loop()
{
  Serial.println("");
  Serial.println("START");

  Serial.print("Device ID: ");
  Serial.println(deviceID);

  delay(1000);
 
  if (SIM900.available())
  Serial.write(SIM900.read());
 
  SIM900.println("AT");
  delay(3000);
 
  SIM900.println("AT+SAPBR=3,1,\"Contype\",\"GPRS\""); // untuk cek  GPRS 
  delay(6000);
  ShowSerialData();
 
  SIM900.println("AT+SAPBR=3,1,\"APN\",\"\"");//APN mobile phone (cek dekat phone)
  delay(6000);
  ShowSerialData();
 
  SIM900.println("AT+SAPBR=1,1"); 
  delay(6000);
  ShowSerialData();
 
  SIM900.println("AT+SAPBR=2,1");
  delay(6000);
  ShowSerialData();
 
  SIM900.println("AT+HTTPINIT"); // jika keluar error means gagal
  delay(6000);
  ShowSerialData();
 
  SIM900.println("AT+HTTPPARA=\"CID\",1"); //parameters untuk HTTP session
  delay(6000);
  ShowSerialData();
 
  StaticJsonBuffer<200> jsonBuffer; 
  JsonObject& object = jsonBuffer.createObject();  
  
  object.set("deviceID",deviceID);
  object.set("Name",Name);
  object.set("Place",Place);

  object.printTo(Serial);
  Serial.println(" ");  
  String sendtoserver;
  object.prettyPrintTo(sendtoserver);
  delay(4000);


  SIM900.println("AT+HTTPPARA=\"URL\",\"http://gas-api.smartcp.app/api/ttn/uplink\""); //Server address // tukar pakai lain https://
  delay(4000);
  ShowSerialData();
 
  SIM900.println("AT+HTTPPARA=\"CONTENT\",\"application/json\""); //json format
  delay(4000);
  ShowSerialData();


  
  SIM900.println("AT+HTTPDATA=" + String(sendtoserver.length()) + ",100000"); // size bytes untuk hantar data dalam masa 10 seconds
  Serial.println(sendtoserver);
  delay(6000);
  ShowSerialData();
 
  SIM900.println(sendtoserver);
  delay(6000);
  ShowSerialData;
 
  SIM900.println("AT+HTTPACTION=1"); // Post the data (1 means post)
  delay(6000);
  ShowSerialData();
 
  SIM900.println("AT+HTTPREAD"); 
  delay(6000);
  ShowSerialData();
 
  SIM900.println("AT+HTTPTERM");
  delay(10000);
  ShowSerialData;
}
 
void ShowSerialData()
{
  while (SIM900.available() != 0)
    Serial.write(SIM900.read());
  delay(1000);
 
}

enter image description here

2
  • 1
    please do not post a picture of text ... remove the picture and add the actual text
    – jsotola
    Apr 20 at 5:00
  • Just looking at the code, my guess is that all those 6 second delays cause a timeout error somewhere. PS +SAPBR: 1,1,"10.143.42.168" I'm unfamiliar with AT-codes, but that 10.143.42.168 looks like an IP address, and that IP address is in the private range. Maybe it's just Carrier-grade NAT, and not related to your problem.
    – Gerben
    Apr 20 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.