Event management

group LWESP_EVT

Event helper functions.

Reset detected

Event helper functions for LWESP_EVT_RESET_DETECTED event

uint8_t lwesp_evt_reset_detected_is_forced(lwesp_evt_t *cc)

Check if detected reset was forced by user.

Parameters

cc[in] Event handle

Returns

1 if forced by user, 0 otherwise

Reset event

Event helper functions for LWESP_EVT_RESET event

lwespr_t lwesp_evt_reset_get_result(lwesp_evt_t *cc)

Get reset sequence operation status.

Parameters

cc[in] Event data

Returns

Member of lwespr_t enumeration

Restore event

Event helper functions for LWESP_EVT_RESTORE event

lwespr_t lwesp_evt_restore_get_result(lwesp_evt_t *cc)

Get restore sequence operation status.

Parameters

cc[in] Event data

Returns

Member of lwespr_t enumeration

Access point or station IP or MAC

Event helper functions for LWESP_EVT_AP_IP_STA event

lwesp_mac_t *lwesp_evt_ap_ip_sta_get_mac(lwesp_evt_t *cc)

Get MAC address from station.

Parameters

cc[in] Event handle

Returns

MAC address

lwesp_ip_t *lwesp_evt_ap_ip_sta_get_ip(lwesp_evt_t *cc)

Get IP address from station.

Parameters

cc[in] Event handle

Returns

IP address

Connected station to access point

Event helper functions for LWESP_EVT_AP_CONNECTED_STA event

lwesp_mac_t *lwesp_evt_ap_connected_sta_get_mac(lwesp_evt_t *cc)

Get MAC address from connected station.

Parameters

cc[in] Event handle

Returns

MAC address

Disconnected station from access point

Event helper functions for LWESP_EVT_AP_DISCONNECTED_STA event

lwesp_mac_t *lwesp_evt_ap_disconnected_sta_get_mac(lwesp_evt_t *cc)

Get MAC address from disconnected station.

Parameters

cc[in] Event handle

Returns

MAC address

Connection data received

Event helper functions for LWESP_EVT_CONN_RECV event

lwesp_pbuf_p lwesp_evt_conn_recv_get_buff(lwesp_evt_t *cc)

Get buffer from received data.

Parameters

cc[in] Event handle

Returns

Buffer handle

lwesp_conn_p lwesp_evt_conn_recv_get_conn(lwesp_evt_t *cc)

Get connection handle for receive.

Parameters

cc[in] Event handle

Returns

Connection handle

Connection data send

Event helper functions for LWESP_EVT_CONN_SEND event

lwesp_conn_p lwesp_evt_conn_send_get_conn(lwesp_evt_t *cc)

Get connection handle for data sent event.

Parameters

cc[in] Event handle

Returns

Connection handle

size_t lwesp_evt_conn_send_get_length(lwesp_evt_t *cc)

Get number of bytes sent on connection.

Parameters

cc[in] Event handle

Returns

Number of bytes sent

lwespr_t lwesp_evt_conn_send_get_result(lwesp_evt_t *cc)

Check if connection send was successful.

Parameters

cc[in] Event handle

Returns

Member of lwespr_t enumeration

Connection active

Event helper functions for LWESP_EVT_CONN_ACTIVE event

lwesp_conn_p lwesp_evt_conn_active_get_conn(lwesp_evt_t *cc)

Get connection handle.

Parameters

cc[in] Event handle

Returns

Connection handle

uint8_t lwesp_evt_conn_active_is_client(lwesp_evt_t *cc)

Check if new connection is client.

Parameters

cc[in] Event handle

Returns

1 if client, 0 otherwise

Connection close event

Event helper functions for LWESP_EVT_CONN_CLOSE event

lwesp_conn_p lwesp_evt_conn_close_get_conn(lwesp_evt_t *cc)

Get connection handle.

Parameters

cc[in] Event handle

Returns

Connection handle

uint8_t lwesp_evt_conn_close_is_client(lwesp_evt_t *cc)

Check if just closed connection was client.

Parameters

cc[in] Event handle

Returns

1 if client, 0 otherwise

uint8_t lwesp_evt_conn_close_is_forced(lwesp_evt_t *cc)

Check if connection close even was forced by user.

Parameters

cc[in] Event handle

Returns

1 if forced, 0 otherwise

