I'm working on a project with Arduino UNO that needs connection with a cloud server, that is why I'm using ESP8266 module.

I'm already connecting to wi-fi and making GET and POST request but my problem is get the response from these requests.

Here is my code:

/* Doing all these steps to make the request

String data = "data=example";

String command = "POST /webservice/v1/dispositivo/atualizar_data_requisicao HTTP/1.1\r\n";
comando += "Host: " + SERVER + "\r\n";
comando += "User-Agent: Arduino/1.0\r\n";
comando += "Connection: Close\r\n";
comando += "Content-Type: application/x-www-form-urlencoded;\r\n";
comando += "Content-Length: " + String(data.length()) + "\r\n\r\n";
comando += data;



String response;

while(esp8266.available()) {
  response += esp8266.readStringUntil('\r');

Serial.print("Request response: ");

When I run this code the only response I can get is something like:

Recv 270 bxt⸮⸮C⸮

+IPD,0.569:HTTP/1.0 200 OK

But I was expecting a JSON.

Can someone tell me what I am doing wrong and how can I resolve it?


Ok, after Code Gorilla helps me (Thank you so much) and a lot of research what I did was program Arduino UNO to send some commands that I invented to serial and program ESP8266 to read the serial and, depending of the command that it reads, do requests and stuff.

ESP8266 is a lot easyer to make requests and have a lot of others possibilities, like HTTPS requests, that you can't do using AT Commands.

When I create this ask I didn't know that I could program directly in ESP8266, but when Code Gorilla told me about it and helps me with some articles I could finally continue with my project.

  • try using the GET method instead of POST
    – jsotola
    Commented May 21, 2018 at 22:37
  • This variable named "data" is the content of the POST Commented May 21, 2018 at 22:38
  • 1
    Try posting all your code, not a meaningless snippet.
    – Majenko
    Commented May 21, 2018 at 22:56
  • you expect that after reading a line, the first character of the next line is immediately available
    – Juraj
    Commented May 22, 2018 at 7:54
  • Why are you using an Uno? Why not just program the ESP8266 directly (using the Arduino IDE and language), much quicker and you don't need to send everything via serial. Commented May 23, 2018 at 11:45

1 Answer 1

String command = "POST /webservice/v1/dispositivo/atualizar_data_requisicao HTTP/1.1\r\n";
comando += "Host: " + SERVER + "\r\n";

I suspect this is just a typo because it shouldn't compile. But you are adding all the HTTP headers to commando not command.

Usually the ? means that the character is unprintable. So to help diagnose the issue display the integer value for each character that is returned. Something LIKE this (I've never used a String before so length() might not be right)

Serial.print("Request response: ");
for (int index = 0; index < response.length(); ++index)
   Serial.print (response[index]);
   Serial.print (" ");

If you want to program the ESP directly then have a look at these guides, they should give you the general idea. Its usually as easy as programming an UNO once you are setup.

http://www.whatimade.today/esp8266-easiest-way-to-program-so-far/ https://learn.adafruit.com/adafruit-huzzah-esp8266-breakout/using-arduino-ide https://www.hackster.io/harshmangukiya/how-to-program-esp8266-with-arduino-uno-efb05f

  • I'm sorry, I think that I need to make a new question because I am not expressing my question very well. But your answer seems to be correct, the example shouldn't compile. Thank you! Commented May 23, 2018 at 23:35
  • Don't make a new question, edit the one above. Use diagrams because then the language doesn't matter so much. Commented May 24, 2018 at 9:01
  • 1
    Thank you so much! I could not continue without your help. I edited the question with what I did to resolve it. Commented Jun 6, 2018 at 19:45

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.