Problem With GSM SIM800C POST method

Hello,
I want to send my sensor data to API.My data in json format. I am using GSM with Arduino and sending HTTP command through software serial library.
POST method code as follow:

void send_http_request() {

  gsm.println("AT+HTTPINIT");
  delay(200);
  read_data();

gsm.println("AT+HTTPPARA=\"URL\",\"http://elearning.campus2pro.com/hvac/ahu_fortis/api/index.php?call=control_list\"");
  delay(200);
  read_data();

  gsm.println("AT+HTTPPARA=\"CONTENT\",\"application/json\"");
  delay(200);
  read_data();

  gsm.println("AT+HTTPDATA=23,5000");
  delay(500);
  read_data();

  gsm.println("{\"device_id\":\"dev_1\"}");
  delay(1000);
  read_data();

  gsm.println("AT+HTTPACTION=1");
  delay(3000);
  read_data();

  gsm.println("AT+HTTPREAD");
  delay(2000);
  read_data();

}
//***********************************
void read_data() {

  String line;
  while (gsm.available() > 0) {
    char data = gsm.read();
    line += data;

  }
  Serial.print(line);

}

Problem: Data do not receive properly or sometimes it receives incomplete response. please help me. All command work properly in AT mode but I want to send the command through programming

Hi Ashwini,
You are doing it the wrong way. You should not just put delays if you want to write a perfect code. You should wait for responses and handle them. You should only execute the next code when you get a OK or ERROR responses from previous command. Without looking at what the module sent back, if we just send the next command, it would lead to problems.

do you have any example .Please send on my mail id

This is written for linux, it should help

I did as you told. I send next command after verify previous command. I have Json data in response . after that i call function jsonexact(); . some time arduino skip function and send next gsm command. I don’t understand how this happen?

I havent used jsonexact(). But if the JSON format you received back is not correct the function can return error and skip. But it should should not skip without entering.
You can print a text in the jsonexact function to see if the code flow is entering into it.

I have project . I get json response from server.
problem

  1. Some time receive half response.
    if I use function
    while (gsm.available()<0){} // for wait to available
    while (gsm.available()<0){ read data}
    still sometime it give half response.

  2. I send response to function
    fucntion unable to parse.

please your expert in GSM .

Do you have enough buffer space to read the response?
How long is data response and what is the size of the buffer you are using?

response is 211 byte. buffer is 256

You should capture the data flow on UART to a text file for analysis, Then we can find out if the module is putting out the full response to the MCU or not.

not understand what you said??

You should capture the AT Command flow between GSM module and MCU UART lines. You need USB-UART converter for this to capture data to PC. This data will help in analyzing whats happening.

Thank you for help me. my problem get sort out. actually this my coading issue .
Thank you once again. I am so happy

Glad you got it working :slight_smile:

hey ive been reading your help but for me i cant make it can u please give me a help

when am writing AT+HTTPPARA=“CONTENT”,“application/json”
am getting error s there any good way i can make it