lwespr_t lwesp_evt_conn_close_get_result(lwesp_evt_t *cc)

Get connection close event result.

Parameters

cc[in] Event handle

Returns

Member of lwespr_t enumeration

Connection poll

Event helper functions for LWESP_EVT_CONN_POLL event

lwesp_conn_p lwesp_evt_conn_poll_get_conn(lwesp_evt_t *cc)

Get connection handle.

Parameters

cc[in] Event handle

Returns

Connection handle

Connection error

Event helper functions for LWESP_EVT_CONN_ERROR event

lwespr_t lwesp_evt_conn_error_get_error(lwesp_evt_t *cc)

Get connection error type.

Parameters

cc[in] Event handle

Returns

Member of lwespr_t enumeration

lwesp_conn_type_t lwesp_evt_conn_error_get_type(lwesp_evt_t *cc)

Get connection type.

Parameters

cc[in] Event handle

Returns

Member of lwespr_t enumeration

const char *lwesp_evt_conn_error_get_host(lwesp_evt_t *cc)

Get connection host.

Parameters

cc[in] Event handle

Returns

Host name for connection

lwesp_port_t lwesp_evt_conn_error_get_port(lwesp_evt_t *cc)

Get connection port.

Parameters

cc[in] Event handle

Returns

Host port number

void *lwesp_evt_conn_error_get_arg(lwesp_evt_t *cc)

Get user argument.

Parameters

cc[in] Event handle

Returns

User argument

List access points

Event helper functions for LWESP_EVT_STA_LIST_AP event

lwespr_t lwesp_evt_sta_list_ap_get_result(lwesp_evt_t *cc)

Get command success result.

Parameters

cc[in] Event handle

Returns

Member of lwespr_t enumeration

lwesp_ap_t *lwesp_evt_sta_list_ap_get_aps(lwesp_evt_t *cc)

Get access points.

Parameters

cc[in] Event handle

Returns

Pointer to lwesp_ap_t with first access point description

size_t lwesp_evt_sta_list_ap_get_length(lwesp_evt_t *cc)

Get number of access points found.

Parameters

cc[in] Event handle

Returns

Number of access points found

Join access point

Event helper functions for LWESP_EVT_STA_JOIN_AP event

lwespr_t lwesp_evt_sta_join_ap_get_result(lwesp_evt_t *cc)

Get command success result.

Parameters

cc[in] Event handle

Returns

Member of lwespr_t enumeration

Get access point info

Event helper functions for LWESP_EVT_STA_INFO_AP event

lwespr_t lwesp_evt_sta_info_ap_get_result(lwesp_evt_t *cc)

Get command result.

Parameters

cc[in] Event handle

Returns

Member of lwespr_t enumeration

const char *lwesp_evt_sta_info_ap_get_ssid(lwesp_evt_t *cc)

Get current AP name.

Parameters

cc[in] Event handle

Returns

AP name

lwesp_mac_t lwesp_evt_sta_info_ap_get_mac(lwesp_evt_t *cc)

Get current AP MAC address.

Parameters

cc[in] Event handle

Returns

AP MAC address

uint8_t lwesp_evt_sta_info_ap_get_channel(lwesp_evt_t *cc)

Get current AP channel.

Parameters

cc[in] Event handle

Returns

AP channel

int16_t lwesp_evt_sta_info_ap_get_rssi(lwesp_evt_t *cc)

Get current AP rssi.

Parameters

cc[in] Event handle

Returns

AP rssi

Get host address by name

Event helper functions for LWESP_EVT_DNS_HOSTBYNAME event

lwespr_t lwesp_evt_dns_hostbyname_get_result(lwesp_evt_t *cc)

Get resolve result.

Parameters

cc[in] Event handle

Returns

Member of lwespr_t enumeration

const char *lwesp_evt_dns_hostbyname_get_host(lwesp_evt_t *cc)

Get hostname used to resolve IP address.

Parameters

cc[in] Event handle

Returns

Hostname

lwesp_ip_t *lwesp_evt_dns_hostbyname_get_ip(lwesp_evt_t *cc)

Get IP address from DNS function.

Parameters

cc[in] Event handle

Returns

IP address

Ping

Event helper functions for LWESP_EVT_PING event

lwespr_t lwesp_evt_ping_get_result(lwesp_evt_t *cc)

Get ping status.

Parameters

cc[in] Event handle

