but when I try to get this data through my esp8266, I get wrong and irrelevant data with meaningless characters.
It has been sometimes that I get correct data but after a short time it stated to get wrong data.
is there any idea? is this code correct?
I use ESP8266 E01
this is my code:
It looks like you are following the BasicHttpClient example fairly closely so my guess is that there is something coming from the website that doesn't make sense to the ESP8266 libraries. Maybe looking at the headers would help. Try putting this in between printing "Http code" and "payload".
for (int i=0; i < http.headers(); i++)
{
Serial.print(http.headerName(i));
Serial.print(": "
Serial.println(http.header(i));
}
Thank you John, I added the code you mentioned but I got nothing between http.code and payload, so I printed http.headers() and saw that it returns 0 , so this is why the for loop is not executed. what does it mean ?
nothing happen when added this between printing "Http code" and "payload"
for (int i=0; i < http.headers(); i++)
{
Serial.print(http.headerName(i));
Serial.print(": ");
Serial.println(http.header(i));
}
things are getting a little bit confusing...
I don't know why but the same code works now (it's dangerous to don't know the reason) and get the payload below:
##DATA-IS:(off)##
but another problem raises now! the term "off" in the mentioned string is actually the value of a variable in the php file, which is updated trough a button in the webserver. when I change the value to "on" the ESP8266 still receives ##DATA-IS:(off)## instead of ##DATA-IS:(on)##.. but when I check the URL through a browser like Chrome it shows ##DATA-IS:(on)##..
at this moment check this URL and you will see it returns the value ##DATA-IS:(on)##
Thank you for your reply, would you please explain a little more?
I want to get the correct value of the url response.. but it always returns wrong using mentioned Arduino code in ESP8266.. I've also tried some python code to check the url and it works fine there...
I tried to find out why the value of http.headers() is equal to zero! I could not make it!
I think all of the mentioned problems above comes from here... http.headers() = 0
My guess is that you were getting the contents of some buffer that formerly contained garbage and now contains "##DATA-IS:(off)##". If you reset the ESP8266 does it still receive "##DATA-IS:(off)##"?
Thank you John, the module reset don't help, and still get ##DATA-IS(off)##, but some times after long time (few hours) if I change the state to "ON" and after that turn on the module it gets ##DATA-IS(on)##.. and here we go.. it starts to show ##DATA-IS(on)## and don't change to off...
thank you so much! It solved my problem I didn't know that it's possible to receive URL payload by POST method.. I've read a little more about POST and GET methods, we can send and receive data with HTTP protocol by both of them.. right??