Announcing HTTP Client availability for lv_micropython ESP32 port

ESP-IDF HTTP client is now available as part of espidf module.

This is a fully featured HTTP client provided as part of ESP-IDF, including TLS, header parsing, chunked responses, etc.
Now you can use it in Micropython.

It can be useful for interacting with REST API, or simply for fetching data from the web.

Here is a simple example that shows how to send a GET request, print HTTP headers and read the payload stream:

import espidf as esp

def event_handler(evt):
     if evt.event_id == esp.HTTP_EVENT.ON_HEADER:
         print("%s : %s" % (evt.header_key, evt.header_value))
     return 0

conf = esp.esp_http_client_config_t()
conf.url="https://lvgl.io"
conf.register_event_handler(event_handler, None)
client = conf.init()
esp.esp_http_client_open(client, 0)
esp.esp_http_client_fetch_headers(client)
buffer = bytes(256)
while True:
     bytes_read = esp.esp_http_client_read(client, buffer, len(buffer))
     if bytes_read < 0: break
     print(buffer[:bytes_read].decode("utf-8"), end="")
     if bytes_read < len(buffer): break
esp.esp_http_client_close(client)
esp.esp_http_client_cleanup(client)
2 Likes