Returns

Member of lwespr_t enumeration

const char *lwesp_evt_ping_get_host(lwesp_evt_t *cc)

Get hostname used to ping.

Parameters

cc[in] Event handle

Returns

Hostname

uint32_t lwesp_evt_ping_get_time(lwesp_evt_t *cc)

Get time required for ping.

Parameters

cc[in] Event handle

Returns

Ping time

Server

Event helper functions for LWESP_EVT_SERVER event

lwespr_t lwesp_evt_server_get_result(lwesp_evt_t *cc)

Get server command result.

Parameters

cc[in] Event handle

Returns

Member of lwespr_t enumeration

lwesp_port_t lwesp_evt_server_get_port(lwesp_evt_t *cc)

Get port for server operation.

Parameters

cc[in] Event handle

Returns

Server port

uint8_t lwesp_evt_server_is_enable(lwesp_evt_t *cc)

Check if operation was to enable or disable server.

Parameters

cc[in] Event handle

Returns

1 if enable, 0 otherwise

Typedefs

typedef lwespr_t (*lwesp_evt_fn)(struct lwesp_evt *evt)

Event function prototype.

Parameters

evt[in] Callback event data

Returns

lwespOK on success, member of lwespr_t otherwise

Enums

enum lwesp_evt_type_t

List of possible callback types received to user.

Values:

enumerator LWESP_EVT_INIT_FINISH

Initialization has been finished at this point

enumerator LWESP_EVT_RESET_DETECTED

Device reset detected

enumerator LWESP_EVT_RESET

Device reset operation finished

enumerator LWESP_EVT_RESTORE

Device restore operation finished

enumerator LWESP_EVT_CMD_TIMEOUT

Timeout on command. When application receives this event, it may reset system as there was (maybe) a problem in device

enumerator LWESP_EVT_DEVICE_PRESENT

Notification when device present status changes

enumerator LWESP_EVT_AT_VERSION_NOT_SUPPORTED

Library does not support firmware version on ESP device.

enumerator LWESP_EVT_CONN_RECV

Connection data received

enumerator LWESP_EVT_CONN_SEND

Connection data send

enumerator LWESP_EVT_CONN_ACTIVE

Connection just became active

enumerator LWESP_EVT_CONN_ERROR

Client connection start was not successful

enumerator LWESP_EVT_CONN_CLOSE

Connection close event. Check status if successful

enumerator LWESP_EVT_CONN_POLL

Poll for connection if there are any changes

enumerator LWESP_EVT_SERVER

Server status changed

enumerator LWESP_EVT_WIFI_CONNECTED

Station just connected to AP

enumerator LWESP_EVT_WIFI_GOT_IP

Station has valid IP. When this event is received to application, no IP has been read from device. Stack will proceed with IP read from device and will later send LWESP_EVT_WIFI_IP_ACQUIRED event

enumerator LWESP_EVT_WIFI_DISCONNECTED

Station just disconnected from AP

enumerator LWESP_EVT_WIFI_IP_ACQUIRED

Station IP address acquired. At this point, valid IP address has been received from device. Application may use lwesp_sta_copy_ip function to read it

enumerator LWESP_EVT_STA_LIST_AP

Station listed APs event

enumerator LWESP_EVT_STA_JOIN_AP

Join to access point

enumerator LWESP_EVT_STA_INFO_AP

Station AP info (name, mac, channel, rssi)

enumerator LWESP_EVT_AP_CONNECTED_STA

New station just connected to ESP’s access point

enumerator LWESP_EVT_AP_DISCONNECTED_STA

New station just disconnected from ESP’s access point

enumerator LWESP_EVT_AP_IP_STA

New station just received IP from ESP’s access point

enumerator LWESP_EVT_DNS_HOSTBYNAME

DNS domain service finished

enumerator LWESP_EVT_PING

PING service finished

Functions

lwespr_t lwesp_evt_register(lwesp_evt_fn fn)

Register event function for global (non-connection based) events.

Parameters

fn[in] Callback function to call on specific event

Returns

lwespOK on success, member of lwespr_t enumeration otherwise

lwespr_t lwesp_evt_unregister(lwesp_evt_fn fn)

Unregister callback function for global (non-connection based) events.

Note

Function must be first registered using lwesp_evt_register

Parameters

fn[in] Callback function to remove from event list

Returns

