A place users can post their projects. If you have a small project and would like your own dedicated place to post and have others chat about it then this is your spot.

User avatar
By Caer
#13978 Hello everyone,

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:
Code: Select allgit 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:
Code: Select allMODULES = 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.
Code: Select allhttp_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.
Code: Select allhttp_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.
Code: Select allhttp_post("http://httpbin.org/post", "first_word=hello&second_word=world", "", http_callback_example);


Pull requests are welcome.
Last edited by Caer on Mon Jan 23, 2017 4:22 am, edited 1 time in total.