data stringlengths 512 2.99k |
|---|
API Conventions
This document describes conventions and assumptions common to ESP-IDF Application Programming Interfaces (APIs).
ESP-IDF provides several kinds of programming interfaces:
C functions, structures, enums, type definitions, and preprocessor macros declared in public header files of ESP-IDF components. Va... |
The following is incorrect:
esp_timer_create_args_t my_timer_args;
my_timer_args.callback = &my_timer_callback;
/* Incorrect! Fields .arg and .name are not initialized */
esp_timer_create(&my_timer_args, &my_timer);
Most ESP-IDF examples use C99 designated initializers for structure initialization since they provide a ... |
Note that C++ language versions older than C++20, which are not the default in the current version of ESP-IDF, do not support designated initializers. If you have to compile code with an older C++ standard than C++20, you may use GCC extensions to produce the following pattern:
esp_timer_create_args_t my_timer_args = {... |
HTTPD_DEFAULT_CONFIG expands to a designated initializer. Now all fields are set to the default values, and any field can still be modified: */
config.server_port = 8081;
httpd_handle_t server;
esp_err_t err = httpd_start(&server, &config);
It is recommended to use default initializer macros whenever they are provided ... |
ESP-MQTT
Overview
ESP-MQTT is an implementation of MQTT protocol client, which is a lightweight publish/subscribe messaging protocol. Now ESP-MQTT supports MQTT v5.0.
Features
-
Support MQTT over TCP, SSL with Mbed TLS, MQTT over WebSocket, and MQTT over WebSocket Secure
-
Easy to setup with URI
-
Multiple instances (m... |
Application Examples
-
protocols/mqtt/tcp: MQTT over TCP, default port 1883
-
protocols/mqtt/ssl: MQTT over TLS, default port 8883
-
protocols/mqtt/ssl_ds: MQTT over TLS using digital signature peripheral for authentication, default port 8883
-
protocols/mqtt/ssl_mutual_auth: MQTT over TLS using certificates for authen... |
= (const char *)mqtt_eclipse_org_pem_start,
},
};
For details about other fields, please check the API Reference and TLS Server Verification.
Client Credentials
All client related credentials are under the
credentials field.
Authentication
It is possible to set authentication parameters through the
authentication fi... |
int cert_selection_callback(mbedtls_ssl_context *ssl)
{
/* Code that the callback should execute */
return 0;
}
esp_tls_cfg_t cfg = {
cert_select_cb = cert_section_callback,
};
Underlying SSL/TLS Library Options
The ESP-TLS component offers the option to use MbedTLS or WolfSSL as its underlying SSL/TLS library. By defa... |
|
Property
|
WolfSSL
|
MbedTLS
|
Total Heap Consumed
|
~ 19 KB
|
~ 37 KB
|
Task Stack Used
|
~ 2.2 KB
|
~ 3.6 KB
|
Bin size
|
~ 858 KB
|
~ 736 KB
Note
These values can vary based on configuration options and version of respective libraries.
ATECC608A (Secure Element) with ESP-TLS
ESP-TLS provides support for using ATE... |
Choose Type of ATECC608A chip
To know more about different types of ATECC608A chips and how to obtain the type of ATECC608A connected to your ESP module, please visit ATECC608A chip type.
Enable the use of ATECC608A in ESP-TLS by providing the following config option in
esp_tls_cfg_t.
esp_tls_cfg_t cfg = {
/* other c... |
ciphersuites_list,
};
ESP-TLS will not check the validity of
ciphersuites_list that was set, you should call
esp_tls_get_ciphersuites_list() to get ciphersuites list supported in the TLS stack and cross-check it against the supplied list.
Note
This feature is supported only in the MbedTLS stack.
API Reference
Header ... |
[in] Pointer to esp-tls as esp-tls handle.
-
- Returns
-1 If connection establishment fails.
1 If connection establishment is successful.
0 If connection state is in progress.
-
-
int esp_tls_conn_http_new_sync(const char *url, const esp_tls_cfg_t *cfg, esp_tls_t *tls)
Create a new blocking TLS/SSL connection with a ... |
[in] Pointer to esp-tls as esp-tls handle.
-
- Returns
-1 If connection establishment fails.
1 If connection establishment is successful.
0 If connection state is in progress.
-
-
int esp_tls_conn_new_async(const char *hostname, int hostlen, int port, const esp_tls_cfg_t *cfg, esp_tls_t *tls)
Create a new non-blockin... |
If connection establishment is in progress.
1 If connection establishment is successful.
-
-
int esp_tls_conn_http_new_async(const char *url, const esp_tls_cfg_t *cfg, esp_tls_t *tls)
Create a new non-blocking TLS/SSL connection with a given "HTTP" url.
The behaviour is same as esp_tls_conn_new_async() API. However t... |
If connection establishment is in progress.
1 If connection establishment is successful.
-
-
ssize_t esp_tls_conn_write(esp_tls_t *tls, const void *data, size_t datalen)
Write from buffer 'data' into specified tls connection.
- Parameters
tls -- [in] pointer to esp-tls as esp-tls handle.
data -- [in] Buffer from whic... |
[in] Length of data buffer.
-
- Returns
>0 if read operation was successful, the return value is the number of bytes actually read from the TLS/SSL connection.
0 if read operation was not successful. The underlying connection was closed.
<0 if read operation was not successful, because either an error occured or an ac... |
Return the number of application data bytes remaining to be read from the current record.
This API is a wrapper over mbedtls's mbedtls_ssl_get_bytes_avail() API.
- Parameters
tls -- [in] pointer to esp-tls as esp-tls handle.
- Returns
-1 in case of invalid arg
bytes available in the application data record read buffer... |
Sets the connection socket file descriptor for the esp_tls session.
- Parameters
tls -- [in] handle to esp_tls context
sockfd -- [in] sockfd value to set.
-
- Returns
- ESP_OK on success and value of sockfd for the tls connection shall updated withthe provided value
ESP_ERR_INVALID_ARG if (tls == NULL || sockfd < 0)
-
... |
[in] Length of the buffer.
-
- Returns
ESP_OK if adding certificates was successful.
Other if an error occured or an action must be taken by the calling process.
-
-
void esp_tls_free_global_ca_store(void)
Free the global CA store currently being used.
The memory being used by the global CA store to store all the pa... |
[out] last error code returned from mbedtls api (set to zero if none) This pointer could be NULL if caller does not care about esp_tls_code
esp_tls_flags -- [out] last certification verification flags (set to zero if none) This pointer could be NULL if caller does not care about esp_tls_code
-
- Returns
ESP_ERR_INVALID... |
Get the pointer to the global CA store currently being used.
The application must first call esp_tls_set_global_ca_store(). Then the same CA store could be used by the application for APIs other than esp_tls.
Note
Modifying the pointer might cause a failure in verifying the certificates.
- Returns
Pointer to the glob... |
[out] ESP-TLS error handle holding potential errors occurred during connection
sockfd -- [out] Socket descriptor if successfully connected on TCP layer
-
- Returns
ESP_OK on success ESP_ERR_INVALID_ARG if invalid output parameters ESP-TLS based error codes on failure
Structures
-
struct psk_key_hint
ESP-TLS preshared k... |
ESP HTTP Client
Overview
esp_http_client component provides a set of APIs for making HTTP/S requests from ESP-IDF applications. The steps to use these APIs are as follows:
-
esp_http_client_init(): Creates an
esp_http_client_handle_tinstance, i.e., an HTTP client handle based on the given
esp_http_client_config_tconfig... |
Basic authentication) and
http_auth_digest(for Digest authentication) in the application example for implementation details.
-
Examples of Authentication Configuration
-
Authentication with URIesp_http_client_config_t config = { .url = "http://user:passwd@httpbin.org/basic-auth/user/passwd", .auth_type = HTTP_AUTH_TYPE... |
HTTP_EVENT_REDIRECT :
esp_http_client_redirect_event_data_t
The
esp_http_client_handle_t received along with the event data will be valid until
HTTP_EVENT_DISCONNECTED is not received. This handle has been sent primarily to differentiate between different client connections and must not be used for any other purpose, a... |
[in] The esp_http_client handle
data -- [in] post data pointer
len -- [in] post length
-
- Returns
ESP_OK
ESP_FAIL
-
-
int esp_http_client_get_post_field(esp_http_client_handle_t client, char **data)
Get current post field information.
- Parameters
client -- [in] The client
data -- [out] Point to post data pointer
-
- ... |
The value stored from the esp_http_client_config_t will be written to the address passed into data.
- Parameters
client -- [in] The esp_http_client handle
data -- [out] A pointer to the pointer that will be set to user_data.
-
- Returns
ESP_OK
ESP_ERR_INVALID_ARG
-
-
esp_err_t esp_http_client_set_user_data(esp_http_cli... |
[in] The esp_http_client handle
data -- [in] The pointer to the user data
-
- Returns
ESP_OK
ESP_ERR_INVALID_ARG
-
-
int esp_http_client_get_errno(esp_http_client_handle_t client)
Get HTTP client session errno.
- Parameters
client -- [in] The esp_http_client handle
- Returns
(-1) if invalid argument
errno
-
-
esp_err_t... |
[in] This value must not be larger than the write_len parameter provided to esp_http_client_open()
-
- Returns
(-1) if any errors
Length of data written
-
-
int64_t esp_http_client_fetch_headers(esp_http_client_handle_t client)
This function need to call after esp_http_client_open, it will read from http stream, proces... |
[in] The esp_http_client handle
buffer -- The buffer
len -- [in] The length
-
- Returns
(-1) if any errors
Length of data was read
-
-
int esp_http_client_get_status_code(esp_http_client_handle_t client)
Get http response status code, the valid value if this function invoke after
esp_http_client_perform
- Parameters
c... |
Chunked transfer
Content-Length value as bytes
-
-
esp_err_t esp_http_client_close(esp_http_client_handle_t client)
Close http connection, still kept all http request resources.
- Parameters
client -- [in] The esp_http_client handle
- Returns
ESP_OK
ESP_FAIL
-
-
esp_err_t esp_http_client_cleanup(esp_http_client_handle_... |
When received the 30x code from the server, the client stores the redirect URL provided by the server. This function will set the current URL to redirect to enable client to execute the redirection request. When
disable_auto_redirectis set, the client will not call this function but the event
HTTP_EVENT_REDIRECTwill be... |
[in] The esp_http_client handle
auth_data -- [in] The authentication data received in the header
len -- [in] length of auth_data.
-
- Returns
ESP_ERR_INVALID_ARG
ESP_OK
-
-
void esp_http_client_add_auth(esp_http_client_handle_t client)
On receiving HTTP Status code 401, this API can be invoked to add authorization info... |
Values:
-
enumerator HTTP_TRANSPORT_UNKNOWN
Unknown
-
enumerator HTTP_TRANSPORT_OVER_TCP
Transport over tcp
-
enumerator HTTP_TRANSPORT_OVER_SSL
Transport over ssl
- enumerator HTTP_TRANSPORT_UNKNOWN
-
enum esp_http_client_proto_ver_t
Values:
-
enumerator ESP_HTTP_CLIENT_TLS_VER_ANY
-
enumerator ESP_HTTP_CLIENT_TLS_VER... |
* ---------------------------------------> MSB */ 0x21, 0xd5, 0x3b, 0x8d, 0xbd, 0x75, 0x68, 0x8a, 0xb4, 0x42, 0xeb, 0x31, 0x4a, 0x1e, 0x98, 0x3d } } }, .proto_sec = { .version = PROTOCOM_SEC0, .custom_handle = NULL, .sec_params = NULL, }, .handlers = { /* User defined handler functions */ .get_prop_values = get_propert... |
[] asm("_binary_servercert_pem_start"); extern const unsigned char servercert_end [] asm("_binary_servercert_pem_end"); https_conf.servercert = servercert_start; https_conf.servercert_len = servercert_end - servercert_start; /* Load server private key */ extern const unsigned char prvtkey_pem_start [] asm("_binary_prvt... |
Each property must have a unique
`name` (string), a
type (e.g., enum),
flags` (bit fields) and
size`.
The
size is to be kept 0, if we want our property value to be of variable length (e.g., if it is a string or bytestream). For data types with fixed-length property value, like int, float, etc., setting the
size field ... |
* Create a timestamp property */ esp_local_ctrl_prop_t timestamp = { .name = "timestamp", .type = TYPE_TIMESTAMP, .size = sizeof(int32_t), .flags = READONLY, .ctx = func_get_time, .ctx_free_fn = NULL }; /* Now register the property */ esp_local_ctrl_add_property(×tamp);
Also notice that there is a ctx field, which is s... |
Notice how we restrict from writing to read-only properties.
static esp_err_t set_property_values(size_t props_count, const esp_local_ctrl_prop_t *props, const esp_local_ctrl_prop_val_t *prop_values, void *usr_ctx) { for (uint32_t i = 0; i < props_count; i++) { if (props[i].flags & READONLY) { ESP_LOGE(TAG, "Cannot wr... |
This accepts an array of indices and an array of new values, which are used for setting the values of the properties corresponding to the indices.
Note that indices may or may not be the same for a property, across multiple sessions. Therefore, the client must only use the names of the properties to uniquely identify ... |
The various protocomm endpoints provided by esp_local_ctrl are listed below:
|
Endpoint Name (Bluetooth Low Energy + GATT Server)
|
URI (HTTPS Server + mDNS)
|
Description
|
esp_local_ctrl/version
|
https://<mdns-hostname>.local/esp_local_ctrl/version
|
Endpoint used for retrieving version string
|
esp_local_ctrl/con... |
Add a new property.
This adds a new property and allocates internal resources for it. The total number of properties that could be added is limited by configuration option
max_properties
- Parameters
prop -- [in] Property description structure
- Returns
ESP_OK : Success
ESP_FAIL : Failure
-
-
esp_err_t esp_local_ctrl_... |
In case of BLE transport the names and uuids of all custom endpoints must be provided beforehand as a part of the
protocomm_ble_config_tstructure set in
esp_local_ctrl_config_t, and passed to
esp_local_ctrl_start().
- Parameters
ep_name -- [in] Name of the endpoint
handler -- [in] Endpoint handler function
user_ctx -- ... |
This is same as
protocomm_ble_config_t. See
protocomm_ble.hfor available configuration parameters.
-
esp_local_ctrl_transport_config_httpd_t *httpd
This is same as
httpd_ssl_config_t. See
esp_https_server.hfor available configuration parameters.
- esp_local_ctrl_transport_config_ble_t *ble
Structures
-
struct esp_local... |
Public Members
-
void *data
Pointer to memory holding property value
-
size_t size
Size of property value
-
void (*free_fn)(void *data)
This may be set by the application in
get_prop_values()handler to tell
esp_local_ctrlto call this function on the data pointer above, for freeing its resources after sending the
get_... |
InvalidProto
All other error codes : InternalError
-
-
esp_err_t (*set_prop_values)(size_t props_count, const esp_local_ctrl_prop_t props[], const esp_local_ctrl_prop_val_t prop_values[], void *usr_ctx)
Handler function to be implemented for changing values of properties.
Note
If any of the properties have variable si... |
ESP Serial Slave Link
Overview
Espressif provides several chips that can work as slaves. These slave devices rely on some common buses, and have their own communication protocols over those buses. The
esp_serial_slave_link component is designed for the master to communicate with ESP slave devices through those protocol... |
The device running the
esp_serial_slave_linkcomponent.
ESSL device: a virtual device on the master associated with an ESP slave device. The device context has the knowledge of the slave protocol above the bus, relying on some bus drivers to communicate with the slave.
ESSL device handle: a handle to ESSL device con... |
The slave can send data in stream to the master. The SDIO slave can also indicate it has new data to send to master by the interrupt line.
The slave updates the RX data size to inform the master how much data it has prepared to send, and then the master read the data size, and take off the data length it has already ... |
Call
sdmmc_card_init()to initialize the card.
Initialize the ESSL device with
essl_sdio_config_t. The
cardmember should be the
sdmmc_card_tgot in step 2, and the
recv_buffer_sizemember should be filled correctly according to pre-negotiated value.
Call
essl_init()to do initialization of the SDIO part.
Call
essl_wa... |
send data to the slave.
RX FIFO
Call
essl_get_rx_data_size()to know how many data the slave has prepared to send to the master. This is optional. When the master tries to receive data from the slave, it updates the
rx_data_sizefor once, if the current
rx_data_sizeis shorter than the buffer size the master prepared to ... |
Output of data size to read from slave, in bytes
wait_ms -- Millisecond to wait before timeout, will not wait at all if set to 0-9.
-
- Returns
ESP_OK: Success
ESP_ERR_NOT_SUPPORTED: This API is not supported in this mode
One of the error codes from SDMMC/SPI host controller
-
-
esp_err_t essl_reset_cnt(essl_handle_t h... |
Millisecond to wait before timeout, will not wait at all if set to 0-9.
-
- Returns
ESP_OK Success
ESP_ERR_INVALID_ARG: Invalid argument, handle is not init or other argument is not valid.
ESP_ERR_TIMEOUT: No buffer to use, or error ftrom SDMMC host controller.
ESP_ERR_NOT_FOUND: Slave is not ready for receiving.
ESP_E... |
Millisecond to wait before timeout, will not wait at all if set to 0-9.
-
- Returns
ESP_OK: Success
ESP_INVALID_ARG: If both
intr_rawand
intr_stare NULL.
ESP_ERR_NOT_SUPPORTED: Current device does not support this function.
One of the error codes from SDMMC host controller
-
-
esp_err_t essl_set_intr_ena(essl_handle_t... |
Millisecond to wait before timeout, will not wait at all if set to 0-9.
-
- Returns
ESP_OK: Success
ESP_ERR_NOT_SUPPORTED: Current device does not support this function.
One of the error codes from SDMMC host controller
-
Type Definitions
-
typedef struct essl_dev_t *essl_handle_t
Handle of an ESSL device.
Header Fil... |
The address argument is not valid. See note 1.
ESP_ERR_NOT_SUPPORTED: Should set
out_valueto NULL. See note 2.
or other return value from :cpp:func:
spi_device_transmit.
-
-
esp_err_t essl_spi_send_packet(void *arg, const void *data, size_t size, uint32_t wait_ms)
Send a packet to Slave.
- Parameters
arg -- Context of ... |
Used when the slave is working in segment mode.
- Parameters
spi -- SPI device handle representing the slave
out_data -- [out] Buffer to hold the received data, strongly suggested to be in the DRAM and aligned to 4
len -- Total length of data to receive.
seg_len -- Length of each segment, which is not larger than the... |
[out] Buffer to hold the received data. strongly suggested to be in the DRAM and aligned to 4
seg_len -- Length of this segment
flags --
SPI_TRANS_*flags to control the transaction mode of the transaction to send.
-
- Returns
ESP_OK: success
or other return value from :cpp:func:
spi_device_transmit.
-
-
esp_err_t essl_... |
Used when the slave is working in segment mode.
- Parameters
spi -- SPI device handle representing the slave
data -- Buffer for data to send, strongly suggested to be in the DRAM
len -- Total length of data to send.
seg_len -- Length of each segment, which is not larger than the maximum transaction length allowed for... |
HTTP Server
Overview
The HTTP Server component provides an ability for running a lightweight web server on ESP32. Following are detailed steps to use the API exposed by HTTP Server:
-
httpd_start(): Creates an instance of HTTP server, allocate memory/resources for it depending upon the specified configuration and outpu... |
In case of string data, null termination will be absent, and * content length would give length of string */ char content[100]; /* Truncate if content length larger than the buffer */ size_t recv_size = MIN(req->content_len, sizeof(content)); int ret = httpd_req_recv(req, content, recv_size); if (ret <= 0) { /* 0 retur... |
NULL }; /* Function for starting the webserver */ httpd_handle_t start_webserver(void) { /* Generate default configuration */ httpd_config_t config = HTTPD_DEFAULT_CONFIG(); /* Empty handle to esp_http_server */ httpd_handle_t server = NULL; /* Start the httpd server */ if (httpd_start(&server, &config) == ESP_OK) { /*... |
Server Example
Check HTTP server example under protocols/http_server/simple where handling of arbitrary content lengths, reading request headers and URL query parameters, and setting response headers is demonstrated.
Persistent Connections
HTTP server features persistent connections, allowing for the re-use of the sa... |
Persistent Connections Example
/* Custom function to free context */
void free_ctx_func(void *ctx)
{
/* Could be something other than free */
free(ctx);
}
esp_err_t adder_post_handler(httpd_req_t *req)
{
/* Create session's context if not already available */
if (! req->sess_ctx) {
req->sess_ctx = malloc(sizeof(ANY_DAT... |
Websocket Server
The HTTP server component provides websocket support. The websocket feature can be enabled in menuconfig using the CONFIG_HTTPD_WS_SUPPORT option. Please refer to the protocols/http_server/ ws_echo_server example which demonstrates usage of the websocket feature.
Event Handling
ESP HTTP server has va... |
Expected data type for different ESP HTTP server events in event loop:
-
HTTP_SERVER_EVENT_ERROR :
httpd_err_code_t
-
HTTP_SERVER_EVENT_START :
NULL
-
HTTP_SERVER_EVENT_ON_CONNECTED :
int
-
HTTP_SERVER_EVENT_ON_HEADER :
int
-
HTTP_SERVER_EVENT_HEADERS_SENT :
int
-
HTTP_SERVER_EVENT_ON_DATA :
esp_http_server_event_data
... |
[in] handle to HTTPD server instance
uri -- [in] URI string
method -- [in] HTTP method
-
- Returns
ESP_OK : On successfully deregistering the handler
ESP_ERR_INVALID_ARG : Null arguments
ESP_ERR_NOT_FOUND : Handler with specified URI and method not found
-
-
esp_err_t httpd_unregister_uri(httpd_handle_t handle, const c... |
[in] The send function to be set for this session
-
- Returns
ESP_OK : On successfully registering override
ESP_ERR_INVALID_ARG : Null arguments
-
-
-
esp_err_t httpd_sess_set_pending_override(httpd_handle_t hd, int sockfd, httpd_pending_func_t pending_func)
Override web server's pending function (by session FD)
This f... |
[in] The request to create an async copy of
out -- [out] A newly allocated request which can be used on an async thread
-
- Returns
ESP_OK : async request object created
-
-
-
esp_err_t httpd_req_async_handler_complete(httpd_req_t *r)
Mark an asynchronous request as completed. This will.
free the request memory
relinqu... |
[in] The request being responded to
buf -- [in] Pointer to a buffer that the data will be read into
buf_len -- [in] Length of the buffer
-
- Returns
Bytes : Number of bytes read into the buffer successfully
0 : Buffer length parameter is zero / connection closed by peer
HTTPD_SOCK_ERR_INVALID : Invalid arguments
HTTPD_... |
[in] Size of the user buffer "val"
-
- Returns
ESP_OK : Field found in the request header and value string copied
ESP_ERR_NOT_FOUND : Key not found
ESP_ERR_INVALID_ARG : Null arguments
ESP_ERR_HTTPD_INVALID_REQ : Invalid HTTP request pointer
ESP_ERR_HTTPD_RESULT_TRUNC : Value string truncated
-
-
-
size_t httpd_req_get... |
Query string truncated
-
-
-
esp_err_t httpd_query_key_value(const char *qry, const char *key, char *val, size_t val_size)
Helper function to get a URL query tag from a query string of the type param1=val1¶m2=val2.
Note
The components of URL query string (keys and values) are not URLdecoded. The user must check for '... |
[in] Pointer to query string
key -- [in] The key to be searched in the query string
val -- [out] Pointer to the buffer into which the value will be copied if the key is found
val_size -- [in] Size of the user buffer "val"
-
- Returns
ESP_OK : Key is found in the URL query string and copied to buffer
ESP_ERR_NOT_FOUND :... |
[in] URI template (pattern)
uri_to_match -- [in] URI to be matched
match_upto -- [in] how many characters of the URI buffer to test (there may be trailing query string etc.)
-
- Returns
true if a match was found
-
-
esp_err_t httpd_resp_send(httpd_req_t *r, const char *buf, ssize_t buf_len)
API to send a complete HTTP ... |
[in] The request being responded to
buf -- [in] Buffer from where the content is to be fetched
buf_len -- [in] Length of the buffer, HTTPD_RESP_USE_STRLEN to use strlen()
-
- Returns
ESP_OK : On successfully sending the response packet
ESP_ERR_INVALID_ARG : Null request pointer
ESP_ERR_HTTPD_RESP_HDR : Essential header... |
[in] The request being responded to
buf -- [in] Pointer to a buffer that stores the data
buf_len -- [in] Length of the buffer, HTTPD_RESP_USE_STRLEN to use strlen()
-
- Returns
ESP_OK : On successfully sending the response packet chunk
ESP_ERR_INVALID_ARG : Null request pointer
ESP_ERR_HTTPD_RESP_HDR : Essential header... |
[in] The request being responded to
str -- [in] String to be sent as response body
-
- Returns
ESP_OK : On successfully sending the response packet
ESP_ERR_INVALID_ARG : Null request pointer
ESP_ERR_HTTPD_RESP_HDR : Essential headers are too large for internal buffer
ESP_ERR_HTTPD_RESP_SEND : Error in raw send
ESP_ERR_... |
[in] The request being responded to
str -- [in] String to be sent as response body (NULL to finish response packet)
-
- Returns
ESP_OK : On successfully sending the response packet
ESP_ERR_INVALID_ARG : Null request pointer
ESP_ERR_HTTPD_RESP_HDR : Essential headers are too large for internal buffer
ESP_ERR_HTTPD_RESP_... |
[in] The request being responded to
status -- [in] The HTTP status code of this response
-
- Returns
ESP_OK : On success
ESP_ERR_INVALID_ARG : Null arguments
ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
-
-
-
esp_err_t httpd_resp_set_type(httpd_req_t *r, const char *type)
API to set the HTTP content type.
This... |
This API sets any additional header fields that need to be sent in the response.
Note
This API is supposed to be called only from the context of a URI handler where httpd_req_t* request pointer is valid.
The header isn't sent out until any of the send APIs is executed.
The maximum allowed number of additional hea... |
[in] The request being responded to
- Returns
ESP_OK : On successfully sending the response packet
ESP_ERR_INVALID_ARG : Null arguments
ESP_ERR_HTTPD_RESP_SEND : Error in raw send
ESP_ERR_HTTPD_INVALID_REQ : Invalid request pointer
-
-
-
static inline esp_err_t httpd_resp_send_500(httpd_req_t *r)
Helper function for HT... |
Call this API if you wish to construct your custom response packet. When using this, all essential header, eg. HTTP version, Status Code, Content Type and Length, Encoding, etc. will have to be constructed manually, and HTTP delimeters (CRLF) will need to be placed correctly for separating sub-sections of the HTTP resp... |
[in] The request being responded to
buf -- [in] Buffer from where the fully constructed packet is to be read
buf_len -- [in] Length of the buffer
-
- Returns
Bytes : Number of bytes that were sent successfully
HTTPD_SOCK_ERR_INVALID : Invalid arguments
HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket... |
[in] server instance
sockfd -- [in] session socket file descriptor
buf -- [in] buffer with bytes to send
buf_len -- [in] data size
flags -- [in] flags for the send() function
-
- Returns
Bytes : The number of bytes sent successfully
HTTPD_SOCK_ERR_INVALID : Invalid arguments
HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted... |
[in] data size
flags -- [in] flags for the send() function
-
- Returns
Bytes : The number of bytes received successfully
0 : Buffer length parameter is zero / connection closed by peer
HTTPD_SOCK_ERR_INVALID : Invalid arguments
HTTPD_SOCK_ERR_TIMEOUT : Timeout/interrupted while calling socket recv()
HTTPD_SOCK_ERR_FAIL... |
[in] HTTP server handle
error -- [in] Error type
handler_fn -- [in] User implemented handler function (Pass NULL to unset any previously set handler)
-
- Returns
ESP_OK : handler registered successfully
ESP_ERR_INVALID_ARG : invalid error code or server handle
-
-
esp_err_t httpd_start(httpd_handle_t *handle, const htt... |
Example usage:
// Function for stopping the webserver void stop_webserver(httpd_handle_t server) { // Ensure handle is non NULL if (server != NULL) { // Stop the httpd server httpd_stop(server); } }
- Parameters
handle -- [in] Handle to server returned by httpd_start
- Returns
ESP_OK : Server stopped successfully
ESP_E... |
[in] Handle to server returned by httpd_start
work -- [in] Pointer to the function to be executed in the HTTPD's context
arg -- [in] Pointer to the arguments that should be passed to this function
-
- Returns
ESP_OK : On successfully queueing the work
ESP_FAIL : Failure in ctrl socket
ESP_ERR_INVALID_ARG : Null argumen... |
[in] Handle to server returned by httpd_start
sockfd -- [in] The socket descriptor for which the context should be extracted.
-
- Returns
void* : Pointer to the context associated with this session
NULL : Empty context / Invalid handle / Invalid socket fd
-
-
void httpd_sess_set_ctx(httpd_handle_t handle, int sockfd, v... |
[in] Context object to assign to the session
free_fn -- [in] Function that should be called to free the context
-
-
void *httpd_sess_get_transport_ctx(httpd_handle_t handle, int sockfd)
Get session 'transport' context by socket descriptor.
This context is used by the send/receive functions, for example to manage SSL c... |
[in] Transport context object to assign to the session
free_fn -- [in] Function that should be called to free the transport context
-
-
void *httpd_get_global_user_ctx(httpd_handle_t handle)
Get HTTPD global user context (it was set in the server config struct)
- Parameters
handle -- [in] Handle to server returned by h... |
Update LRU counter for a given socket.
LRU Counters are internally associated with each session to monitor how recently a session exchanged traffic. When LRU purge is enabled, if a client is requesting for connection but maximum number of sockets/sessions is reached, then the session having the earliest LRU counter i... |
[in] Handle to server returned by httpd_start
sockfd -- [in] The socket descriptor of the session for which LRU counter is to be updated
-
- Returns
ESP_OK : Socket found and LRU counter updated
ESP_ERR_NOT_FOUND : Socket not found
ESP_ERR_INVALID_ARG : Null arguments
-
-
esp_err_t httpd_get_client_list(httpd_handle_t ... |
Prototype for HTTPDs low-level recv function.
Note
User specified recv function must handle errors internally, depending upon the set value of errno, and return specific HTTPD_SOCK_ERR_ codes, which will eventually be conveyed as return value of httpd_req_recv() function
- Param hd
[in] server instance
- Param sock... |
This function is executed upon HTTP errors generated during internal processing of an HTTP request. This is used to override the default behavior on error, which is to send HTTP error response and close the underlying socket.
Note
If implemented, the server will not automatically send out HTTP error response codes, t... |
[in] server instance
- Param sockfd
[in] session socket file descriptor
-
typedef bool (*httpd_uri_match_func_t)(const char *reference_uri, const char *uri_to_match, size_t match_upto)
Function prototype for URI matching.
- Param reference_uri
[in] URI/template with respect to which the other URI is matched
- Param u... |
Values:
-
enumerator HTTPD_500_INTERNAL_SERVER_ERROR
-
enumerator HTTPD_501_METHOD_NOT_IMPLEMENTED
-
enumerator HTTPD_505_VERSION_NOT_SUPPORTED
-
enumerator HTTPD_400_BAD_REQUEST
-
enumerator HTTPD_401_UNAUTHORIZED
-
enumerator HTTPD_403_FORBIDDEN
-
enumerator HTTPD_404_NOT_FOUND
-
enumerator HTTPD_405_METHOD_NOT_ALLOW... |
This event occurs when there are any errors during execution
-
enumerator HTTP_SERVER_EVENT_START
This event occurs when HTTP Server is started
-
enumerator HTTP_SERVER_EVENT_ON_CONNECTED
Once the HTTP Server has been connected to the client, no data exchange has been performed
-
enumerator HTTP_SERVER_EVENT_ON_HEADER
... |
HTTPS Server
Overview
This component is built on top of HTTP Server. The HTTPS server takes advantage of hook registration functions in the regular HTTP server to provide callback function for SSL session.
All documentation for HTTP Server applies also to a server you create this way.
Used APIs
The following APIs of... |
Invalid argument
ESP_FAIL: Failure to shut down server
-
Structures
-
struct esp_https_server_user_cb_arg
Callback data struct, contains the ESP-TLS connection handle and the connection state at which the callback is executed.
Public Members
-
httpd_ssl_user_cb_state_t user_cb_state
State of user callback
- httpd_ssl... |
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 9