-->
Page 1 of 2

ESP8266 send data to website

PostPosted: Sat Apr 30, 2016 7:52 am
by drekthral
Hello,
I would like to send data from temperature sensor to my network webserver.
In my arduino IDE I need to make somthing like this :
Code: Select allhttp.begin("http://192.168.10.1/test/esp8266.php/?temp=" + temp);


On my webserver I have php script that takes variable temp and save it.

So I just need to make ESP8266 open "192.168.10.1/test/esp8266.php/?temp=" + variable temp

Any ides how to do that ?

Thanks for every reply :)

Re: ESP8266 send data to website

PostPosted: Sat Apr 30, 2016 1:00 pm
by martinayotte
Yes, since you seems to use ESP8266HTTPClient, it should work !
Did you started with esp8266/2.2.0/libraries/ESP8266HTTPClient/examples/BasicHttpClient/BasicHttpClient.ino example ?

Re: ESP8266 send data to website

PostPosted: Sun May 01, 2016 2:26 am
by Ayush Sharma
Hello Sir,
I was Doing the Same but It's Really Hard to Understand the Example without some explanation . Sir, Could you please Tell me how this Example will work? I could understand this will send a url request to my website where my php script will understand it.
But this Part: ( Code from Basic HTTP Client Example) :geek:
Code: Select allif(httpCode > 0) {
            // HTTP header has been send and Server response header has been handled
            USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);

            // file found at server
            if(httpCode == HTTP_CODE_OK) {
                String payload = http.getString();
                USE_SERIAL.println(payload);
            }
        } else {
            USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
        }


I don't understand.. Help would be really Appreciated! :)

Re: ESP8266 send data to website

PostPosted: Sun May 01, 2016 7:40 am
by martinayotte
The actual request is sent when http.GET() is call, then returning the response status code.
If the returned httpCode is 0, it never received any response, probably due to timeout or non-responding server.
If httpCode is higher than 0, server actually provided an response, it could be any, such the famous "404 Page not Found", or a "200 OK", which is HTTP_CODE_OK, in this case the code above simply display the response body received from the server, in your case, whatever your PHP will answer after executing your command.