Let's say your ESP8266 acquires data from a sensor. You want to periodically send it on a remote webserver for logging, on a shared host for instance.
The easiest solution is to POST data on HTTP (like a form on a web page would).
Here is a simple library that will do the HTTP requests for you:
https://github.com/Caerbannog/esphttpclient
- Easy to use.
- Supports multiple requests in parallel.
- Supports GET and POST requests.
- Tested with Espressif SDK v1.0.0
Installing
If your project looks like esphttpd from Sprite_tm:
git clone http://git.spritesserver.nl/esphttpd.git/
cd esphttpd
git submodule add https://github.com/Caerbannog/esphttpclient.git lib/esphttpclient
git submodule update --init
Now append lib/esphttpclient to the following Makefile line and you should be ready:
MODULES = driver user lib/esphttpclient
Example GET
Include httpclient.h from user_main.c then add this line to perform a single request and display your public IP address.
http_get("http://wtfismyip.com/text", "", http_callback_example);
The output looks like this. It is a success because the 200 code means OK. You can now write your own function to replace http_callback_example.
http_status=200
strlen(full_response)=244
body_size=15
body=208.97.177.124
<EOF>
Example POST
To send sensor data use http_post as follows. If you are not interested in the response you can pass NULL for the callback function.
http_post("http://httpbin.org/post", "first_word=hello&second_word=world", "", http_callback_example);
Pull requests are welcome.