lwespOK on success, member of lwespr_t enumeration otherwise

lwesp_evt_type_t lwesp_evt_get_type(lwesp_evt_t *cc)

Get event type.

Parameters

cc[in] Event handle

Returns

Event type. Member of lwesp_evt_type_t enumeration

struct lwesp_evt_t
#include <lwesp_typedefs.h>

Global callback structure to pass as parameter to callback function.

Public Members

lwesp_evt_type_t type

Callback type

uint8_t forced

Set to 1 if reset forced by user

Set to 1 if connection action was forced when active: 1 = CLIENT, 0 = SERVER when closed, 1 = CMD, 0 = REMOTE

struct lwesp_evt_t::[anonymous]::[anonymous] reset_detected

Reset occurred. Use with LWESP_EVT_RESET_DETECTED event

lwespr_t res

Reset operation result

Restore operation result

Send data result

Result of close event. Set to lwespOK on success

Status of command

Result of command

struct lwesp_evt_t::[anonymous]::[anonymous] reset

Reset sequence finish. Use with LWESP_EVT_RESET event

struct lwesp_evt_t::[anonymous]::[anonymous] restore

Restore sequence finish. Use with LWESP_EVT_RESTORE event

lwesp_conn_p conn

Connection where data were received

Connection where data were sent

Pointer to connection

Set connection pointer

lwesp_pbuf_p buff

Pointer to received data

struct lwesp_evt_t::[anonymous]::[anonymous] conn_data_recv

Network data received. Use with LWESP_EVT_CONN_RECV event

size_t sent

Number of bytes sent on connection

struct lwesp_evt_t::[anonymous]::[anonymous] conn_data_send

Data send. Use with LWESP_EVT_CONN_SEND event

const char *host

Host to use for connection

Host name for DNS lookup

Host name for ping

lwesp_port_t port

Remote port used for connection

Server port number

lwesp_conn_type_t type

Connection type

void *arg

Connection user argument

lwespr_t err

Error value

struct lwesp_evt_t::[anonymous]::[anonymous] conn_error

Client connection start error. Use with LWESP_EVT_CONN_ERROR event

uint8_t client

Set to 1 if connection is/was client mode

struct lwesp_evt_t::[anonymous]::[anonymous] conn_active_close

Process active and closed statuses at the same time. Use with LWESP_EVT_CONN_ACTIVE or LWESP_EVT_CONN_CLOSE events

struct lwesp_evt_t::[anonymous]::[anonymous] conn_poll

Polling active connection to check for timeouts. Use with LWESP_EVT_CONN_POLL event

uint8_t en

Status to enable/disable server

struct lwesp_evt_t::[anonymous]::[anonymous] server

Server change event. Use with LWESP_EVT_SERVER event

lwesp_ap_t *aps

Pointer to access points

size_t len

Number of access points found

struct lwesp_evt_t::[anonymous]::[anonymous] sta_list_ap

Station list access points. Use with LWESP_EVT_STA_LIST_AP event

struct lwesp_evt_t::[anonymous]::[anonymous] sta_join_ap

Join to access point. Use with LWESP_EVT_STA_JOIN_AP event

lwesp_sta_info_ap_t *info

AP info of current station

struct lwesp_evt_t::[anonymous]::[anonymous] sta_info_ap

Current AP informations. Use with LWESP_EVT_STA_INFO_AP event

lwesp_mac_t *mac

Station MAC address

struct lwesp_evt_t::[anonymous]::[anonymous] ap_conn_disconn_sta

A new station connected or disconnected to ESP’s access point. Use with LWESP_EVT_AP_CONNECTED_STA or LWESP_EVT_AP_DISCONNECTED_STA events

lwesp_ip_t *ip

Station IP address

Pointer to IP result

struct lwesp_evt_t::[anonymous]::[anonymous] ap_ip_sta

Station got IP address from ESP’s access point. Use with LWESP_EVT_AP_IP_STA event

struct lwesp_evt_t::[anonymous]::[anonymous] dns_hostbyname

DNS domain service finished. Use with LWESP_EVT_DNS_HOSTBYNAME event

uint32_t time

Time required for ping. Valid only if operation succedded

struct lwesp_evt_t::[anonymous]::[anonymous] ping

Ping finished. Use with LWESP_EVT_PING event

union lwesp_evt_t::[anonymous] evt

Callback event union