0

I can't validate an AT command. Would anyone have any suggestions as to what I might be doing wrong? It should be printing "Sending successful! or "Sending failed!", but it doesn't show any text.

if (httpReadResponse.indexOf("OK") != -1) {
  Serial.println("Envio bem-sucedido!");
} else {
  Serial.println("Falha no envio!");
}

My serial monitor is printing this:

AT+HTTPDATA=192,5000\
DOWNLOAD\
OK\
AT+HTTPACTION=0\
OK\
AT+HTTPREAD

Full function:

void sendHttpRequest(int distance_cm) {
  gsm_send_serial("AT+HTTPINIT");
  gsm_send_serial("AT+HTTPPARA=CID,1");
  gsm_send_serial("AT+HTTPSSL=1");
  gsm_send_serial("AT+HTTPPARA=URL," + url2 + "/" + distance_cm + "/" + id_cliente + "/" + id_caixa + "/" + ipadd1 + "/" + sinal + "/" + totalMilliLitres + "/" + vazao_atual + "/" + apikey);
  gsm_send_serial("AT+HTTPPARA=CONTENT,application/x-www-form-urlencoded");
  gsm_send_serial("AT+HTTPDATA=192,5000");
  gsm_send_serial("param=Aqualizar");
  gsm_send_serial("AT+HTTPACTION=0");

  String httpReadResponse = gsm_send_serial("AT+HTTPREAD");

  gsm_send_serial("AT+HTTPTERM");

  if (httpReadResponse.indexOf("OK") != -1) {
    Serial.println("Sending successful!");
  } else {
    Serial.println("Sending failed!");
  }
}
6
  • The declaration of url2 may be important to interpreting gsm_send_serial("AT+HTTPPARA=URL," + url2... It would be better to provide all the variable declaration involved, if not compilable and testable code.
    – timemage
    Feb 1 at 22:56
  • what is the value of httpReadResponse.indexOf("OK")?
    – jsotola
    Feb 1 at 22:59
  • 2
    Print the value of the response, ie. Serial.println(httpReadResponse);
    – Nick Gammon
    Feb 2 at 2:43
  • 1
    String httpReadResponse = gsm_send_serial ("AT+HTTPREAD"); How is function gsm_send_serial() defined ? You are clearly expecting it to return a String under the circumstances that you are using it. Also, which Serial instance is connected to the serial monitor? Does, for example, Serial.println("Hello World") work? Which serial instance is connected to the GSM device?
    – 6v6gt
    Feb 2 at 3:24
  • 1
    It would help, if you provide a minimal compilable example code, that demonstrates your problem. How is the SIM800 connected, that the Serial Monitor and the Arduino both see the modules AT answer?
    – chrisl
    Feb 2 at 8:41

1 Answer 1

0

AT+HTTPACTION=0

AT+HTTPACTION=0 starts a GET session. Based on your code, you are supposed to create a POST session, which should be AT+HTTPACTION=1.

Read SIM800 Series_IP_Application Note which provides the examples for both GET and POST request based on the SIMCOM HTTP AT-command set. The application note can be found at SIMCOM's website (requires registration for free download) or simply google "SIM800 Series_IP_Application Note" as there are many sites that have the document available without the need for registration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.