Chitraveer Akhil
Chitraveer Akhil

Reputation: 147

Sending datas using HTTP request using SIM 900

I'm trying to post some manual data from Arduino to a server. I'm using SIM 900 for data connection.. The data are not reaching the server.. The SIM is been initialized without error but the data are not been posted to the server.. Please help me to fix that.. The code is below..

#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();
}

Upvotes: 2

Views: 4764

Answers (1)

Sajith Dimal
Sajith Dimal

Reputation: 61

You need to add another '\"' to complete the URL and content type.

client.println("AT+HTTPPARA=\"URL\",\"http://test.server/insert-path\"");
client.println("AT+HTTPPARA=\"CONTENT\",\"application/json\"");

Also, trying to increase the client.println("AT+HTTPDATA=99,10000"); data input delay 10s to 20s.

Upvotes: 1

Related Questions