Code Monkey home page Code Monkey logo

esphttpclient's Introduction

esphttpclient

This is a short library for ESP8266(EX) chips to make HTTP requests.

Features

  • Easy to use.
  • Supports multiple requests in parallel.
  • Supports POST,GET,PUT,DELETE and user defined RAW requests.
  • Tested with Espressif SDK v1.0.0, V1.3.0, V1.4.0

Building

If you don't have a toolchain yet, install one with https://github.com/pfalcon/esp-open-sdk then get Espressif's SDK.

The submodule way

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

In case you want to use SSL don't forget to add ssl to LIBS in the Makefile

LIBS = c gcc hal pp phy net80211 lwip wpa main ssl

The dirty way

Alternatively you could create a simple project:

git clone https://github.com/esp8266/source-code-examples.git
cd source-code-examples/basic_example
# Set your Wifi credentials in user_config.h
# I could not test this because of the UART baud rate (74880)

Then download this library and move the files to user/:

git clone https://github.com/Caerbannog/esphttpclient.git
mv esphttpclient/*.* user/

Usage

Include httpclient.h from user_main.c then call one of these functions:

void http_request(const char * url, const char * method, const char * headers, const char * post_data, http_callback_t callback_handle);
void http_post(const char * url, const char * headers, const char * post_data, http_callback_t callback_handle);
void http_get(const char * url, const char * headers, http_callback_t callback_handle);
void http_delete(const char * url, const char * headers, const char * post_data, http_callback_t callback_handle);
void http_put(const char * url, const char * headers, const char * post_data, http_callback_t callback_handle);

void http_callback_example(char * response, int http_status, char * full_response)
{
	os_printf("http_status=%d\n", http_status);
	if (http_status != HTTP_STATUS_GENERIC_ERROR) {
		os_printf("strlen(full_response)=%d\n", strlen(full_response));
		os_printf("response=%s<EOF>\n", response);
	}
}

Example

The following code performs a single request, then calls http_callback_example to display your public IP address.

http_get("http://wtfismyip.com/text", "", http_callback_example);

The output looks like this:

http_status=200
strlen(full_response)=244
response=208.97.177.124
<EOF>

esphttpclient's People

Contributors

caerbannog avatar georgkreimer avatar jpenninkhof avatar mharizanov avatar vowstar avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.