Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Question Protected by CommunityBot
Bumped by Community user
Bumped by Community user
Bumped by Community user
deleted 155 characters in body; edited title
Source Link
dda
  • 1.6k
  • 1
  • 12
  • 18

HTTP post request in JSON Format using SIM-900SIM900 module

I tried to send HTTP post requestrequests to a server in JSON Format using SIM-900a SIM900 module.. But the code is not posting the data. While posting the data I'm getting the error response while initializing the server using the command:

I don't know what'swhat the error is and how to fix thisit. Please help me to fix this.

#include<SoftwareSerial.h>

SoftwareSerial client(2,3);

String testReading="{  \"testID\" : 1,  \"testLevel\" : 1, }";

void setup()
  {
  Serial.begin(9600);  
  client.begin(9600);
  delay(1000);
  if(client.available())
  {
    Serial.print("Connected");
  } 
  else
  {
    Serial.print("Not Connected");
  }
   checkSignal(); 
   connectGPRS();
   postData();
   delay(1000);
}

void loop()
  {
  if(client.available())
  {
    checkSignal(); 
    connectGPRS();
    postData();
    delay(1000);
  }
}

void connectGPRS()
  {
  client.println("AT+CGATT?");
  delay(1000);
  ShowSerialData();
  
  client.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(1000);
  ShowSerialData();                                             

  client.println("AT+SAPBR=3,1,\"APN\",\"www\"");
  //Using Indian Standard Vodafone Sim and so APN is www
  delay(1000);
  ShowSerialData();

  client.println("AT+SAPBR=1,1");
  delay(1000);
  ShowSerialData();

  client.println("AT+SAPBR=2,1");
  delay(1000);
  ShowSerialData();
}

void checkSignal()
  {
  client.println("AT+CSQ");
  delay(1000);
  ShowSerialData();
}
 
void ShowSerialData()
  {
  while(client.available()!=0)
    Serial.write(client.read());
 }

void postData()
  {
  client.println("AT+HTTPINIT");
  delay(1000);
  ShowSerialData();

  client.println("AT+HTTPPARA=\"CID\",1");
  delay(1000);
  ShowSerialData();
 

  client.println("AT+HTTPPARA=\"URL\",\"http://test.server/insert-path");
  delay(1000);
  ShowSerialData();

  client.println("AT+HTTPPARA=\"CONTENT\",\"application/json");
  delay(1000);
  ShowSerialData();

  client.println("AT+HTTPDATA=99,10000");
  delay(1000);
  ShowSerialData;

  client.println(testReading);
  delay(1000);
  ShowSerialData;

  client.println("AT+HTTPACTION=1");
  delay(10000);
  while(!client.available());
  ShowSerialData();
}

HTTP post request in JSON Format using SIM-900 module

I tried to send HTTP post request to a server in JSON Format using SIM-900 module.. But the code is not posting the data. While posting the data I'm getting the error response while initializing the server using the command

I don't know what's the error and how to fix this. Please help me to fix this.

#include<SoftwareSerial.h>

SoftwareSerial client(2,3);

String testReading="{  \"testID\" : 1,  \"testLevel\" : 1, }";

void setup()
 {
  Serial.begin(9600);  
  client.begin(9600);
  delay(1000);
  if(client.available())
  {
    Serial.print("Connected");
  } 
  else
  {
    Serial.print("Not Connected");
  }
   checkSignal(); 
   connectGPRS();
   postData();
   delay(1000);
}

void loop()
 {
  if(client.available())
  {
   checkSignal(); 
   connectGPRS();
   postData();
   delay(1000);
  }
}

void connectGPRS()
 {
  client.println("AT+CGATT?");
  delay(1000);
  ShowSerialData();
  
  client.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(1000);
  ShowSerialData();                                             

  client.println("AT+SAPBR=3,1,\"APN\",\"www\"");//Using Indian Standard Vodafone Sim and so APN is www
  delay(1000);
  ShowSerialData();

  client.println("AT+SAPBR=1,1");
  delay(1000);
  ShowSerialData();

  client.println("AT+SAPBR=2,1");
  delay(1000);
  ShowSerialData();
}

void checkSignal()
 {
  client.println("AT+CSQ");
  delay(1000);
  ShowSerialData();
}
 
void ShowSerialData()
 {
  while(client.available()!=0)
  Serial.write(client.read());
 }

void postData()
 {
  client.println("AT+HTTPINIT");
  delay(1000);
  ShowSerialData();

  client.println("AT+HTTPPARA=\"CID\",1");
  delay(1000);
  ShowSerialData();
 

  client.println("AT+HTTPPARA=\"URL\",\"http://test.server/insert-path");
  delay(1000);
  ShowSerialData();

  client.println("AT+HTTPPARA=\"CONTENT\",\"application/json");
  delay(1000);
  ShowSerialData();

  client.println("AT+HTTPDATA=99,10000");
  delay(1000);
  ShowSerialData;

  client.println(testReading);
  delay(1000);
  ShowSerialData;

  client.println("AT+HTTPACTION=1");
  delay(10000);
  while(!client.available());
  ShowSerialData();
}

HTTP post request in JSON Format using SIM900 module

I tried to send HTTP post requests to a server in JSON Format using a SIM900 module. But the code is not posting the data. While posting the data I'm getting the error response while initializing the server using the command:

I don't know what the error is and how to fix it. Please help me to fix this.

#include<SoftwareSerial.h>

SoftwareSerial client(2,3);

String testReading="{  \"testID\" : 1,  \"testLevel\" : 1, }";

void setup() {
  Serial.begin(9600);
  client.begin(9600);
  delay(1000);
  if(client.available()) {
    Serial.print("Connected");
  } else {
    Serial.print("Not Connected");
  }
  checkSignal();
  connectGPRS();
  postData();
  delay(1000);
}

void loop() {
  if(client.available()) {
    checkSignal();
    connectGPRS();
    postData();
    delay(1000);
  }
}

void connectGPRS() {
  client.println("AT+CGATT?");
  delay(1000);
  ShowSerialData();
  client.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(1000);
  ShowSerialData();
  client.println("AT+SAPBR=3,1,\"APN\",\"www\"");
  //Using Indian Standard Vodafone Sim and so APN is www
  delay(1000);
  ShowSerialData();

  client.println("AT+SAPBR=1,1");
  delay(1000);
  ShowSerialData();

  client.println("AT+SAPBR=2,1");
  delay(1000);
  ShowSerialData();
}

void checkSignal() {
  client.println("AT+CSQ");
  delay(1000);
  ShowSerialData();
}

void ShowSerialData() {
  while(client.available()!=0)
    Serial.write(client.read());
}

void postData() {
  client.println("AT+HTTPINIT");
  delay(1000);
  ShowSerialData();

  client.println("AT+HTTPPARA=\"CID\",1");
  delay(1000);
  ShowSerialData();

  client.println("AT+HTTPPARA=\"URL\",\"http://test.server/insert-path");
  delay(1000);
  ShowSerialData();

  client.println("AT+HTTPPARA=\"CONTENT\",\"application/json");
  delay(1000);
  ShowSerialData();

  client.println("AT+HTTPDATA=99,10000");
  delay(1000);
  ShowSerialData;

  client.println(testReading);
  delay(1000);
  ShowSerialData;

  client.println("AT+HTTPACTION=1");
  delay(10000);
  while(!client.available());
  ShowSerialData();
}
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user