data
stringlengths
512
2.99k
Set wake window for esp_now to wake up in interval unit. - Attention 1. This configuration could work at connected status. When ESP_WIFI_STA_DISCONNECTED_PM_ENABLE is enabled, this configuration could work at disconnected status. - Attention 2. Default value is the maximum. - Parameters window -- Milliseconds would the chip keep waked each interval, from 0 to 65535. - Returns ESP_OK : succeed ESP_ERR_ESPNOW_NOT_INIT : ESPNOW is not initialized - Structures - struct esp_now_peer_info ESPNOW peer information parameters.
Calling Wi-Fi API There can be instances in which an application may want to directly call Wi-Fi API whilst using ESP-WIFI-MESH. For example, an application may want to manually scan for neighboring APs. However, self-organized networking must be disabled before the application calls any Wi-Fi APIs. This will prevent the ESP-WIFI-MESH stack from attempting to call any Wi-Fi APIs and potentially interfering with the application's calls. Therefore, application calls to Wi-Fi APIs should be placed in between calls of esp_mesh_set_self_organized() which disable and enable self-organized networking. The following code snippet demonstrates how an application can safely call esp_wifi_scan_start() whilst using ESP-WIFI-MESH. //Disable self-organized networking esp_mesh_set_self_organized(0, 0); //Stop any scans already in progress esp_wifi_scan_stop(); //Manually start scan. Will automatically stop when run to completion esp_wifi_scan_start(); //Process scan results ... //Re-enable self-organized networking if still connected esp_mesh_set_self_organized(1, 0); ... //Re-enable self-organized networking if non-root and disconnected esp_mesh_set_self_organized(1, 1); ... //Re-enable self-organized networking if root and disconnected esp_mesh_set_self_organized(1, 0); //Do not select new parent esp_mesh_connect(); //Manually reconnect to router Application Examples ESP-IDF contains these ESP-WIFI-MESH example projects: The Internal Communication Example demonstrates how to set up a ESP-WIFI-MESH network and have the root node send a data packet to every node within the network. The Manual Networking Example demonstrates how to use ESP-WIFI-MESH without the self-organizing features. This example shows how to program a node to manually scan for a list of potential parent nodes and select a parent node based on custom criteria. API Reference Header File This header file can be included with: #include "esp_mesh.h" This header file is a part of the API provided by the esp_wificomponent. To declare that your component depends on esp_wifi, add the following to your CMakeLists.txt: REQUIRES esp_wifi or PRIV_REQUIRES esp_wifi Functions - esp_err_t esp_mesh_init(void) Mesh initialization.
[in] wait time if a packet isn't immediately available (0:no wait, portMAX_DELAY:wait forever) flag -- [out] bitmap for data received MESH_DATA_FROMDS represents data from external IP network MESH_DATA_TODS represents data directed upward within the mesh network - opt -- [out] options desired to receive MESH_OPT_RECV_DS_ADDR attaches the DS address - opt_count -- [in] option count desired to receive Currently, this API only takes one option, so opt_count is only supported to be 1. - - - Returns ESP_OK ESP_ERR_MESH_ARGUMENT ESP_ERR_MESH_NOT_START ESP_ERR_MESH_TIMEOUT ESP_ERR_MESH_DISCARD - - esp_err_t esp_mesh_recv_toDS(mesh_addr_t *from, mesh_addr_t *to, mesh_data_t *data, int timeout_ms, int *flag, mesh_opt_t opt [], int opt_count) Receive a packet targeted to external IP network. Root uses this API to receive packets destined to external IP network Root forwards the received packets to the final destination via socket. If no socket connection is ready to send out the received packets and this esp_mesh_recv_toDS() hasn't been called by applications, packets from the whole mesh network will be pending in toDS queue. Use esp_mesh_get_rx_pending() to check the number of packets available in the queue waiting to be received by applications in case of running out of memory in the root. Using esp_mesh_set_xon_qsize() users may configure the RX queue size, default:32. If this size is too large, and esp_mesh_recv_toDS() isn't called in time, there is a risk that a great deal of memory is occupied by the pending packets. If this size is too small, it will impact the efficiency on upstream. How to decide this value depends on the specific application scenarios. flag could be MESH_DATA_TODS. - Attention This API is only called by the root. - Parameters from -- [out] the address of the original source of the packet to -- [out] the address contains remote IP address and port (IPv4:PORT) data -- [out] pointer to the received packet Contain the protocol and applications should follow it to parse the data. - timeout_ms -- [in] wait time if a packet isn't immediately available (0:no wait, portMAX_DELAY:wait forever) flag -- [out] bitmap for data received MESH_DATA_TODS represents the received data target to external IP network. Root shall forward this data to external IP network via the association with router. - opt -- [out] options desired to receive opt_count -- [in] option count desired to receive - - Returns ESP_OK ESP_ERR_MESH_ARGUMENT ESP_ERR_MESH_NOT_START ESP_ERR_MESH_TIMEOUT ESP_ERR_MESH_DISCARD ESP_ERR_MESH_RECV_RELEASE - - - esp_err_t
Nodes with the same mesh ID can communicate with each other. Regarding to the router configuration, if the router is hidden, BSSID field is mandatory. If BSSID field isn't set and there exists more than one router with same SSID, there is a risk that more roots than one connected with different BSSID will appear. It means more than one mesh network is established with the same mesh ID. Root conflict function could eliminate redundant roots connected with the same BSSID, but couldn't handle roots connected with different BSSID. Because users might have such requirements of setting up routers with same SSID for the future replacement. But in that case, if the above situations happen, please make sure applications implement forward functions on the root to guarantee devices in different mesh networks can communicate with each other.
- Attention This API shall be called before mesh is started after mesh is initialized. - Parameters config -- [in] pointer to mesh stack configuration - Returns ESP_OK ESP_ERR_MESH_ARGUMENT ESP_ERR_MESH_NOT_ALLOWED - - - esp_err_t esp_mesh_get_config(mesh_cfg_t *config) Get mesh stack configuration. - Parameters config -- [out] pointer to mesh stack configuration - Returns ESP_OK ESP_ERR_MESH_ARGUMENT - - esp_err_t esp_mesh_set_router(const mesh_router_t *router) Get router configuration. - Attention This API is used to dynamically modify the router configuration after mesh is configured. - Parameters router -- [in] pointer to router configuration - Returns ESP_OK ESP_ERR_MESH_ARGUMENT - - esp_err_t esp_mesh_get_router(mesh_router_t *router) Get router configuration. - Parameters router -- [out] pointer to router configuration - Returns ESP_OK ESP_ERR_MESH_ARGUMENT - - esp_err_t esp_mesh_set_id(const mesh_addr_t
- Attention This API is used to dynamically modify the mesh network ID. - Parameters id -- [in] pointer to mesh network ID - Returns ESP_OK ESP_ERR_MESH_ARGUMENT: invalid argument - - esp_err_t esp_mesh_get_id(mesh_addr_t *id) Get mesh network ID. - Parameters id -- [out] pointer to mesh network ID - Returns ESP_OK ESP_ERR_MESH_ARGUMENT - - esp_err_t esp_mesh_set_type(mesh_type_t type) Designate device type over the mesh network. MESH_IDLE: designates a device as a self-organized node for a mesh network MESH_ROOT: designates the root node for a mesh network MESH_LEAF: designates a device as a standalone Wi-Fi station that connects to a parent MESH_STA: designates a device as a standalone Wi-Fi station that connects to a router - Parameters type -- [in] device type - Returns ESP_OK ESP_ERR_MESH_NOT_ALLOWED - - - mesh_type_t esp_mesh_get_type(void) Get device type over mesh network. - Attention This API shall be called after having received the event MESH_EVENT_PARENT_CONNECTED. - Returns mesh type - esp_err_t esp_mesh_set_max_layer(int max_layer) Set network max layer value. for tree topology, the max is 25. for chain topology, the max is 1000. Network max layer limits the max hop count. - Attention This API shall be called before mesh is started. - Parameters max_layer -- [in] max layer value - Returns ESP_OK ESP_ERR_MESH_ARGUMENT ESP_ERR_MESH_NOT_ALLOWED - - - int esp_mesh_get_max_layer(void) Get max layer value. - Returns max layer value - esp_err_t esp_mesh_set_ap_password(const uint8_t *pwd, int len) Set mesh softAP password. -
Set vote percentage threshold for approval of being a root (default:0.9) During the networking, only obtaining vote percentage reaches this threshold, the device could be a root. - Attention This API shall be called before mesh is started. - Parameters percentage -- [in] vote percentage threshold - Returns ESP_OK ESP_FAIL - - - float esp_mesh_get_vote_percentage(void) Get vote percentage threshold for approval of being a root. - Returns percentage threshold - esp_err_t esp_mesh_set_ap_assoc_expire(int seconds) Set mesh softAP associate expired time (default:10 seconds) If mesh softAP hasn't received any data from an associated child within this time, mesh softAP will take this child inactive and disassociate it. If mesh softAP is encrypted, this value should be set a greater value, such as 30 seconds. - Parameters seconds -- [in] the expired time - Returns ESP_OK ESP_FAIL - - - int esp_mesh_get_ap_assoc_expire(void) Get mesh softAP associate expired time. - Returns seconds - int esp_mesh_get_total_node_num(void) Get total number of devices in current network (including the root) - Attention The returned value might be incorrect when the network is changing . - Returns total number of devices (including the root) - int esp_mesh_get_routing_table_size(void) Get the number of devices in this device's sub-network (including self) - Returns the number of devices over this device's sub-network (including self) - esp_err_t esp_mesh_get_routing_table(mesh_addr_t *mac, int len, int *size) Get routing table of this device's sub-network (including itself) - Parameters mac --
Post the toDS state to the mesh stack. - Attention This API is only for the root. - Parameters reachable -- [in] this state represents whether the root is able to access external IP network - Returns ESP_OK ESP_FAIL - - esp_err_t esp_mesh_get_tx_pending(mesh_tx_pending_t *pending) Return the number of packets pending in the queue waiting to be sent by the mesh stack. - Parameters pending -- [out] pointer to the TX pending - Returns ESP_OK ESP_FAIL - - esp_err_t esp_mesh_get_rx_pending(mesh_rx_pending_t *pending) Return the number of packets available in the queue waiting to be received by applications. - Parameters pending -- [out] pointer to the RX pending - Returns ESP_OK ESP_FAIL - - int esp_mesh_available_txupQ_num(const mesh_addr_t *addr, uint32_t *xseqno_in) Return the number of packets could be accepted from the specified address. - Parameters addr -- [in] self address or an associate children address xseqno_in -- [out] sequence number of the last received packet from the specified address - - Returns the number of upQ for a certain address - esp_err_t esp_mesh_set_xon_qsize(int qsize) Set the number of RX queue for the node, the average number of window allocated to one of its child node is: wnd = xon_qsize /
However, the window of each child node is not strictly equal to the average value, it is affected by the traffic also. - Attention This API shall be called before mesh is started. - Parameters qsize -- [in] default:32 (min:16) - Returns ESP_OK ESP_FAIL - - int esp_mesh_get_xon_qsize(void) Get queue size. - Returns the number of queue - esp_err_t esp_mesh_allow_root_conflicts(bool allowed) Set whether allow more than one root existing in one network. - Parameters allowed -- [in] allow or not - Returns ESP_OK ESP_WIFI_ERR_NOT_INIT ESP_WIFI_ERR_NOT_START - - bool esp_mesh_is_root_conflicts_allowed(void) Check whether allow more than one root to exist in one network. - Returns true/false - esp_err_t esp_mesh_set_group_id(const mesh_addr_t *addr, int num) Set group ID addresses. - Parameters addr -- [in] pointer to new group ID addresses num -- [in] the number of group ID addresses - - Returns ESP_OK ESP_MESH_ERR_ARGUMENT - - esp_err_t esp_mesh_delete_group_id(const mesh_addr_t *addr, int num) Delete group ID addresses. - Parameters addr -- [in] pointer to deleted group ID address num -- [in] the number of group ID addresses - - Returns ESP_OK ESP_MESH_ERR_ARGUMENT - - int esp_mesh_get_group_num(void) Get the number of group ID addresses. - Returns the number of group ID addresses - esp_err_t esp_mesh_get_group_list(mesh_addr_t *addr, int num) Get group ID addresses. - Parameters addr -- [out] pointer to group ID addresses num -- [in] the number of group ID addresses - - Returns ESP_OK ESP_MESH_ERR_ARGUMENT - - bool esp_mesh_is_my_group(const mesh_addr_t *addr) Check whether the specified group address is my group. - Returns true/false - esp_err_t esp_mesh_set_capacity_num(int num) Set mesh network capacity (max:1000, default:300) - Attention This API shall be called before mesh is started. - Parameters num -- [in] mesh network capacity - Returns ESP_OK ESP_ERR_MESH_NOT_ALLOWED ESP_MESH_ERR_ARGUMENT - - int esp_mesh_get_capacity_num(void) Get mesh network capacity. - Returns mesh network capacity - esp_err_t esp_mesh_set_ie_crypto_funcs(const mesh_crypto_funcs_t *crypto_funcs) Set mesh IE crypto functions. - Attention This API can be called at any time after mesh is configured. - Parameters crypto_funcs -- [in] crypto functions for mesh IE If crypto_funcs is set to NULL, mesh IE is no longer encrypted. - - Returns ESP_OK - - esp_err_t esp_mesh_set_ie_crypto_key(const char *key, int len) Set mesh IE crypto key. - Attention This API can be called at any time after mesh is configured. - Parameters key -- [in] ASCII crypto key len -- [in] length in bytes, range:8~64 - - Returns ESP_OK ESP_MESH_ERR_ARGUMENT - - esp_err_t esp_mesh_get_ie_crypto_key(char *key, int len) Get mesh IE crypto key. - Parameters key -- [out] ASCII crypto key len --
[in] length in bytes, range:8~64 - - Returns ESP_OK ESP_MESH_ERR_ARGUMENT - - esp_err_t esp_mesh_set_root_healing_delay(int delay_ms) Set delay time before starting root healing. - Parameters delay_ms -- [in] delay time in milliseconds - Returns ESP_OK - - int esp_mesh_get_root_healing_delay(void) Get delay time before network starts root healing. - Returns delay time in milliseconds - esp_err_t esp_mesh_fix_root(bool enable) Enable network Fixed Root Setting. Enabling fixed root disables automatic election of the root node via voting. All devices in the network shall use the same Fixed Root Setting (enabled or disabled). If Fixed Root is enabled, users should make sure a root node is designated for the network. - Parameters enable -- [in] enable or not - Returns ESP_OK - - - bool esp_mesh_is_root_fixed(void) Check whether network Fixed Root Setting is enabled. Enable/disable network Fixed Root Setting by API esp_mesh_fix_root(). Network Fixed Root Setting also changes with the "flag" value in parent networking IE. - Returns true/false - - esp_err_t esp_mesh_set_parent(const wifi_config_t *parent, const mesh_addr_t *parent_mesh_id, mesh_type_t my_type, int my_layer) Set a specified parent for the device. - Attention This API can be called at any time after mesh is configured. - Parameters parent -- [in] parent configuration, the SSID and the channel of the parent are mandatory. If the BSSID is set, make sure that the SSID and BSSID represent the same parent, otherwise the device will never find this specified parent. - parent_mesh_id -- [in] parent mesh ID, If this value is not set, the original mesh ID is used. - my_type -- [in] mesh type MESH_STA is not supported.
If my_type is set MESH_LEAF, the device becomes a standalone Wi-Fi station and no longer has the ability to extend the network. - - - Returns ESP_OK ESP_ERR_ARGUMENT ESP_ERR_MESH_NOT_CONFIG - - esp_err_t esp_mesh_scan_get_ap_ie_len(int *len) Get mesh networking IE length of one AP. - Parameters len -- [out] mesh networking IE length - Returns ESP_OK ESP_ERR_WIFI_NOT_INIT ESP_ERR_INVALID_ARG ESP_ERR_WIFI_FAIL - - esp_err_t esp_mesh_scan_get_ap_record(wifi_ap_record_t *ap_record, void *buffer) Get AP record. - Attention Different from esp_wifi_scan_get_ap_records(), this API only gets one of APs scanned each time.
[out] pointer to the mesh networking IE of this AP - - Returns ESP_OK ESP_ERR_WIFI_NOT_INIT ESP_ERR_INVALID_ARG ESP_ERR_WIFI_FAIL - - esp_err_t esp_mesh_flush_upstream_packets(void) Flush upstream packets pending in to_parent queue and to_parent_p2p queue. - Returns ESP_OK - - esp_err_t esp_mesh_get_subnet_nodes_num(const mesh_addr_t * child_mac, int *nodes_num) Get the number of nodes in the subnet of a specific child. - Parameters child_mac -- [in] an associated child address of this device nodes_num -- [out] pointer to the number of nodes in the subnet of a specific child - - Returns ESP_OK ESP_ERR_MESH_NOT_START ESP_ERR_MESH_ARGUMENT - - esp_err_t esp_mesh_get_subnet_nodes_list(const mesh_addr_t *child_mac, mesh_addr_t *nodes, int nodes_num) Get nodes in the subnet of a specific child. - Parameters child_mac -- [in] an associated child address of this device nodes -- [out] pointer to nodes in the subnet of a specific child nodes_num -- [in] the number of nodes in the subnet of a specific child - - Returns ESP_OK ESP_ERR_MESH_NOT_START ESP_ERR_MESH_ARGUMENT - - esp_err_t esp_mesh_switch_channel(const uint8_t *new_bssid, int csa_newchan, int csa_count)
Cause the root device to add Channel Switch Announcement Element (CSA IE) to beacon. Set the new channel Set how many beacons with CSA IE will be sent before changing a new channel Enable the channel switch function - Attention This API is only called by the root. - Parameters new_bssid -- [in] the new router BSSID if the router changes csa_newchan -- [in] the new channel number to which the whole network is moving csa_count -- [in] channel switch period(beacon count), unit is based on beacon interval of its softAP, the default value is 15. - - Returns ESP_OK - - - esp_err_t
The default value is MESH_TOPO_TREE. MESH_TOPO_CHAIN supports up to 1000 layers - Attention This API shall be called before mesh is started. - Parameters topo -- [in] MESH_TOPO_TREE or MESH_TOPO_CHAIN - Returns ESP_OK ESP_MESH_ERR_ARGUMENT ESP_ERR_MESH_NOT_ALLOWED - - - esp_mesh_topology_t esp_mesh_get_topology(void) Get mesh topology. - Returns MESH_TOPO_TREE or MESH_TOPO_CHAIN - esp_err_t esp_mesh_enable_ps(void) Enable mesh Power Save function. - Attention This API shall be called before mesh is started. - Returns ESP_OK ESP_ERR_WIFI_NOT_INIT ESP_ERR_MESH_NOT_ALLOWED - - esp_err_t esp_mesh_disable_ps(void) Disable mesh Power Save function. - Attention This API shall be called before mesh is started. - Returns ESP_OK ESP_ERR_WIFI_NOT_INIT ESP_ERR_MESH_NOT_ALLOWED - - bool esp_mesh_is_ps_enabled(void) Check whether the mesh Power Save function is enabled. - Returns true/false - bool esp_mesh_is_device_active(void) Check whether the device is in active state. If the device is not in active state, it will neither transmit nor receive frames. - Returns true/false - - esp_err_t esp_mesh_set_active_duty_cycle(int dev_duty, int dev_duty_type) Set the device duty cycle and type. The range of dev_duty values is 1 to 100. The default value is 10. dev_duty = 100, the PS will be stopped. dev_duty is better to not less than 5. dev_duty_type could be MESH_PS_DEVICE_DUTY_REQUEST or MESH_PS_DEVICE_DUTY_DEMAND. If dev_duty_type is set to MESH_PS_DEVICE_DUTY_REQUEST, the device will use a nwk_duty provided by the network. If dev_duty_type is set to MESH_PS_DEVICE_DUTY_DEMAND, the device will use the specified dev_duty. - Attention This API can be called at any time after mesh is started. - Parameters dev_duty --
The range of nwk_duty values is 1 to 100. The default value is 10. nwk_duty is the network duty cycle the entire network or the up-link path will use. A device that successfully sets the nwk_duty is known as a NWK-DUTY-MASTER. duration_mins specifies how long the specified nwk_duty will be used. Once duration_mins expires, the root will take over as the NWK-DUTY-MASTER. If an existing NWK-DUTY-MASTER leaves the network, the root will take over as the NWK-DUTY-MASTER again. duration_mins = (-1) represents nwk_duty will be used until a new NWK-DUTY-MASTER with a different nwk_duty appears. Only the root can set duration_mins to (-1). If applied_rule is set to MESH_PS_NETWORK_DUTY_APPLIED_ENTIRE, the nwk_duty will be used by the entire network. If applied_rule is set to MESH_PS_NETWORK_DUTY_APPLIED_UPLINK, the nwk_duty will only be used by the up-link path nodes. The root does not accept MESH_PS_NETWORK_DUTY_APPLIED_UPLINK. A nwk_duty with duration_mins(-1) set by the root is the default network duty cycle used by the entire network. - Attention This API can be called at any time after mesh is started. In self-organized network, if this API is called before mesh is started in all devices, (1)nwk_duty shall be set to the same value for all devices; (2)duration_mins shall be set to (-1); (3)applied_rule shall be set to MESH_PS_NETWORK_DUTY_APPLIED_ENTIRE; after the voted root appears, the root will become the NWK-DUTY-MASTER and broadcast the nwk_duty and its identity of NWK-DUTY-MASTER. If the root is specified (FIXED-ROOT), call this API in the root to provide a default nwk_duty for the entire network. After joins the network, any device can call this API to change the nwk_duty, duration_mins or applied_rule. - - Parameters nwk_duty --
[in] network duty cycle duration_mins -- [in] duration (unit: minutes) applied_rule -- [in] only support MESH_PS_NETWORK_DUTY_APPLIED_ENTIRE - - Returns ESP_OK ESP_FAIL - - - esp_err_t esp_mesh_get_network_duty_cycle(int *nwk_duty, int *duration_mins, int *dev_duty_type, int *applied_rule) Get the network duty cycle, duration, type and rule. - Parameters nwk_duty -- [out] current network duty cycle duration_mins -- [out] the duration of current nwk_duty dev_duty_type -- [out] if it includes MESH_PS_DEVICE_DUTY_MASTER, this device is the current NWK-DUTY-MASTER.
Public Members - int scan_times scan times being through - int scan_times - struct mesh_event_layer_change_t Layer change information. Public Members - uint16_t new_layer new layer - uint16_t new_layer - struct mesh_event_vote_started_t vote started information Public Members - int reason vote reason, vote could be initiated by children or by the root itself - int attempts max vote attempts before stopped - mesh_addr_t rc_addr root address specified by users via API esp_mesh_waive_root() - int reason - struct mesh_event_find_network_t find a mesh network that this device can join - struct mesh_event_root_switch_req_t Root switch request information. Public Members - int reason root switch reason, generally root switch is initialized by users via API esp_mesh_waive_root() - mesh_addr_t rc_addr the address of root switch requester - int reason - struct mesh_event_root_conflict_t Other powerful root address. - struct mesh_event_routing_table_change_t Routing table change. - struct mesh_event_scan_done_t Scan done event information. Public Members - uint8_t number the number of APs scanned - uint8_t number - struct mesh_event_network_state_t Network state information. Public Members - bool is_rootless whether current mesh network has a root - bool is_rootless - struct mesh_event_ps_duty_t PS duty information. Public Members - uint8_t duty parent or child duty - mesh_event_child_connected_t child_connected child info - uint8_t duty - struct mesh_opt_t Mesh option. - struct mesh_data_t Mesh data for esp_mesh_send() and esp_mesh_recv() Public Members - uint8_t *data data - uint16_t size data size - mesh_proto_t proto data protocol - mesh_tos_t tos data type of service - uint8_t *data - struct mesh_router_t Router configuration. Public Members - uint8_t
ssid[32] SSID - uint8_t ssid_len length of SSID - uint8_t bssid[6] BSSID, if this value is specified, users should also specify "allow_router_switch". - uint8_t password[64] password - bool allow_router_switch if the BSSID is specified and this value is also set, when the router of this specified BSSID fails to be found after "fail" (mesh_attempts_t) times, the whole network is allowed to switch to another router with the same SSID. The new router might also be on a different channel. The default value is false. There is a risk that if the password is different between the new switched router and the previous one, the mesh network could be established but the root will never connect to the new switched router. - uint8_t
ssid[32] - struct mesh_ap_cfg_t Mesh softAP configuration. - struct mesh_cfg_t Mesh initialization configuration. Public Members - uint8_t channel channel, the mesh network on - bool allow_channel_switch if this value is set, when "fail" (mesh_attempts_t) times is reached, device will change to a full channel scan for a network that could join. The default value is false. - mesh_addr_t mesh_id mesh network identification - mesh_router_t router router configuration - mesh_ap_cfg_t mesh_ap mesh softAP configuration - const mesh_crypto_funcs_t *crypto_funcs crypto functions - uint8_t channel - struct mesh_vote_t Vote. Public Members - float percentage vote percentage threshold for approval of being a root - bool is_rc_specified if true, rc_addr shall be specified (Unimplemented). if false, attempts value shall be specified to make network start root election. - mesh_rc_config_t config vote address configuration - float percentage - struct mesh_tx_pending_t The number of packets pending in the queue waiting to be sent by the mesh stack. - struct mesh_rx_pending_t The number of packets available in the queue waiting to be received by applications.
Values: - enumerator MESH_TOS_P2P provide P2P (point-to-point) retransmission on mesh stack by default - enumerator MESH_TOS_E2E provide E2E (end-to-end) retransmission on mesh stack (Unimplemented) - enumerator MESH_TOS_DEF no retransmission on mesh stack - enumerator MESH_TOS_P2P - enum mesh_vote_reason_t Vote reason. Values: - enumerator MESH_VOTE_REASON_ROOT_INITIATED vote is initiated by the root - enumerator MESH_VOTE_REASON_CHILD_INITIATED vote is initiated by children - enumerator MESH_VOTE_REASON_ROOT_INITIATED - enum mesh_disconnect_reason_t Mesh disconnect reason code. Values: - enumerator MESH_REASON_CYCLIC cyclic is detected - enumerator MESH_REASON_PARENT_IDLE parent is idle - enumerator MESH_REASON_LEAF the connected device is changed to a leaf - enumerator MESH_REASON_DIFF_ID in different mesh ID - enumerator MESH_REASON_ROOTS root conflict is detected - enumerator MESH_REASON_PARENT_STOPPED parent has stopped the mesh - enumerator MESH_REASON_SCAN_FAIL scan fail - enumerator MESH_REASON_IE_UNKNOWN unknown IE - enumerator MESH_REASON_WAIVE_ROOT waive root - enumerator MESH_REASON_PARENT_WORSE parent with very poor RSSI - enumerator MESH_REASON_EMPTY_PASSWORD use an empty password to connect to an encrypted parent - enumerator MESH_REASON_PARENT_UNENCRYPTED connect to an unencrypted parent/router - enumerator MESH_REASON_CYCLIC - enum esp_mesh_topology_t Mesh topology. Values: - enumerator MESH_TOPO_TREE tree topology - enumerator MESH_TOPO_CHAIN chain topology - enumerator MESH_TOPO_TREE
SmartConfig The SmartConfigTM is a provisioning technology developed by TI to connect a new Wi-Fi device to a Wi-Fi network. It uses a mobile application to broadcast the network credentials from a smartphone, or a tablet, to an un-provisioned Wi-Fi device. The advantage of this technology is that the device does not need to directly know SSID or password of an Access Point (AP). This information is provided using the smartphone. This is particularly important to headless device and systems, due to their lack of a user interface. If you are looking for other options to provision your ESP32 devices, check Provisioning API. Application Example Connect ESP32 to the target AP using SmartConfig: wifi/smart_config. API Reference Header File This header file can be included with: #include "esp_smartconfig.h" This header file is a part of the API provided by the esp_wificomponent. To declare that your component depends on esp_wifi, add the following to your CMakeLists.txt: REQUIRES esp_wifi or PRIV_REQUIRES esp_wifi Functions - const char *esp_smartconfig_get_version(void) Get the version of SmartConfig. - Returns SmartConfig version const char. - - esp_err_t esp_smartconfig_start(const smartconfig_start_config_t *config) Start SmartConfig, config ESP device to connect AP.
Device sniffer special packets from the air that containing SSID and password of target AP. - Attention 1. This API can be called in station or softAP-station mode. - Attention 2. Can not call esp_smartconfig_start twice before it finish, please call esp_smartconfig_stop first. - Parameters config -- pointer to smartconfig start configure structure - Returns ESP_OK: succeed others: fail - - esp_err_t esp_smartconfig_stop(void) Stop SmartConfig, free the buffer taken by esp_smartconfig_start. - Attention Whether connect to AP succeed or not, this API should be called to free memory taken by smartconfig_start. - Returns ESP_OK: succeed others: fail - - esp_err_t esp_esptouch_set_timeout(uint8_t time_s) Set timeout of SmartConfig process. - Attention Timing starts from SC_STATUS_FIND_CHANNEL status. SmartConfig will restart if timeout. - Parameters time_s -- range 15s~255s, offset:45s. - Returns ESP_OK: succeed others: fail - - esp_err_t esp_smartconfig_set_type(smartconfig_type_t type) Set protocol type of SmartConfig. - Attention If users need to set the SmartConfig type, please set it before calling esp_smartconfig_start. - Parameters type -- Choose from the smartconfig_type_t. - Returns ESP_OK: succeed others: fail - - esp_err_t esp_smartconfig_fast_mode(bool enable) Set mode of SmartConfig. default normal mode. - Attention 1. Please call it before API esp_smartconfig_start. - Attention 2. Fast mode have corresponding APP(phone). - Attention 3. Two mode is compatible. - Parameters enable -- false-disable(default); true-enable; - Returns ESP_OK: succeed others: fail - Structures - struct smartconfig_event_got_ssid_pswd_t Argument structure for SC_EVENT_GOT_SSID_PSWD event Public Members - uint8_t
- uint8_t ssid[32] - struct smartconfig_start_config_t Configure structure for esp_smartconfig_start Macros - SMARTCONFIG_START_CONFIG_DEFAULT() Enumerations - enum smartconfig_type_t Values: - enumerator SC_TYPE_ESPTOUCH protocol: ESPTouch - enumerator SC_TYPE_AIRKISS protocol: AirKiss - enumerator SC_TYPE_ESPTOUCH_AIRKISS protocol: ESPTouch and AirKiss - enumerator SC_TYPE_ESPTOUCH_V2 protocol: ESPTouch v2 - enumerator SC_TYPE_ESPTOUCH - enum smartconfig_event_t Smartconfig event declarations Values: - enumerator SC_EVENT_SCAN_DONE Station smartconfig has finished to scan for APs - enumerator SC_EVENT_FOUND_CHANNEL Station smartconfig has found the channel of the target AP - enumerator SC_EVENT_GOT_SSID_PSWD Station smartconfig got the SSID and password - enumerator SC_EVENT_SEND_ACK_DONE Station smartconfig has sent ACK to cellphone - enumerator SC_EVENT_SCAN_DONE
Wi-Fi Easy ConnectTM (DPP) Wi-Fi Easy ConnectTM, also known as Device Provisioning Protocol (DPP) or Easy Connect, is a provisioning protocol certified by Wi-Fi Alliance. It is a secure and standardized provisioning protocol for configuration of Wi-Fi Devices. With Easy Connect, adding a new device to a network is as simple as scanning a QR Code. This reduces complexity and enhances user experience while onboarding devices without UI like Smart Home and IoT products. Unlike old protocols like Wi-Fi Protected Setup (WPS), Wi-Fi Easy Connect in corporates strong encryption through public key cryptography to ensure networks remain secure as new devices are added. Easy Connect brings many benefits in the user experience: - Simple and intuitive to use; no lengthy instructions to follow for new device setup - No need to remember and enter passwords into the device being provisioned - Works with electronic or printed QR codes, or human-readable strings - Supports both WPA2 and WPA3 networks Please refer to Wi-Fi Alliance's official page on Easy Connect for more information. ESP32 supports Enrollee mode of Easy Connect with QR Code as the provisioning method. A display is required to display this QR Code. Users can scan this QR Code using their capable device and provision the ESP32 to their Wi-Fi network. The provisioning device needs to be connected to the AP which need not support Wi-Fi Easy ConnectTM. Easy Connect is still an evolving protocol. Of known platforms that support the QR Code method are some Android smartphones with Android 10 or higher. To use Easy Connect, no additional App needs to be installed on the supported smartphone. Application Example Example on how to provision ESP32 using a supported smartphone: wifi/wifi_easy_connect/dpp-enrollee. API Reference Header File This header file can be included with: #include "esp_dpp.h" This header file is a part of the API provided by the wpa_supplicantcomponent. To declare that your component depends on wpa_supplicant, add the following to your CMakeLists.txt: REQUIRES wpa_supplicant or PRIV_REQUIRES wpa_supplicant Functions - esp_err_t esp_supp_dpp_init(esp_supp_dpp_event_cb_t evt_cb) Initialize DPP Supplicant. Starts DPP Supplicant and initializes related Data Structures. return ESP_OK: Success ESP_FAIL: Failure - Parameters evt_cb -- Callback function to receive DPP related events - - void esp_supp_dpp_deinit(void) De-initalize DPP Supplicant. Frees memory from DPP Supplicant Data Structures. - esp_err_t esp_supp_dpp_bootstrap_gen(const char *chan_list, esp_supp_dpp_bootstrap_t type, const char *key, const char *info)
key -- (Optional) 32 byte Raw Private Key for generating a Bootstrapping Public Key info -- (Optional) Ancilliary Device Information like Serial Number - - Returns ESP_OK: Success ESP_FAIL: Failure - - esp_err_t esp_supp_dpp_start_listen(void) Start listening on Channels provided during esp_supp_dpp_bootstrap_gen. Listens on every Channel from Channel List for a pre-defined wait time. - Returns ESP_OK: Success ESP_FAIL: Generic Failure ESP_ERR_INVALID_STATE: ROC attempted before WiFi is started ESP_ERR_NO_MEM: Memory allocation failed while posting ROC request - - void esp_supp_dpp_stop_listen(void) Stop listening on Channels. Stops listening on Channels and cancels ongoing listen operation.
Macros - ESP_DPP_AUTH_TIMEOUT_SECS - ESP_ERR_DPP_FAILURE Generic failure during DPP Operation - ESP_ERR_DPP_TX_FAILURE DPP Frame Tx failed OR not Acked - ESP_ERR_DPP_INVALID_ATTR Encountered invalid DPP Attribute - ESP_ERR_DPP_AUTH_TIMEOUT DPP Auth response was not recieved in time Type Definitions - typedef enum dpp_bootstrap_type esp_supp_dpp_bootstrap_t Types of Bootstrap Methods for DPP. - typedef void (*esp_supp_dpp_event_cb_t)(esp_supp_dpp_event_t evt, void *data) Callback function for receiving DPP Events from Supplicant. Callback function will be called with DPP related information. - Param evt DPP event ID - Param data Event data payload Enumerations - enum dpp_bootstrap_type Types of Bootstrap Methods for DPP. Values: - enumerator DPP_BOOTSTRAP_QR_CODE QR Code Method - enumerator DPP_BOOTSTRAP_PKEX Proof of Knowledge Method - enumerator DPP_BOOTSTRAP_NFC_URI NFC URI record Method - enumerator DPP_BOOTSTRAP_QR_CODE
Wi-Fi AwareTM (NAN) Wi-Fi AwareTM or NAN (Neighbor Awareness Networking) is a protocol that allows Wi-Fi devices to discover services in their proximity. Typically, location-based services are based on querying servers for information about the environment and the location knowledge is based on GPS or other location reckoning techniques. However, NAN does not require real-time connection to servers, GPS or other geo-location, but instead uses direct device-to-device Wi-Fi to discover and exchange information. NAN scales effectively in dense Wi-Fi environments and complements the connectivity of Wi-Fi by providing information about people and services in the proximity. Multiple NAN devices which are in the vicinity form a NAN cluster which allows them to communicate with each other. Devices within a NAN cluster can advertise (Publish method) or look for (Subscribe method) services using NAN Service Discovery protocols. Matching of services is done by service name, once a match is found, a device can either send a message or establish an IPv6 Datapath with the peer. ESP32 supports Wi-Fi Aware in standalone mode with support for both Service Discovery and Datapath. Wi-Fi Aware is still an evolving protocol. Please refer to Wi-Fi Alliance's official page on Wi-Fi Aware for more information. Many Android smartphones with Android 8 or higher support Wi-Fi Aware. Refer to Android's developer guide on Wi-Fi Aware Wi-Fi Aware for more information. Application Example A pair of examples for a Publisher-Subscriber use case: wifi/wifi_aware/nan_publisher and wifi/wifi_aware/nan_subscriber. A user interactive console example to explore full functionality of Wi-Fi Aware: wifi/wifi_aware/nan_console. Please check the README for more details in respective example directories. API Reference Header File This header file can be included with: #include "esp_nan.h" This header file is a part of the API provided by the esp_wificomponent. To declare that your component depends on esp_wifi, add the following to your CMakeLists.txt: REQUIRES esp_wifi or PRIV_REQUIRES esp_wifi Functions - esp_err_t esp_wifi_nan_start(const wifi_nan_config_t *nan_cfg) Start NAN Discovery with provided configuration. - Attention This API should be called after esp_wifi_init(). - Parameters nan_cfg -- NAN related parameters to be configured. - Returns ESP_OK: succeed others: failed - - esp_err_t esp_wifi_nan_stop(void) Stop NAN Discovery, end NAN Services and Datapaths. - Returns ESP_OK: succeed others: failed - - uint8_t esp_wifi_nan_publish_service(const wifi_nan_publish_cfg_t *publish_cfg, bool ndp_resp_needed)
Start Publishing a service to the NAN Peers in vicinity. - Attention This API should be called after esp_wifi_nan_start(). - Parameters publish_cfg -- Configuration parameters for publishing a service. ndp_resp_needed -- Setting this true will require user response for every NDP Req using esp_wifi_nan_datapath_resp API. - - Returns non-zero: Publish service identifier zero: failed - - uint8_t esp_wifi_nan_subscribe_service(const wifi_nan_subscribe_cfg_t *subscribe_cfg) Subscribe for a service within the NAN cluster. - Attention This API should be called after esp_wifi_nan_start(). - Parameters subscribe_cfg -- Configuration parameters for subscribing for a service. - Returns non-zero: Subscribe service identifier zero: failed - - esp_err_t esp_wifi_nan_send_message(wifi_nan_followup_params_t *fup_params) Send a follow-up message to the NAN Peer with matched service. - Attention This API should be called after a NAN service is discovered due to a match. - Parameters fup_params -- Configuration parameters for sending a Follow-up message. - Returns ESP_OK: succeed others: failed - - esp_err_t esp_wifi_nan_cancel_service(uint8_t service_id) Cancel a NAN service. - Parameters service_id -- Publish/Subscribe service id to be cancelled. - Returns ESP_OK: succeed others: failed - - uint8_t esp_wifi_nan_datapath_req(wifi_nan_datapath_req_t *req) Send NAN Datapath Request to a NAN Publisher with matched service. - Attention This API should be called by the Subscriber after a match occurs with a Publisher. - Parameters req -- NAN Datapath Request parameters. - Returns non-zero NAN Datapath identifier: If NAN datapath req was accepted by publisher zero: If NAN datapath req was rejected by publisher or a timeout occurs - - esp_err_t esp_wifi_nan_datapath_resp(wifi_nan_datapath_resp_t *resp) Respond to a NAN Datapath request with Accept or Reject. - Attention This API should be called if ndp_resp_needed is set True by the Publisher and a WIFI_EVENT_NDP_INDICATION event is received due to an incoming NDP request. - Parameters resp -- NAN Datapath Response parameters. - Returns ESP_OK: succeed others: failed - - esp_err_t esp_wifi_nan_datapath_end(wifi_nan_datapath_end_req_t *req) Terminate a NAN Datapath. - Parameters req -- NAN Datapath end request parameters. - Returns ESP_OK: succeed others: failed - - void esp_wifi_nan_get_ipv6_linklocal_from_mac(ip6_addr_t
- Parameters ip6 -- [out] Derived IPv6 Link Local address. mac_addr -- [in] Input MAC Address. - - esp_err_t esp_wifi_nan_get_own_svc_info(uint8_t *own_svc_id, char *svc_name, int *num_peer_records) brief Get own Service information from Service ID OR Name. - Attention If service information is to be fetched from service name, set own_svc_id as zero. - Parameters own_svc_id -- [inout] As input, it indicates Service ID to search for. As output, it indicates Service ID of the service found using Service Name.
[out] Number of peers discovered by corresponding service. - - Returns ESP_OK: succeed ESP_FAIL: failed - - esp_err_t esp_wifi_nan_get_peer_records(int *num_peer_records, uint8_t own_svc_id, struct nan_peer_record *peer_record) brief Get a list of Peers discovered by the given Service. - Parameters num_peer_records -- [inout] As input param, it stores max peers peer_record can hold. As output param, it specifies the actual number of peers this API returns. own_svc_id -- Service ID of own service. peer_record -- [out] Pointer to first peer record. - - Returns ESP_OK: succeed ESP_FAIL: failed - - esp_err_t esp_wifi_nan_get_peer_info(char *svc_name, uint8_t *peer_mac, struct nan_peer_record *peer_info) brief Find Peer's Service information using Peer MAC and optionally Service Name. - Parameters svc_name -- Service Name of the published/subscribed service.
Peer's NAN Management Interface MAC address. peer_info -- [out] Peer's service information structure. - - Returns ESP_OK: succeed ESP_FAIL: failed - Structures - struct nan_peer_record Parameters of a peer service record Public Members - uint8_t peer_svc_id Identifier of Peer's service - uint8_t own_svc_id Identifier of own service associated with Peer - uint8_t peer_nmi[6] Peer's NAN Management Interface address - uint8_t peer_svc_type Peer's service type (Publish/Subscribe) - uint8_t ndp_id Specifies if the peer has any active datapath - uint8_t peer_ndi[6] Peer's NAN Data Interface address, only valid when ndp_id is non-zero - uint8_t peer_svc_id Macros - WIFI_NAN_CONFIG_DEFAULT() - NDP_STATUS_ACCEPTED - NDP_STATUS_REJECTED - NAN_MAX_PEERS_RECORD - ESP_NAN_PUBLISH - ESP_NAN_SUBSCRIBE
Ethernet Overview ESP-IDF provides a set of consistent and flexible APIs to support both internal Ethernet MAC (EMAC) controller and external SPI-Ethernet modules. This programming guide is split into the following sections: Basic Ethernet Concepts Ethernet is an asynchronous Carrier Sense Multiple Access with Collision Detect (CSMA/CD) protocol/interface. It is generally not well suited for low-power applications. However, with ubiquitous deployment, internet connectivity, high data rates, and limitless-range expandability, Ethernet can accommodate nearly all wired communications. Normal IEEE 802.3 compliant Ethernet frames are between 64 and 1518 bytes in length. They are made up of five or six different fields: a destination MAC address (DA), a source MAC address (SA), a type/length field, a data payload, an optional padding field and a Cyclic Redundancy Check (CRC). Additionally, when transmitted on the Ethernet medium, a 7-byte preamble field and Start-of-Frame (SOF) delimiter byte are appended to the beginning of the Ethernet packet. Thus the traffic on the twist-pair cabling appears as shown below: Preamble and Start-of-Frame Delimiter The preamble contains seven bytes of 55H. It allows the receiver to lock onto the stream of data before the actual frame arrives. The Start-of-Frame Delimiter (SFD) is a binary sequence 10101011 (as seen on the physical medium). It is sometimes considered to be part of the preamble. When transmitting and receiving data, the preamble and SFD bytes will be automatically generated or stripped from the packets. Destination Address The destination address field contains a 6-byte length MAC address of the device that the packet is directed to. If the Least Significant bit in the first byte of the MAC address is set, the address is a multicast destination.
MII usually costs up to 18 signals, while the RMII interface can reduce the consumption to 9. In RMII mode, both the receiver and transmitter signals are referenced to the REF_CLK. REF_CLK must be stable during any access to PHY and MAC. Generally, there are three ways to generate the REF_CLK depending on the PHY device in your design: Some PHY chips can derive the REF_CLKfrom its externally connected 25 MHz crystal oscillator (as seen the option a in the picture). In this case, you should select CONFIG_ETH_RMII_CLK_INPUTin CONFIG_ETH_RMII_CLK_MODE. Some PHY chip uses an externally connected 50MHz crystal oscillator or other clock sources, which can also be used as the REF_CLKfor the MAC side (as seen the option b in the picture). In this case, you still need to select CONFIG_ETH_RMII_CLK_INPUTin CONFIG_ETH_RMII_CLK_MODE. Some EMAC controllers can generate the REF_CLKusing an internal high-precision PLL (as seen the option c in the picture). In this case, you should select CONFIG_ETH_RMII_CLK_OUTPUTin CONFIG_ETH_RMII_CLK_MODE.
Note REF_CLK is configured via Project Configuration as described above by default. However, it can be overwritten from user application code by appropriately setting eth_esp32_emac_config_t::interface and eth_esp32_emac_config_t::clock_config members. See emac_rmii_clock_mode_t and emac_rmii_clock_gpio_t for more details. Warning If the RMII clock mode is selected to CONFIG_ETH_RMII_CLK_OUTPUT, then GPIO0 can be used to output the REF_CLK signal. See CONFIG_ETH_RMII_CLK_OUTPUT_GPIO0 for more information. What is more, if you are not using PSRAM in your design, GPIO16 and GPIO17 are also available to output the reference clock. See CONFIG_ETH_RMII_CLK_OUT_GPIO for more information. If the RMII clock mode is selected to CONFIG_ETH_RMII_CLK_INPUT, then GPIO0 is the only choice to input the REF_CLK signal. Please note that GPIO0 is also an important strapping GPIO on ESP32. If GPIO0 samples a low level during power-up, ESP32 will go into download mode. The system will get halted until a manually reset. The workaround for this issue is disabling the REF_CLK in hardware by default so that the strapping pin is not interfered by other signals in the boot stage. Then, re-enable the REF_CLK in the Ethernet driver installation stage. The ways to disable the REF_CLK signal can be: Disable or power down the crystal oscillator (as the case b in the picture). Force the PHY device to reset status (as the case a in the picture). This could fail for some PHY device (i.e., it still outputs signals to GPIO0 even in reset state). No matter which RMII clock mode you select, you really need to take care of the signal integrity of REF_CLK in your hardware design! Keep the trace as short as possible. Keep it away from RF devices and inductor elements.
Note ESP-IDF only supports the RMII interface (i.e., always select CONFIG_ETH_PHY_INTERFACE_RMII in the Kconfig option CONFIG_ETH_PHY_INTERFACE). Signals used in the data plane are fixed to specific GPIOs via MUX, they can not be modified to other GPIOs. Signals used in the control plane can be routed to any free GPIOs via Matrix. Please refer to ESP32-Ethernet-Kit for hardware design example. You need to set up the necessary parameters for MAC and PHY respectively based on your Ethernet board design, and then combine the two together to complete the driver installation. Configuration for MAC is described in eth_mac_config_t, including: eth_mac_config_t::sw_reset_timeout_ms: software reset timeout value, in milliseconds. Typically, MAC reset should be finished within 100 ms. eth_mac_config_t::rx_task_stack_sizeand eth_mac_config_t::rx_task_prio: the MAC driver creates a dedicated task to process incoming packets. These two parameters are used to set the stack size and priority of the task. eth_mac_config_t::flags: specifying extra features that the MAC driver should have, it could be useful in some special situations. The value of this field can be OR'd with macros prefixed with ETH_MAC_FLAG_. For example, if the MAC driver should work when the cache is disabled, then you should configure this field with ETH_MAC_FLAG_WORK_WITH_CACHE_DISABLE. eth_esp32_emac_config_t::smi_mdc_gpio_numand eth_esp32_emac_config_t::smi_mdio_gpio_num: the GPIO number used to connect the SMI signals.
eth_esp32_emac_config_t::interface: configuration of MAC Data interface to PHY (MII/RMII). eth_esp32_emac_config_t::clock_config: configuration of EMAC Interface clock ( REF_CLKmode and GPIO number in case of RMII). Configuration for PHY is described in eth_phy_config_t, including: eth_phy_config_t::phy_addr: multiple PHY devices can share the same SMI bus, so each PHY needs a unique address. Usually, this address is configured during hardware design by pulling up/down some PHY strapping pins. You can set the value from 0to 15based on your Ethernet board. Especially, if the SMI bus is shared by only one PHY device, setting this value to -1can enable the driver to detect the PHY address automatically. eth_phy_config_t::reset_timeout_ms: reset timeout value, in milliseconds. Typically, PHY reset should be finished within 100 ms. eth_phy_config_t::autonego_timeout_ms: auto-negotiation timeout value, in milliseconds. The Ethernet driver starts negotiation with the peer Ethernet node automatically, to determine to duplex and speed mode. This value usually depends on the ability of the PHY device on your board.
if your board also connects the PHY reset pin to one of the GPIO, then set it here. Otherwise, set this field to -1. ESP-IDF provides a default configuration for MAC and PHY in macro ETH_MAC_DEFAULT_CONFIG and ETH_PHY_DEFAULT_CONFIG. Create MAC and PHY Instance The Ethernet driver is implemented in an Object-Oriented style. Any operation on MAC and PHY should be based on the instance of the two. Internal EMAC + External PHY eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); // apply default common MAC configuration eth_esp32_emac_config_t esp32_emac_config = ETH_ESP32_EMAC_DEFAULT_CONFIG(); // apply default vendor-specific MAC configuration esp32_emac_config.smi_mdc_gpio_num = CONFIG_EXAMPLE_ETH_MDC_GPIO; // alter the GPIO used for MDC signal esp32_emac_config.smi_mdio_gpio_num = CONFIG_EXAMPLE_ETH_MDIO_GPIO; // alter the GPIO used for MDIO signal esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); // create MAC instance eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); // apply default PHY configuration phy_config.phy_addr = CONFIG_EXAMPLE_ETH_PHY_ADDR; // alter the PHY address according to your board design phy_config.reset_gpio_num = CONFIG_EXAMPLE_ETH_PHY_RST_GPIO; // alter the GPIO used for PHY reset esp_eth_phy_t *phy = esp_eth_phy_new_ip101(&phy_config); // create PHY instance // ESP-IDF officially supports several different Ethernet PHY chip driver // esp_eth_phy_t *phy = esp_eth_phy_new_rtl8201(&phy_config); // esp_eth_phy_t *phy = esp_eth_phy_new_lan8720(&phy_config); //
; // apply default vendor-specific MAC configuration // ... esp32_emac_config.interface = EMAC_DATA_INTERFACE_RMII; // alter EMAC Data Interface esp32_emac_config.clock_config.rmii.clock_mode = EMAC_CLK_OUT; // select EMAC REF_CLK mode esp32_emac_config.clock_config.rmii.clock_gpio = EMAC_CLK_OUT_GPIO; // select GPIO number used to input/output EMAC REF_CLK esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&esp32_emac_config, &mac_config); // create MAC instance SPI-Ethernet Module eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); // apply default common MAC configuration eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); // apply default PHY configuration phy_config.phy_addr = CONFIG_EXAMPLE_ETH_PHY_ADDR; // alter the PHY address according to your board design phy_config.reset_gpio_num = CONFIG_EXAMPLE_ETH_PHY_RST_GPIO; // alter the GPIO used for PHY reset // Install GPIO interrupt service (as the SPI-Ethernet module is interrupt-driven) gpio_install_isr_service(0); // SPI bus configuration spi_device_handle_t spi_handle = NULL; spi_bus_config_t buscfg = { .miso_io_num =
CONFIG_EXAMPLE_ETH_SPI_MISO_GPIO, .mosi_io_num = CONFIG_EXAMPLE_ETH_SPI_MOSI_GPIO, .sclk_io_num = CONFIG_EXAMPLE_ETH_SPI_SCLK_GPIO, .quadwp_io_num = -1, .quadhd_io_num = -1, }; ESP_ERROR_CHECK(spi_bus_initialize(CONFIG_EXAMPLE_ETH_SPI_HOST, &buscfg, 1)); // Configure SPI device spi_device_interface_config_t spi_devcfg = { .mode = 0, .clock_speed_hz = CONFIG_EXAMPLE_ETH_SPI_CLOCK_MHZ * 1000 * 1000, .spics_io_num = CONFIG_EXAMPLE_ETH_SPI_CS_GPIO, .queue_size = 20 }; /* dm9051 ethernet driver is based on spi driver */ eth_dm9051_config_t dm9051_config = ETH_DM9051_DEFAULT_CONFIG(CONFIG_EXAMPLE_ETH_SPI_HOST, &spi_devcfg); dm9051_config.int_gpio_num = CONFIG_EXAMPLE_ETH_SPI_INT_GPIO; esp_eth_mac_t *mac = esp_eth_mac_new_dm9051(&dm9051_config, &mac_config); esp_eth_phy_t *phy = esp_eth_phy_new_dm9051(&phy_config) ; Note When creating MAC and PHY instances for SPI-Ethernet modules (e.g., DM9051), the constructor function must have the same suffix (e.g., esp_eth_mac_new_dm9051 and esp_eth_phy_new_dm9051). This is because we don not have other choices but the integrated PHY. The SPI device configuration (i.e., spi_device_interface_config_t) may slightly differ for other Ethernet modules or to meet SPI timing on specific PCB. Please check out your module's specs and the examples in ESP-IDF. Install Driver To install the Ethernet driver, we need to combine the instance of MAC and PHY and set some additional high-level configurations (i.e., not specific to either MAC or PHY) in esp_eth_config_t: esp_eth_config_t::mac: instance that created from MAC generator (e.g., esp_eth_mac_new_esp32()). esp_eth_config_t::phy: instance that created from PHY generator (e.g., esp_eth_phy_new_ip101()). esp_eth_config_t::check_link_period_ms: Ethernet driver starts an OS timer to check the link status periodically, this field is used to set the interval, in milliseconds. esp_eth_config_t::stack_input: In most Ethernet IoT applications, any Ethernet frame received by a driver should be passed to the upper layer (e.g., TCP/IP stack). This field is set to a function that is responsible to deal with the incoming frames. You can even update this field at runtime via function esp_eth_update_input_path()after driver installation. esp_eth_config_t::on_lowlevel_init_doneand esp_eth_config_t::on_lowlevel_deinit_done: These two fields are used to specify the hooks which get invoked when low-level hardware has been initialized or de-initialized. ESP-IDF provides a default configuration for driver installation in macro ETH_DEFAULT_CONFIG.
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy); // apply default driver configuration esp_eth_handle_t eth_handle = NULL; // after the driver is installed, we will get the handle of the driver esp_eth_driver_install(&config, ð_handle); // install driver The Ethernet driver also includes an event-driven model, which sends useful and important events to user space. We need to initialize the event loop before installing the Ethernet driver. For more information about event-driven programming, please refer to ESP Event.
/ ** Event handler for Ethernet events */ static void eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { uint8_t mac_addr[6] = {0}; / * we can get the ethernet driver handle from event data */ esp_eth_handle_t eth_handle = *(esp_eth_handle_t *)event_data; switch (event_id) { case ETHERNET_EVENT_CONNECTED: esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr); ESP_LOGI(TAG, "Ethernet Link Up"); ESP_LOGI(TAG, "Ethernet HW Addr %02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); break; case ETHERNET_EVENT_DISCONNECTED: ESP_LOGI(TAG, "Ethernet Link Down"); break; case ETHERNET_EVENT_START: ESP_LOGI(TAG, "Ethernet Started"); break; case ETHERNET_EVENT_STOP: ESP_LOGI(TAG, "Ethernet Stopped"); break; default: break; } } esp_event_loop_create_default(); // create a default event loop that runs in the background esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, ð_event_handler, NULL); // register Ethernet event handler (to deal with user-specific stuff when events like link up/down happened) Start Ethernet Driver After driver installation, we can start Ethernet immediately. esp_eth_start(eth_handle); // start Ethernet driver state machine Connect Driver to TCP/IP Stack Up until now, we have installed the Ethernet driver. From the view of OSI (Open System Interconnection), we are still on level 2 (i.e., Data Link Layer). While we can detect link up and down events and gain MAC address in user space, it is infeasible to obtain the IP address, let alone send an HTTP request. The TCP/IP stack used in ESP-IDF is called LwIP. For more information about it, please refer to LwIP. To connect the Ethernet driver to TCP/IP stack, follow these three steps: Create a network interface for the Ethernet driver Attach the network interface to the Ethernet driver Register IP event handlers For more information about the network interface, please refer to Network Interface.
*arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data; const esp_netif_ip_info_t *ip_info = &event->ip_info; ESP_LOGI(TAG, "Ethernet Got IP Address"); ESP_LOGI(TAG, "~~~~~~~~~~~"); ESP_LOGI(TAG, "ETHIP:" IPSTR, IP2STR(&ip_info->ip)); ESP_LOGI(TAG, "ETHMASK:" IPSTR, IP2STR(&ip_info->netmask)); ESP_LOGI(TAG, "ETHGW:" IPSTR, IP2STR(&ip_info->gw)); ESP_LOGI(TAG, "~~~~~~~~~~~"); } esp_netif_init()); // Initialize TCP/IP network interface (should be called only once in application) esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH(); // apply default network interface configuration for Ethernet esp_netif_t *eth_netif = esp_netif_new(&cfg); // create network interface for Ethernet driver esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle)); // attach Ethernet driver to TCP/IP stack esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &got_ip_event_handler, NULL); // register user defined IP event handlers esp_eth_start(eth_handle); // start Ethernet driver state machine Warning
It is recommended to fully initialize the Ethernet driver and network interface before registering the user's Ethernet/IP event handlers, i.e., register the event handlers as the last thing prior to starting the Ethernet driver. Such an approach ensures that Ethernet/IP events get executed first by the Ethernet driver or network interface so the system is in the expected state when executing the user's handlers. Misc Control of Ethernet Driver The following functions should only be invoked after the Ethernet driver has been installed.
Stop Ethernet driver: esp_eth_stop() Update Ethernet data input path: esp_eth_update_input_path() Misc get/set of Ethernet driver attributes: esp_eth_ioctl() /* get MAC address */ uint8_t mac_addr[6]; memset(mac_addr, 0, sizeof(mac_addr)); esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac_addr); ESP_LOGI(TAG, "Ethernet MAC Address: %02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); /* get PHY address */ int phy_addr = -1; esp_eth_ioctl(eth_handle, ETH_CMD_G_PHY_ADDR, &phy_addr); ESP_LOGI(TAG, "Ethernet PHY Address: %d", phy_addr); Flow Control Ethernet on MCU usually has a limitation in the number of frames it can handle during network congestion, because of the limitation in RAM size.
A sending station might be transmitting data faster than the peer end can accept it. The ethernet flow control mechanism allows the receiving node to signal the sender requesting the suspension of transmissions until the receiver catches up. The magic behind that is the pause frame, which was defined in IEEE 802.3x. Pause frame is a special Ethernet frame used to carry the pause command, whose EtherType field is 0x8808, with the Control opcode set to 0x0001. Only stations configured for full-duplex operation may send pause frames. When a station wishes to pause the other end of a link, it sends a pause frame to the 48-bit reserved multicast address of 01-80-C2-00-00-01. The pause frame also includes the period of pause time being requested, in the form of a two-byte integer, ranging from 0 to 65535. After the Ethernet driver installation, the flow control feature is disabled by default. You can enable it by: bool flow_ctrl_enable = true; esp_eth_ioctl(eth_handle, ETH_CMD_S_FLOW_CTRL, &flow_ctrl_enable); One thing that should be kept in mind is that the pause frame ability is advertised to the peer end by PHY during auto-negotiation. The Ethernet driver sends a pause frame only when both sides of the link support it.
There are multiple PHY manufacturers with wide portfolios of chips available. The ESP-IDF already supports several PHY chips however one can easily get to a point where none of them satisfies the user's actual needs due to price, features, stock availability, etc. Luckily, a management interface between EMAC and PHY is standardized by IEEE 802.3 in Section 22.2.4 Management Functions. It defines provisions of the so-called "MII Management Interface" to control the PHY and gather status from the PHY. A set of management registers is defined to control chip behavior, link properties, auto-negotiation configuration, etc. This basic management functionality is addressed by esp_eth/src/esp_eth_phy_802_3.c in ESP-IDF and so it makes the creation of a new custom PHY chip driver quite a simple task. Note Always consult with PHY datasheet since some PHY chips may not comply with IEEE 802.3, Section 22.2.4. It does not mean you are not able to create a custom PHY driver, but it just requires more effort. You will have to define all PHY management functions.
The majority of PHY management functionality required by the ESP-IDF Ethernet driver is covered by the esp_eth/src/esp_eth_phy_802_3.c. However, the following may require developing chip-specific management functions: - Link status which is almost always chip-specific - Chip initialization, even though not strictly required, should be customized to at least ensure that the expected chip is used - Chip-specific features configuration Steps to create a custom PHY driver: Define vendor-specific registry layout based on the PHY datasheet.
Prepare derived PHY management object info structure which: must contain at least parent IEEE 802.3 phy_802_3_tobject optionally contain additional variables needed to support non-IEEE 802.3 or customized functionality. See esp_eth/src/esp_eth_phy_ksz80xx.c as an example. - Define chip-specific management call-back functions. Initialize parent IEEE 802.3 object and re-assign chip-specific management call-back functions. Once you finish the new custom PHY driver implementation, consider sharing it among other users via IDF Component Registry. API Reference Header File This header file can be included with: #include "esp_eth.h" This header file is a part of the API provided by the esp_ethcomponent. To declare that your component depends on esp_eth, add the following to your CMakeLists.txt: REQUIRES esp_eth or PRIV_REQUIRES esp_eth Header File This header file can be included with: #include "esp_eth_driver.h" This header file is a part of the API provided by the esp_ethcomponent. To declare that your component depends on esp_eth, add the following to your CMakeLists.txt: REQUIRES esp_eth or PRIV_REQUIRES
dataargument is pointer to memory of uint32_t datatype from where the configuration option is read. ETH_CMD_G_PHY_ADDRgets PHY address. dataargument is pointer to memory of uint32_t datatype to which the PHY address is to be stored. ETH_CMD_S_AUTONEGOenables or disables Ethernet link speed and duplex mode autonegotiation. dataargument is pointer to memory of bool datatype from which the configuration option is read. Preconditions: Ethernet driver needs to be stopped. ETH_CMD_G_AUTONEGOgets current configuration of the Ethernet link speed and duplex mode autonegotiation. dataargument is pointer to memory of bool datatype to which the current configuration is to be stored. ETH_CMD_S_SPEEDsets the Ethernet link speed. dataargument is pointer to memory of eth_speed_t datatype from which the configuration option is read. Preconditions: Ethernet driver needs to be stopped and auto-negotiation disabled. ETH_CMD_G_SPEEDgets current Ethernet link speed. dataargument is pointer to memory of eth_speed_t datatype to which the speed is to be stored. ETH_CMD_S_PROMISCUOUSsets/resets Ethernet interface promiscuous mode. dataargument is pointer to memory of bool datatype from which the configuration option is read. ETH_CMD_S_FLOW_CTRLsets/resets Ethernet interface flow control. dataargument is pointer to memory of bool datatype from which the configuration option is read. ETH_CMD_S_DUPLEX_MODEsets the Ethernet duplex mode. dataargument is pointer to memory of eth_duplex_t datatype from which the configuration option is read. Preconditions: Ethernet driver needs to be stopped and auto-negotiation disabled. ETH_CMD_G_DUPLEX_MODEgets current Ethernet link duplex mode. dataargument is pointer to memory of eth_duplex_t datatype to which the duplex mode is to be stored.
[in] handle of Ethernet driver cmd -- [in] IO control command data -- [inout] address of data for setcommand or address where to store the data when used with getcommand - - Returns ESP_OK: process io command successfully ESP_ERR_INVALID_ARG: process io command failed because of some invalid argument ESP_FAIL: process io command failed because some other error occurred ESP_ERR_NOT_SUPPORTED: requested feature is not supported - - - esp_err_t esp_eth_increase_reference(esp_eth_handle_t hdl) Increase Ethernet driver reference. Note Ethernet driver handle can be obtained by os timer, netif, etc. It's dangerous when thread A is using Ethernet but thread B uninstall the driver. Using reference counter can prevent such risk, but care should be taken, when you obtain Ethernet driver, this API must be invoked so that the driver won't be uninstalled during your using time. - Parameters hdl --
[in] handle of Ethernet driver - Returns ESP_OK: increase reference successfully ESP_ERR_INVALID_ARG: increase reference failed because of some invalid argument - - esp_err_t esp_eth_decrease_reference(esp_eth_handle_t hdl) Decrease Ethernet driver reference. - Parameters hdl -- [in] handle of Ethernet driver - Returns ESP_OK: increase reference successfully ESP_ERR_INVALID_ARG: increase reference failed because of some invalid argument - Structures - struct esp_eth_config_t Configuration of Ethernet driver. Public Members - esp_eth_mac_t *mac Ethernet MAC object. - esp_eth_phy_t *phy Ethernet PHY object. - uint32_t check_link_period_ms Period time of checking Ethernet link status. - esp_err_t (*stack_input)(esp_eth_handle_t eth_handle, uint8_t *buffer, uint32_t length, void *priv) Input frame buffer to user's stack. - Param eth_handle [in] handle of Ethernet driver - Param buffer [in] frame buffer that will get input to upper stack - Param length [in] length of the frame buffer - Return ESP_OK: input frame buffer to upper stack successfully ESP_FAIL: error occurred when inputting buffer to upper stack - - esp_err_t (*on_lowlevel_init_done)(esp_eth_handle_t eth_handle) Callback function invoked when lowlevel initialization is finished. - Param eth_handle [in] handle of Ethernet driver - Return ESP_OK: process extra lowlevel initialization successfully ESP_FAIL: error occurred when processing extra lowlevel initialization - - esp_err_t (*on_lowlevel_deinit_done)(esp_eth_handle_t eth_handle) Callback function invoked when lowlevel deinitialization is finished. - Param eth_handle [in] handle of Ethernet driver - Return ESP_OK: process extra lowlevel deinitialization successfully ESP_FAIL: error occurred when processing extra lowlevel deinitialization - - esp_err_t (*read_phy_reg)(esp_eth_handle_t eth_handle, uint32_t phy_addr, uint32_t phy_reg, uint32_t *reg_value)
Note Usually the PHY register read/write function is provided by MAC (SMI interface), but if the PHY device is managed by other interface (e.g. I2C), then user needs to implement the corresponding read/write. Setting this to NULL means your PHY device is managed by MAC's SMI interface. - Param eth_handle [in] handle of Ethernet driver - Param phy_addr [in] PHY chip address (0~31) - Param phy_reg [in] PHY register index code - Param reg_value [out] PHY register value - Return ESP_OK: read PHY register successfully ESP_ERR_INVALID_ARG: read PHY register failed because of invalid argument ESP_ERR_TIMEOUT: read PHY register failed because of timeout ESP_FAIL: read PHY register failed because some other error occurred - - esp_err_t (*write_phy_reg)(esp_eth_handle_t eth_handle, uint32_t phy_addr, uint32_t phy_reg, uint32_t reg_value)
[in] PHY chip address (0~31) - Param phy_reg [in] PHY register index code - Param reg_value [in] PHY register value - Return ESP_OK: write PHY register successfully ESP_ERR_INVALID_ARG: read PHY register failed because of invalid argument ESP_ERR_TIMEOUT: write PHY register failed because of timeout ESP_FAIL: write PHY register failed because some other error occurred - - esp_eth_mac_t *mac - struct esp_eth_phy_reg_rw_data_t Data structure to Read/Write PHY register via ioctl API. Macros - ETH_DEFAULT_CONFIG(emac, ephy) Default configuration for Ethernet driver. Type Definitions - typedef void *esp_eth_handle_t Handle of Ethernet driver. Enumerations - enum esp_eth_io_cmd_t Command list for ioctl API. Values: - enumerator ETH_CMD_G_MAC_ADDR Get MAC address - enumerator ETH_CMD_S_MAC_ADDR Set MAC address - enumerator ETH_CMD_G_PHY_ADDR Get PHY address - enumerator ETH_CMD_S_PHY_ADDR Set PHY address - enumerator ETH_CMD_G_AUTONEGO Get PHY Auto Negotiation - enumerator ETH_CMD_S_AUTONEGO Set PHY Auto Negotiation - enumerator ETH_CMD_G_SPEED Get Speed - enumerator ETH_CMD_S_SPEED Set Speed - enumerator ETH_CMD_S_PROMISCUOUS Set promiscuous mode - enumerator ETH_CMD_S_FLOW_CTRL Set flow control - enumerator ETH_CMD_G_DUPLEX_MODE Get Duplex mode - enumerator ETH_CMD_S_DUPLEX_MODE Set Duplex mode - enumerator ETH_CMD_S_PHY_LOOPBACK Set PHY loopback - enumerator ETH_CMD_READ_PHY_REG Read PHY register - enumerator ETH_CMD_WRITE_PHY_REG Write PHY register - enumerator ETH_CMD_CUSTOM_MAC_CMDS - enumerator ETH_CMD_CUSTOM_PHY_CMDS - enumerator ETH_CMD_G_MAC_ADDR Header File This header file can be included with: #include "esp_eth_com.h" This header file is a part of the API provided by the esp_ethcomponent.
Deliver packet to upper stack. - Param eth [in] mediator of Ethernet driver - Param buffer [in] packet buffer - Param length [in] length of the packet - Return ESP_OK: deliver packet to upper stack successfully ESP_FAIL: deliver packet failed because some error occurred - - esp_err_t (*on_state_changed)(esp_eth_mediator_t *eth, esp_eth_state_t state, void *args) Callback on Ethernet state changed. - Param eth [in] mediator of Ethernet driver - Param state [in] new state - Param args [in] optional argument for the new state - Return ESP_OK: process the new state successfully ESP_FAIL: process the new state failed because some error occurred - - esp_err_t (*phy_reg_read)(esp_eth_mediator_t *eth, uint32_t phy_addr, uint32_t phy_reg, uint32_t *reg_value) Type Definitions - typedef struct esp_eth_mediator_s esp_eth_mediator_t Ethernet mediator. Enumerations - enum esp_eth_state_t Ethernet driver state. Values: - enumerator ETH_STATE_LLINIT Lowlevel init done - enumerator ETH_STATE_DEINIT Deinit done - enumerator ETH_STATE_LINK Link status changed - enumerator ETH_STATE_SPEED Speed updated - enumerator ETH_STATE_DUPLEX Duplex updated - enumerator ETH_STATE_PAUSE Pause ability updated - enumerator ETH_STATE_LLINIT Header File This header file can be included with: #include "esp_eth_mac.h" This header file is a part of the API provided by the esp_ethcomponent.
esp_eth Functions - esp_eth_mac_t *esp_eth_mac_new_esp32(const eth_esp32_emac_config_t *esp32_config, const eth_mac_config_t *config) Create ESP32 Ethernet MAC instance. - Parameters esp32_config -- EMAC specific configuration config -- Ethernet MAC configuration - - Returns instance: create MAC instance successfully NULL: create MAC instance failed because some error occurred - Unions - union eth_mac_clock_config_t - #include <esp_eth_mac.h> Ethernet MAC Clock Configuration. Public Members - struct eth_mac_clock_config_t::[anonymous] mii EMAC MII Clock Configuration - emac_rmii_clock_mode_t clock_mode RMII Clock Mode Configuration - emac_rmii_clock_gpio_t clock_gpio RMII Clock GPIO Configuration - struct eth_mac_clock_config_t::[anonymous] rmii EMAC RMII Clock Configuration - struct eth_mac_clock_config_t::[anonymous] mii Structures - struct esp_eth_mac_s Ethernet MAC. Public Members - esp_err_t (*set_mediator)(esp_eth_mac_t *mac, esp_eth_mediator_t *eth) Set mediator for Ethernet MAC. - Param mac [in] Ethernet MAC instance - Param eth [in] Ethernet mediator - Return ESP_OK: set mediator for Ethernet MAC successfully ESP_ERR_INVALID_ARG: set mediator for Ethernet MAC failed because of invalid argument - - esp_err_t (*init)(esp_eth_mac_t *mac) Initialize Ethernet MAC. - Param mac [in] Ethernet MAC instance - Return ESP_OK: initialize Ethernet MAC successfully ESP_ERR_TIMEOUT: initialize Ethernet MAC failed because of timeout ESP_FAIL: initialize Ethernet MAC failed because some other error occurred - - esp_err_t (*deinit)(esp_eth_mac_t *mac) Deinitialize Ethernet MAC. - Param mac [in] Ethernet MAC instance - Return ESP_OK: deinitialize Ethernet MAC successfully ESP_FAIL: deinitialize Ethernet MAC failed because some error occurred - - esp_err_t (*start)(esp_eth_mac_t *mac) Start Ethernet MAC. - Param mac [in] Ethernet MAC instance - Return ESP_OK: start Ethernet MAC successfully ESP_FAIL: start Ethernet MAC failed because some other error occurred - - esp_err_t (*stop)(esp_eth_mac_t *mac) Stop Ethernet MAC. - Param mac [in] Ethernet MAC instance - Return ESP_OK: stop Ethernet MAC successfully ESP_FAIL: stop Ethernet MAC failed because some error occurred - - esp_err_t (*transmit)(esp_eth_mac_t *mac, uint8_t *buf, uint32_t length)
Transmit packet from Ethernet MAC. Note Returned error codes may differ for each specific MAC chip. - Param mac [in] Ethernet MAC instance - Param buf [in] packet buffer to transmit - Param length [in] length of packet - Return ESP_OK: transmit packet successfully ESP_ERR_INVALID_SIZE: number of actually sent bytes differs to expected ESP_FAIL: transmit packet failed because some other error occurred - - esp_err_t (*transmit_vargs)(esp_eth_mac_t *mac, uint32_t argc, va_list args) Transmit packet from Ethernet MAC constructed with special parameters at Layer2. Note Typical intended use case is to make possible to construct a frame from multiple higher layer buffers without a need of buffer reallocations. However, other use cases are not limited. Note Returned error codes may differ for each specific MAC chip. - Param mac [in] Ethernet MAC instance - Param argc [in] number variable arguments - Param args [in] variable arguments - Return ESP_OK: transmit packet successfully ESP_ERR_INVALID_SIZE: number of actually sent bytes differs to expected ESP_FAIL: transmit packet failed because some other error occurred - - esp_err_t (*receive)(esp_eth_mac_t *mac, uint8_t *buf, uint32_t *length) Receive packet from Ethernet MAC.
Note Memory of buf is allocated in the Layer2, make sure it get free after process. Note Before this function got invoked, the value of "length" should set by user, equals the size of buffer. After the function returned, the value of "length" means the real length of received data. - Param mac [in] Ethernet MAC instance - Param buf [out] packet buffer which will preserve the received frame - Param length [out] length of the received packet - Return ESP_OK: receive packet successfully ESP_ERR_INVALID_ARG: receive packet failed because of invalid argument ESP_ERR_INVALID_SIZE: input buffer size is not enough to hold the incoming data. in this case, value of returned "length" indicates the real size of incoming data.
[in] Ethernet MAC instance - Param phy_addr [in] PHY chip address (0~31) - Param phy_reg [in] PHY register index code - Param reg_value [out] PHY register value - Return ESP_OK: read PHY register successfully ESP_ERR_INVALID_ARG: read PHY register failed because of invalid argument ESP_ERR_INVALID_STATE: read PHY register failed because of wrong state of MAC ESP_ERR_TIMEOUT: read PHY register failed because of timeout ESP_FAIL: read PHY register failed because some other error occurred - - esp_err_t (*write_phy_reg)(esp_eth_mac_t *mac, uint32_t phy_addr, uint32_t phy_reg, uint32_t reg_value) Write PHY register. - Param mac
This function is intended to extend common options of esp_eth_ioctl to cover specifics of MAC chip. Note This function may not be assigned when the MAC chip supports only most common set of configuration options. - Param mac [in] Ethernet MAC instance - Param cmd [in] IO control command - Param data [inout] address of data for setcommand or address where to store the data when used with getcommand - Return ESP_OK: process io command successfully ESP_ERR_INVALID_ARG: process io command failed because of some invalid argument ESP_FAIL: process io command failed because some other error occurred ESP_ERR_NOT_SUPPORTED: requested feature is not supported - - esp_err_t (*del)(esp_eth_mac_t *mac) Free memory of Ethernet MAC. - Param mac [in] Ethernet MAC instance - Return ESP_OK: free Ethernet MAC instance successfully ESP_FAIL: free Ethernet MAC instance failed because some error occurred - - esp_err_t (*set_mediator)(esp_eth_mac_t *mac, esp_eth_mediator_t *eth) - struct eth_mac_config_t Configuration of Ethernet MAC object. - struct eth_esp32_emac_config_t EMAC specific configuration. Public Members - int smi_mdc_gpio_num SMI MDC GPIO number, set to -1 could bypass the SMI GPIO configuration - int smi_mdio_gpio_num SMI MDIO GPIO number, set to -1 could bypass the SMI GPIO configuration - eth_data_interface_t interface EMAC Data interface to PHY (MII/RMII) - eth_mac_clock_config_t clock_config EMAC Interface clock configuration - eth_mac_dma_burst_len_t dma_burst_len EMAC DMA burst length for both Tx and Rx - int smi_mdc_gpio_num - struct eth_spi_custom_driver_config_t Custom SPI Driver Configuration. This structure declares configuration and callback functions to access Ethernet SPI module via user's custom SPI driver. Public Members - void *config Custom driver specific configuration data used by init()function. Note Type and its content is fully under user's control - void *
Note that outputting RMII clock on GPIO0 is an experimental practice. If you want the Ethernet to work with WiFi, don’t select GPIO0 output mode for stability. - enumerator EMAC_CLK_OUT_GPIO Output RMII Clock from internal APLL Clock available at GPIO16. - enumerator EMAC_CLK_OUT_180_GPIO Inverted Output RMII Clock from internal APLL Clock available at GPIO17. - enumerator EMAC_CLK_IN_GPIO Header File This header file can be included with: #include "esp_eth_phy.h" This header file is a part of the API provided by the esp_ethcomponent. To declare that your component depends on esp_eth, add the following to your CMakeLists.txt: REQUIRES esp_eth or PRIV_REQUIRES
create PHY instance failed because some error occurred - - esp_eth_phy_t * esp_eth_phy_new_rtl8201(const eth_phy_config_t *config) Create a PHY instance of RTL8201. - Parameters config -- [in] configuration of PHY - Returns instance: create PHY instance successfully NULL: create PHY instance failed because some error occurred - - esp_eth_phy_t *esp_eth_phy_new_lan87xx(const eth_phy_config_t *config) Create a PHY instance of LAN87xx. - Parameters config -- [in] configuration of PHY - Returns instance: create PHY instance successfully NULL: create PHY instance failed because some error occurred - - esp_eth_phy_t *esp_eth_phy_new_dp83848(const eth_phy_config_t *config) Create a PHY instance of DP83848. - Parameters config -- [in] configuration of PHY - Returns instance: create PHY instance successfully NULL: create PHY instance failed because some error occurred - - esp_eth_phy_t *esp_eth_phy_new_ksz80xx(const eth_phy_config_t *config) Create a PHY instance of KSZ80xx. The phy model from the KSZ80xx series is detected automatically. If the driver is unable to detect a supported model, NULLis returned. Currently, the following models are supported: KSZ8001, KSZ8021, KSZ8031, KSZ8041, KSZ8051, KSZ8061, KSZ8081, KSZ8091 - Parameters config --
[in] configuration of PHY - Returns instance: create PHY instance successfully NULL: create PHY instance failed because some error occurred - Structures - struct esp_eth_phy_s Ethernet PHY. Public Members - esp_err_t (*set_mediator)(esp_eth_phy_t *phy, esp_eth_mediator_t *mediator) Set mediator for PHY. - Param phy [in] Ethernet PHY instance - Param mediator [in] mediator of Ethernet driver - Return ESP_OK: set mediator for Ethernet PHY instance successfully ESP_ERR_INVALID_ARG: set mediator for Ethernet PHY instance failed because of some invalid arguments - - esp_err_t (*reset)(esp_eth_phy_t *phy) Software Reset Ethernet PHY. - Param phy [in] Ethernet PHY instance - Return ESP_OK: reset Ethernet PHY successfully ESP_FAIL: reset Ethernet PHY failed because some error occurred - - esp_err_t (*reset_hw)(esp_eth_phy_t *phy) Hardware Reset Ethernet PHY.
[in] Ethernet PHY instance - Return ESP_OK: reset Ethernet PHY successfully ESP_FAIL: reset Ethernet PHY failed because some error occurred - - esp_err_t (*init)(esp_eth_phy_t *phy) Initialize Ethernet PHY. - Param phy [in] Ethernet PHY instance - Return ESP_OK: initialize Ethernet PHY successfully ESP_FAIL: initialize Ethernet PHY failed because some error occurred - - esp_err_t (*deinit)(esp_eth_phy_t *phy) Deinitialize Ethernet PHY. - Param phy [in] Ethernet PHY instance - Return ESP_OK: deinitialize Ethernet PHY successfully ESP_FAIL: deinitialize Ethernet PHY failed because some error occurred - - esp_err_t (*autonego_ctrl)(esp_eth_phy_t *phy, eth_phy_autoneg_cmd_t cmd, bool *autonego_en_stat) Configure auto negotiation. - Param phy [in] Ethernet PHY instance - Param cmd [in] Configuration command, it is possible to Enable (restart), Disable or get current status of PHY auto negotiation - Param autonego_en_stat [out] Address where to store current status of auto negotiation configuration - Return ESP_OK: restart auto negotiation successfully ESP_FAIL: restart auto negotiation failed because some error occurred ESP_ERR_INVALID_ARG: invalid command - - esp_err_t (*get_link)(esp_eth_phy_t *phy) Get Ethernet PHY link status. - Param phy [in] Ethernet PHY instance - Return ESP_OK: get Ethernet PHY link status successfully ESP_FAIL: get Ethernet PHY link status failed because some error occurred - - esp_err_t (*pwrctl)(esp_eth_phy_t *phy, bool enable) Power control of Ethernet PHY. - Param phy [in] Ethernet PHY instance - Param enable [in] set true to power on Ethernet PHY; ser false to power off Ethernet PHY - Return ESP_OK: control Ethernet PHY power successfully ESP_FAIL: control Ethernet PHY power failed because some error occurred - - esp_err_t (*set_addr)(esp_eth_phy_t *phy, uint32_t addr) Set PHY chip address. - Param phy [in] Ethernet PHY instance - Param addr [in] PHY chip address - Return ESP_OK: set Ethernet PHY address successfully ESP_FAIL: set Ethernet PHY address failed because some error occurred - - esp_err_t (*get_addr)(esp_eth_phy_t *phy, uint32_t *addr) Get PHY chip address. - Param phy [in] Ethernet PHY instance - Param addr [out] PHY chip address - Return ESP_OK: get Ethernet PHY address successfully ESP_ERR_INVALID_ARG: get Ethernet PHY address failed because of invalid argument - - esp_err_t (*advertise_pause_ability)(esp_eth_phy_t *phy, uint32_t ability) Advertise pause function supported by MAC layer. - Param phy [in] Ethernet PHY instance - Param addr [out] Pause ability - Return ESP_OK: Advertise pause ability successfully ESP_ERR_INVALID_ARG: Advertise pause ability failed because of invalid argument - - esp_err_t (*loopback)(esp_eth_phy_t *phy, bool enable) Sets the PHY to loopback mode. - Param phy [in] Ethernet PHY instance - Param enable [in] enables or disables PHY loopback - Return ESP_OK:
PHY instance duplex mode has been configured successfully ESP_FAIL: PHY instance duplex mode configuration failed because some error occurred - - esp_err_t (*custom_ioctl)(esp_eth_phy_t *phy, uint32_t cmd, void *data) Custom IO function of PHY driver. This function is intended to extend common options of esp_eth_ioctl to cover specifics of PHY chip. Note This function may not be assigned when the PHY chip supports only most common set of configuration options. - Param phy [in] Ethernet PHY instance - Param cmd [in] IO control command - Param data [inout] address of data for setcommand or address where to store the data when used with getcommand - Return ESP_OK: process io command successfully ESP_ERR_INVALID_ARG: process io command failed because of some invalid argument ESP_FAIL: process io command failed because some other error occurred ESP_ERR_NOT_SUPPORTED: requested feature is not supported - - esp_err_t (*del)(esp_eth_phy_t *phy) Free memory of Ethernet PHY instance. - Param phy [in] Ethernet PHY instance - Return ESP_OK: free PHY instance successfully ESP_FAIL: free PHY instance failed because some error occurred - - esp_err_t (*set_mediator)(esp_eth_phy_t *phy, esp_eth_mediator_t *mediator) - struct eth_phy_config_t Ethernet PHY configuration. Public Members - int32_t phy_addr PHY address, set -1 to enable PHY address detection at initialization stage - uint32_t reset_timeout_ms Reset timeout value (Unit: ms) - uint32_t autonego_timeout_ms Auto-negotiation timeout value (Unit: ms) - int reset_gpio_num Reset GPIO number, -1 means no hardware reset - int32_t phy_addr Macros - ESP_ETH_PHY_ADDR_AUTO - ETH_PHY_DEFAULT_CONFIG() Default configuration for Ethernet PHY object. Type Definitions - typedef struct esp_eth_phy_s esp_eth_phy_t Ethernet PHY. Enumerations Header File This header file can be included with: #include "esp_eth_phy_802_3.h" This header file is a part of the API provided by the esp_ethcomponent. To declare that your component depends on esp_eth, add the following to your CMakeLists.txt: REQUIRES esp_eth or PRIV_REQUIRES
esp_eth Functions - esp_err_t esp_eth_phy_802_3_set_mediator(phy_802_3_t *phy_802_3, esp_eth_mediator_t *eth) Set Ethernet mediator. - Parameters phy_802_3 -- IEEE 802.3 PHY object infostructure eth -- Ethernet mediator pointer - - Returns ESP_OK: Ethermet mediator set successfuly ESP_ERR_INVALID_ARG: if ethis NULL - - esp_err_t esp_eth_phy_802_3_reset(phy_802_3_t *phy_802_3) Reset PHY. - Parameters phy_802_3 -- IEEE 802.3 PHY object infostructure - Returns ESP_OK: Ethernet PHY reset successfuly ESP_FAIL: reset Ethernet PHY failed because some error occured - - esp_err_t esp_eth_phy_802_3_autonego_ctrl(phy_802_3_t *phy_802_3, eth_phy_autoneg_cmd_t cmd, bool *autonego_en_stat) Control autonegotiation mode of Ethernet PHY. - Parameters phy_802_3 -- IEEE 802.3 PHY object infostructure cmd -- autonegotiation command enumeration autonego_en_stat -- [out] autonegotiation enabled flag - - Returns ESP_OK: Ethernet PHY autonegotiation configured successfuly ESP_FAIL: Ethernet PHY autonegotiation configuration fail because some error occured ESP_ERR_INVALID_ARG: invalid value of cmd - - esp_err_t esp_eth_phy_802_3_pwrctl(phy_802_3_t *phy_802_3, bool enable) Power control of Ethernet PHY. - Parameters phy_802_3 -- IEEE 802.3 PHY object infostructure enable -- set true to power ON Ethernet PHY; set false to power OFF Ethernet PHY - - Returns ESP_OK: Ethernet PHY power down mode set successfuly ESP_FAIL: Ethernet PHY power up or power down failed because some error occured - - esp_err_t esp_eth_phy_802_3_set_addr(phy_802_3_t *phy_802_3, uint32_t addr) Set Ethernet PHY address. - Parameters phy_802_3 -- IEEE 802.3 PHY object infostructure addr -- new PHY address - - Returns ESP_OK: Ethernet PHY address set - - esp_err_t esp_eth_phy_802_3_get_addr(phy_802_3_t *phy_802_3, uint32_t *addr) Get Ethernet PHY address. - Parameters phy_802_3 -- IEEE 802.3 PHY object infostructure addr --
PHY is in invalid state to perform requested operation - - esp_err_t esp_eth_phy_802_3_basic_phy_deinit(phy_802_3_t *phy_802_3) Performs basic PHY chip de-initialization. Note It should be called as the last function in PHY specific driver instance - Parameters phy_802_3 -- IEEE 802.3 PHY object infostructure - Returns ESP_OK: de-initialized Ethernet PHY successfully ESP_FAIL: de-initialization of Ethernet PHY failed because some error occurred ESP_ERR_TIMEOUT: MII Management read/write operation timeout ESP_ERR_INVALID_STATE: PHY is in invalid state to perform requested operation - - esp_err_t esp_eth_phy_802_3_read_oui(phy_802_3_t *phy_802_3, uint32_t *oui) Reads raw content of OUI field. - Parameters phy_802_3 --
[out] OUI value - - Returns ESP_OK: OUI field read successfully ESP_FAIL: OUI field read failed because some error occurred ESP_ERR_INVALID_ARG: invalid ouiargument ESP_ERR_TIMEOUT: MII Management read/write operation timeout ESP_ERR_INVALID_STATE: PHY is in invalid state to perform requested operation - - esp_err_t esp_eth_phy_802_3_read_manufac_info(phy_802_3_t *phy_802_3, uint8_t *model, uint8_t *rev) Reads manufacturer’s model and revision number. - Parameters phy_802_3 -- IEEE 802.3 PHY object infostructure model -- [out] Manufacturer’s model number (can be NULL when not required) rev -- [out] Manufacturer’s revision number (can be NULL when not required) - - Returns ESP_OK: Manufacturer’s info read successfully ESP_FAIL: Manufacturer’s info read failed because some error occurred ESP_ERR_TIMEOUT: MII Management read/write operation timeout ESP_ERR_INVALID_STATE: PHY is in invalid state to perform requested operation - - inline phy_802_3_t *esp_eth_phy_into_phy_802_3(esp_eth_phy_t *phy) Returns address to parent IEEE 802.3 PHY object infostructure. - Parameters phy -- Ethernet PHY instance - Returns phy_802_3_t* address to parent IEEE 802.3 PHY object infostructure - - esp_err_t esp_eth_phy_802_3_obj_config_init(phy_802_3_t *phy_802_3, const eth_phy_config_t *config) Initializes configuration of parent IEEE 802.3 PHY object infostructure. - Parameters phy_802_3 -- Address to IEEE 802.3 PHY object infostructure config -- Configuration of the IEEE 802.3 PHY object - - Returns ESP_OK: configuration initialized successfully ESP_ERR_INVALID_ARG: invalid configargument - Structures - struct phy_802_3_t IEEE 802.3 PHY object infostructure. Public Members - esp_eth_phy_t parent Parent Ethernet PHY instance - esp_eth_mediator_t *eth Mediator of Ethernet driver - int addr PHY address - uint32_t reset_timeout_ms Reset timeout value (Unit: ms) - uint32_t autonego_timeout_ms Auto-negotiation timeout value (Unit: ms) - eth_link_t link_status Current Link status - int reset_gpio_num Reset GPIO number, -1 means no hardware reset - esp_eth_phy_t parent Header File This header file can be included with: #include "esp_eth_netif_glue.h" This header file is a part of the API provided by the esp_ethcomponent.
esp_eth Functions - esp_eth_netif_glue_handle_t esp_eth_new_netif_glue(esp_eth_handle_t eth_hdl) Create a netif glue for Ethernet driver. Note netif glue is used to attach io driver to TCP/IP netif - Parameters eth_hdl -- Ethernet driver handle - Returns glue object, which inherits esp_netif_driver_base_t - esp_err_t esp_eth_del_netif_glue(esp_eth_netif_glue_handle_t eth_netif_glue) Delete netif glue of Ethernet driver. - Parameters eth_netif_glue -- netif glue - Returns -ESP_OK: delete netif glue successfully Type Definitions - typedef struct esp_eth_netif_glue_t *esp_eth_netif_glue_handle_t Handle of netif glue - an intermediate layer between netif and Ethernet driver.
Thread Introduction Thread is an IP-based mesh networking protocol. It is based on the 802.15.4 physical and MAC layer. Application Examples The openthread directory of ESP-IDF examples contains the following applications: The OpenThread interactive shell openthread/ot_cli The Thread Border Router openthread/ot_br The Thread Radio Co-Processor openthread/ot_rcp API Reference For manipulating the Thread network, the OpenThread API shall be used. The OpenThread API docs can be found at the OpenThread API docs. ESP-IDF provides extra APIs for launching and managing the OpenThread stack, binding to network interfaces and border routing features. Header File This header file can be included with: #include "esp_openthread.h" This header file is a part of the API provided by the openthreadcomponent. To declare that your component depends on openthread, add the following to your CMakeLists.txt: REQUIRES openthread or PRIV_REQUIRES
Note The OpenThread instance will also be initialized in this function. - Parameters init_config -- [in] The initialization configuration. - Returns ESP_OK on success ESP_ERR_NO_MEM if allocation has failed ESP_ERR_INVALID_ARG if radio or host connection mode not supported ESP_ERR_INVALID_STATE if already initialized - - esp_err_t esp_openthread_auto_start(otOperationalDatasetTlvs *datasetTlvs) Starts the Thread protocol operation and attaches to a Thread network. - Parameters datasetTlvs -- [in] The operational dataset (TLV encoded), if it's NULL, the function will generate the dataset based on the configurations from kconfig. - Returns ESP_OK on success ESP_FAIL on failures - - esp_err_t esp_openthread_launch_mainloop(void) Launches the OpenThread main loop. Note This function will not return unless error happens when running the OpenThread stack. - Returns ESP_OK on success ESP_ERR_NO_MEM if allocation has failed ESP_FAIL on other failures - - esp_err_t esp_openthread_deinit(void) This function performs OpenThread stack and platform driver deinitialization. - Returns ESP_OK on success ESP_ERR_INVALID_STATE if not initialized - - otInstance *esp_openthread_get_instance(void) This function acquires the underlying OpenThread instance. Note This function can be called on other tasks without lock. - Returns The OpenThread instance pointer Header File This header file can be included with: #include "esp_openthread_types.h" This header file is a part of the API provided by the openthreadcomponent. To declare that your component depends on openthread, add the following to your CMakeLists.txt: REQUIRES openthread or PRIV_REQUIRES
openthread Structures - struct esp_openthread_role_changed_event_t OpenThread role changed event data. - struct esp_openthread_mainloop_context_t This structure represents a context for a select() based mainloop. - struct esp_openthread_uart_config_t The uart port config for OpenThread. Public Members - uart_port_t port UART port number - uart_config_t uart_config UART configuration, see uart_config_t docs - gpio_num_t rx_pin UART RX pin - gpio_num_t tx_pin UART TX pin - uart_port_t port - struct esp_openthread_spi_host_config_t The spi port config for OpenThread. Public Members - spi_host_device_t host_device SPI host device - spi_dma_chan_t dma_channel DMA channel - spi_bus_config_t spi_interface SPI bus - spi_device_interface_config_t spi_device SPI peripheral device - gpio_num_t intr_pin SPI interrupt pin - spi_host_device_t host_device - struct esp_openthread_spi_slave_config_t
Public Members - spi_host_device_t host_device SPI host device - spi_bus_config_t bus_config SPI bus config - spi_slave_interface_config_t slave_config SPI slave config - gpio_num_t intr_pin SPI interrupt pin - spi_host_device_t host_device - struct esp_openthread_radio_config_t The OpenThread radio configuration. Public Members - esp_openthread_radio_mode_t radio_mode The radio mode - esp_openthread_uart_config_t radio_uart_config The uart configuration to RCP - esp_openthread_spi_host_config_t radio_spi_config The spi configuration to RCP - esp_openthread_radio_mode_t radio_mode - struct esp_openthread_host_connection_config_t The OpenThread host connection configuration. Public Members - esp_openthread_host_connection_mode_t host_connection_mode The host connection mode - esp_openthread_uart_config_t host_uart_config The uart configuration to host - usb_serial_jtag_driver_config_t host_usb_config The usb configuration to host - esp_openthread_spi_slave_config_t spi_slave_config The spi configuration to host - esp_openthread_host_connection_mode_t host_connection_mode - struct esp_openthread_port_config_t The OpenThread port specific configuration. - struct esp_openthread_platform_config_t The OpenThread platform configuration.
Public Members - esp_openthread_radio_config_t radio_config The radio configuration - esp_openthread_host_connection_config_t host_config The host connection configuration - esp_openthread_port_config_t port_config The port configuration - esp_openthread_radio_config_t radio_config Type Definitions - typedef void (*esp_openthread_rcp_failure_handler)(void) Enumerations - enum esp_openthread_event_t OpenThread event declarations. Values: - enumerator OPENTHREAD_EVENT_START OpenThread stack start - enumerator OPENTHREAD_EVENT_STOP OpenThread stack stop - enumerator OPENTHREAD_EVENT_DETACHED OpenThread detached - enumerator OPENTHREAD_EVENT_ATTACHED OpenThread attached - enumerator OPENTHREAD_EVENT_ROLE_CHANGED OpenThread role changed - enumerator OPENTHREAD_EVENT_IF_UP OpenThread network interface up - enumerator OPENTHREAD_EVENT_IF_DOWN OpenThread network interface down - enumerator OPENTHREAD_EVENT_GOT_IP6 OpenThread stack added IPv6 address - enumerator OPENTHREAD_EVENT_LOST_IP6 OpenThread stack removed IPv6 address - enumerator OPENTHREAD_EVENT_MULTICAST_GROUP_JOIN OpenThread stack joined IPv6 multicast group - enumerator OPENTHREAD_EVENT_MULTICAST_GROUP_LEAVE OpenThread stack left IPv6 multicast group - enumerator OPENTHREAD_EVENT_TREL_ADD_IP6 OpenThread stack added TREL IPv6 address - enumerator OPENTHREAD_EVENT_TREL_REMOVE_IP6 OpenThread stack removed TREL IPv6 address - enumerator OPENTHREAD_EVENT_TREL_MULTICAST_GROUP_JOIN OpenThread stack joined TREL IPv6 multicast group - enumerator OPENTHREAD_EVENT_SET_DNS_SERVER OpenThread stack set DNS server > - enumerator OPENTHREAD_EVENT_START - enum esp_openthread_radio_mode_t The radio mode of OpenThread. Values: - enumerator RADIO_MODE_NATIVE Use the native 15.4 radio - enumerator RADIO_MODE_UART_RCP UART connection to a 15.4 capable radio co-processor (RCP) - enumerator RADIO_MODE_SPI_RCP SPI connection to a 15.4 capable radio co-processor (RCP) - enumerator RADIO_MODE_MAX Using for parameter check - enumerator RADIO_MODE_NATIVE - enum esp_openthread_host_connection_mode_t How OpenThread connects to the host. Values: - enumerator HOST_CONNECTION_MODE_NONE Disable host connection - enumerator HOST_CONNECTION_MODE_CLI_UART CLI UART connection to the host - enumerator HOST_CONNECTION_MODE_CLI_USB CLI USB connection to the host - enumerator HOST_CONNECTION_MODE_RCP_UART RCP UART connection to the host - enumerator HOST_CONNECTION_MODE_RCP_SPI RCP SPI connection to the host - enumerator HOST_CONNECTION_MODE_MAX Using for parameter check - enumerator HOST_CONNECTION_MODE_NONE Header File This header file can be included with: #include "esp_openthread_lock.h" This header file is a part of the API provided by the openthreadcomponent. To declare that your component depends on openthread, add the following to your CMakeLists.txt: REQUIRES openthread or PRIV_REQUIRES
This function initializes the OpenThread API lock. - Returns ESP_OK on success ESP_ERR_NO_MEM if allocation has failed ESP_ERR_INVALID_STATE if already initialized - - void esp_openthread_lock_deinit(void) This function deinitializes the OpenThread API lock. - bool esp_openthread_lock_acquire(TickType_t block_ticks) This function acquires the OpenThread API lock. Note Every OT APIs that takes an otInstance argument MUST be protected with this API lock except that the call site is in OT callbacks. - Parameters block_ticks -- [in] The maxinum number of RTOS ticks to wait for the lock. - Returns True on lock acquired False on failing to acquire the lock with the timeout. - - void esp_openthread_lock_release(void) This function releases the OpenThread API lock. - bool esp_openthread_task_switching_lock_acquire(TickType_t block_ticks) This function acquires the OpenThread API task switching lock.
[in] The maxinum number of RTOS ticks to wait for the lock. - Returns True on lock acquired False on failing to acquire the lock with the timeout. - - void esp_openthread_task_switching_lock_release(void) This function releases the OpenThread API task switching lock. Header File This header file can be included with: #include "esp_openthread_netif_glue.h" This header file is a part of the API provided by the openthreadcomponent. To declare that your component depends on openthread, add the following to your CMakeLists.txt: REQUIRES openthread or PRIV_REQUIRES
openthread Functions - void *esp_openthread_netif_glue_init(const esp_openthread_platform_config_t *config) This function initializes the OpenThread network interface glue. - Parameters config -- [in] The platform configuration. - Returns glue pointer on success NULL on failure - - void esp_openthread_netif_glue_deinit(void) This function deinitializes the OpenThread network interface glue. - esp_netif_t *esp_openthread_get_netif(void) This function acquires the OpenThread netif. - Returns The OpenThread netif or NULL if not initialzied. Macros - ESP_NETIF_INHERENT_DEFAULT_OPENTHREAD() Default configuration reference of OT esp-netif. - ESP_NETIF_DEFAULT_OPENTHREAD() Header File components/openthread/include/esp_openthread_border_router.h This header file can be included with: #include "esp_openthread_border_router.h" This header file is a part of the API provided by the openthreadcomponent.
To declare that your component depends on openthread, add the following to your CMakeLists.txt: REQUIRES openthread or PRIV_REQUIRES openthread Functions - void esp_openthread_set_backbone_netif(esp_netif_t *backbone_netif) Sets the backbone interface used for border routing. Note This function must be called before esp_openthread_init - Parameters backbone_netif -- [in] The backbone network interface (WiFi or ethernet) - esp_err_t esp_openthread_border_router_init(void) Initializes the border router features of OpenThread. Note Calling this function will make the device behave as an OpenThread border router. Kconfig option CONFIG_OPENTHREAD_BORDER_ROUTER is required. - Returns ESP_OK on success ESP_ERR_NOT_SUPPORTED if feature not supported ESP_ERR_INVALID_STATE if already initialized ESP_FIAL on other failures - - esp_err_t esp_openthread_border_router_deinit(void) Deinitializes the border router features of OpenThread. - Returns ESP_OK on success ESP_ERR_INVALID_STATE if not initialized ESP_FIAL on other failures - - esp_netif_t *esp_openthread_get_backbone_netif(void) Gets the backbone interface of OpenThread border router. - Returns The backbone interface or NULL if border router not initialized. - void esp_openthread_register_rcp_failure_handler(esp_openthread_rcp_failure_handler handler) Registers the callback for RCP failure. - esp_err_t esp_openthread_rcp_deinit(void) Deinitializes the conneciton to RCP. - Returns ESP_OK on success ESP_ERR_INVALID_STATE if fail to deinitialize RCP -
ESP-NETIF The purpose of the ESP-NETIF library is twofold: It provides an abstraction layer for the application on top of the TCP/IP stack. This allows applications to choose between IP stacks in the future. The APIs it provides are thread-safe, even if the underlying TCP/IP stack APIs are not. ESP-IDF currently implements ESP-NETIF for the lwIP TCP/IP stack only. However, the adapter itself is TCP/IP implementation-agnostic and allows different implementations. It is also possible to use a custom TCP/IP stack with ESP-IDF, provided it implements BSD API. For more information on building ESP-IDF without lwIP, please refer to components/esp_netif_stack/README.md. Some ESP-NETIF API functions are intended to be called by application code, for example, to get or set interface IP addresses, and configure DHCP. Other functions are intended for internal ESP-IDF use by the network driver layer. In many cases, applications do not need to call ESP-NETIF APIs directly as they are called by the default network event handlers.
+----------------------------------------+ . . | * . . | * --------+ +===========================+ * +-----------------------+ | | new/config get/set/apps | * | init | | | |...*.....| Apps (DHCP, SNTP) | | |---------------------------| * | | init | | |**** | | start |************| event handler |*********| DHCP | stop | | | | | | |---------------------------| | | | | | | NETIF | +-----| | | +-----------------+ | | glue|---<----|---| esp_netif_transmit |--<------| netif_output | | | | | | | | | | | |--->----|---| esp_netif_receive |-->------| netif_input | | | | | | | + ----------------+ | | |...<....|...| esp_netif_free_rx_buffer |...<.....| packet buffer | +-----| | | | | | | | | | | | | (D) | (B) | | | | (C) | +-----------------------+ --------+ | | +===========================+ COMMUNICATION | | NETWORK STACK DRIVER | | ESP-NETIF | | +------------------+ | | +---------------------------+.........| open/close | | | | | | | | -<--| l2tap_write |-----<---| write | | | | | | ---->--| esp_vfs_l2tap_eth_filter |----->---| read | | | | | | (E) | +------------------+ +---------------------------+ USER CODE ESP-NETIF L2 TAP Data and Event Flow in the Diagram ........
There is only one ESP-NETIF L2 TAP interface device (path name) available. However multiple file descriptors with different configurations can be opened at a time since the ESP-NETIF L2 TAP interface can be understood as a generic entry point to the Layer 2 infrastructure. What is important is then the specific configuration of the particular file descriptor. It can be configured to give access to a specific Network Interface identified by if_key (e.g., ETH_DEF) and to filter only specific frames based on their type (e.g., Ethernet type in the case of IEEE 802.3). Filtering only specific frames is crucial since the ESP-NETIF L2 TAP needs to exist along with the IP stack and so the IP-related traffic (IP, ARP, etc.) should not be passed directly to the user application. Even though this option is still configurable, it is not recommended in standard use cases. Filtering is also advantageous from the perspective of the user's application, as it only gets access to the frame types it is interested in, and the remaining traffic is either passed to other L2 TAP file descriptors or to the IP stack. ESP-NETIF L2 TAP Interface Usage Manual Initialization To be able to use the ESP-NETIF L2 TAP interface, it needs to be enabled in Kconfig by CONFIG_ESP_NETIF_L2_TAP first and then registered by esp_vfs_l2tap_intf_register() prior usage of any VFS function. open() Once the ESP-NETIF L2 TAP is registered, it can be opened at path name "/dev/net/tap". The same path name can be opened multiple times up to CONFIG_ESP_NETIF_L2_TAP_MAX_FDS and multiple file descriptors with a different configuration may access the Data Link Layer frames. The ESP-NETIF L2 TAP can be opened with the O_NONBLOCK file status flag to make sure the read() does not block. Note that the write() may block in the current implementation when accessing a Network interface since it is a shared resource among multiple ESP-NETIF L2 TAP file descriptors and IP stack, and there is currently no queuing mechanism deployed. The file status flag can be retrieved and modified using fcntl(). On success, open() returns the new file descriptor (a nonnegative integer).
On error, -1 is returned, and errno is set to indicate the error. ioctl() The newly opened ESP-NETIF L2 TAP file descriptor needs to be configured prior to its usage since it is not bounded to any specific Network Interface and no frame type filter is configured. The following configuration options are available to do so: - L2TAP_S_INTF_DEVICE- bounds the file descriptor to a specific Network Interface that is identified by its if_key. ESP-NETIF Network Interface if_keyis passed to ioctl()as the third parameter. Note that default Network Interfaces if_key's used in ESP-IDF can be found in esp_netif/include/esp_netif_defaults.h. - L2TAP_S_DEVICE_DRV_HNDL- is another way to bound the file descriptor to a specific Network Interface. In this case, the Network interface is identified directly by IO Driver handle (e.g., esp_eth_handle_tin case of Ethernet). The IO Driver handle is passed to ioctl()as the third parameter. - L2TAP_S_RCV_FILTER- sets the filter to frames with the type to be passed to the file descriptor. In the case of Ethernet frames, the frames are to be filtered based on the Length and Ethernet type field. In case the filter value is set less than or equal to 0x05DC, the Ethernet type field is considered to represent IEEE802.3 Length Field, and all frames with values in interval <0, 0x05DC> at that field are passed to the file descriptor. The IEEE802.2 logical link control (LLC) resolution is then expected to be performed by the user's application. In case the filter value is set greater than 0x05DC, the Ethernet type field is considered to represent protocol identification and only frames that are equal to the set value are to be passed to the file descriptor. All above-set configuration options have a getter counterpart option to read the current settings. Warning The file descriptor needs to be firstly bounded to a specific Network Interface by L2TAP_S_INTF_DEVICE or L2TAP_S_DEVICE_DRV_HNDL to make L2TAP_S_RCV_FILTER option available. Note VLAN-tagged frames are currently not recognized. If the user needs to process VLAN-tagged frames, they need a set filter to be equal to the VLAN tag (i.e., 0x8100 or 0x88A8) and process the VLAN-tagged frames in the user application. Note L2TAP_S_DEVICE_DRV_HNDL is particularly useful when the user's application does not require the usage of an IP stack and so ESP-NETIF is not required to be initialized too. As a result, Network Interface cannot be identified by its if_key and hence it needs to be identified directly by its IO Driver handle.
On error, -1 is returned, and errno is set to indicate the error. read() Opened and configured ESP-NETIF L2 TAP file descriptor can be accessed by read() to get inbound frames. The read operation can be either blocking or non-blocking based on the actual state of the O_NONBLOCK file status flag. When the file status flag is set to blocking, the read operation waits until a frame is received and the context is switched to other tasks. When the file status flag is set to non-blocking, the read operation returns immediately. In such case, either a frame is returned if it was already queued or the function indicates the queue is empty. The number of queued frames associated with one file descriptor is limited by CONFIG_ESP_NETIF_L2_TAP_RX_QUEUE_SIZE Kconfig option. Once the number of queued frames reached a configured threshold, the newly arrived frames are dropped until the queue has enough room to accept incoming traffic (Tail Drop queue management). read() returns the number of bytes read. Zero is returned when the size of the destination buffer is 0. On error, -1 is returned, and errno is set to indicate the error. O_NONBLOCK), and the read would block. write() A raw Data Link Layer frame can be sent to Network Interface via opened and configured ESP-NETIF L2 TAP file descriptor. The user's application is responsible to construct the whole frame except for fields which are added automatically by the physical interface device. The following fields need to be constructed by the user's application in case of an Ethernet link: source/destination MAC addresses, Ethernet type, actual protocol header, and user data. The length of these fields is as follows: | Destination MAC | Source MAC | Type/Length | Payload (protocol header/data) | 6 B | 6 B | 2 B | 0-1486 B In other words, there is no additional frame processing performed by the ESP-NETIF L2 TAP interface. It only checks the Ethernet type of the frame is the same as the filter configured in the file descriptor. If the Ethernet type is different, an error is returned and the frame is not sent. Note that the write() may block in the current implementation when accessing a Network interface since it is a shared resource among multiple ESP-NETIF L2 TAP file descriptors and IP stack, and there is currently no queuing mechanism deployed. write() returns the number of bytes written. Zero is returned when the size of the input buffer is 0. On error, -1 is returned, and errno is set to indicate the error. close() Opened ESP-NETIF L2 TAP file descriptor can be closed by the close() to free its allocated resources. The ESP-NETIF L2 TAP implementation of close() may block. On the other hand, it is thread-safe and can be called from a different task than the file descriptor is actually used. If such a situation occurs and one task is blocked in the I/O operation and another task tries to close the file descriptor, the first task is unblocked. The first's task read operation then ends with an error.
close() returns zero. On error, -1 is returned, and errno is set to indicate the error. select() Select is used in a standard way, just CONFIG_VFS_SUPPORT_SELECT needs to be enabled to make the select() function available. SNTP API You can find a brief introduction to SNTP in general, its initialization code, and basic modes in Section SNTP Time Synchronization in System Time. This section provides more details about specific use cases of the SNTP service, with statically configured servers, or use the DHCP-provided servers, or both. The workflow is usually very simple: Initialize and configure the service using esp_netif_sntp_init(). Start the service via esp_netif_sntp_start(). This step is not needed if we auto-started the service in the previous step (default). It is useful to start the service explicitly after connecting if we want to use the DHCP-obtained NTP servers. Please note, this option needs to be enabled before connecting, but the SNTP service should be started after. Wait for the system time to synchronize using esp_netif_sntp_sync_wait()(only if needed). Stop and destroy the service using esp_netif_sntp_deinit(). Basic Mode with Statically Defined Server(s) Initialize the module with the default configuration after connecting to the network. Note that it is possible to provide multiple NTP servers in the configuration struct: esp_sntp_config_t config =
[inout] pointer to the object to be configured driver_config -- [in] pointer esp-netif io driver related configuration - - Returns ESP_OK on success ESP_ERR_ESP_NETIF_INVALID_PARAMS if invalid parameters provided - - esp_err_t esp_netif_attach(esp_netif_t *esp_netif, esp_netif_iodriver_handle driver_handle) Attaches esp_netif instance to the io driver handle. Calling this function enables connecting specific esp_netif object with already initialized io driver to update esp_netif object with driver specific configuration (i.e. calls post_attach callback, which typically sets io driver callbacks to esp_netif instance and starts the driver) - Parameters esp_netif -- [inout] pointer to esp_netif object to be attached driver_handle -- [in] pointer to the driver handle - - Returns ESP_OK on success ESP_ERR_ESP_NETIF_DRIVER_ATTACH_FAILED if driver's pot_attach callback failed - - esp_err_t esp_netif_receive(esp_netif_t *esp_netif, void *buffer, size_t len, void *eb) Passes the raw packets from communication media to the appropriate TCP/IP stack. This function is called from the configured (peripheral) driver layer. The data are then forwarded as frames to the TCP/IP stack.
[in] Handle to esp-netif instance addr -- [in] The multicast group to join - - Returns ESP_OK ESP_ERR_ESP_NETIF_INVALID_PARAMS ESP_ERR_ESP_NETIF_MLD6_FAILED ESP_ERR_NO_MEM - - esp_err_t esp_netif_leave_ip6_multicast_group(esp_netif_t *esp_netif, const esp_ip6_addr_t *addr) Cause the TCP/IP stack to leave a IPv6 multicast group. - Parameters esp_netif -- [in] Handle to esp-netif instance addr -- [in] The multicast group to leave - - Returns ESP_OK ESP_ERR_ESP_NETIF_INVALID_PARAMS ESP_ERR_ESP_NETIF_MLD6_FAILED ESP_ERR_NO_MEM - - esp_err_t esp_netif_set_mac(esp_netif_t *esp_netif, uint8_t mac []) Set the mac address for the interface instance. - Parameters esp_netif -- [in] Handle to esp-netif instance mac -- [in] Desired mac address for the related network interface - - Returns ESP_OK - success ESP_ERR_ESP_NETIF_IF_NOT_READY - interface status error ESP_ERR_NOT_SUPPORTED - mac not supported on this interface - - esp_err_t esp_netif_get_mac(esp_netif_t *esp_netif, uint8_t mac []) Get the mac address for the interface instance. -
[in] Handle to esp-netif instance mac -- [out] Resultant mac address for the related network interface - - Returns ESP_OK - success ESP_ERR_ESP_NETIF_IF_NOT_READY - interface status error ESP_ERR_NOT_SUPPORTED - mac not supported on this interface - - esp_err_t esp_netif_set_hostname(esp_netif_t *esp_netif, const char *hostname) Set the hostname of an interface. The configured hostname overrides the default configuration value CONFIG_LWIP_LOCAL_HOSTNAME. Please note that when the hostname is altered after interface started/connected the changes would only be reflected once the interface restarts/reconnects - Parameters esp_netif --
- esp_err_t esp_netif_get_ip_info(esp_netif_t *esp_netif, esp_netif_ip_info_t *ip_info) Get interface's IP address information. If the interface is up, IP information is read directly from the TCP/IP stack. If the interface is down, IP information is read from a copy kept in the ESP-NETIF instance - Parameters esp_netif -- [in] Handle to esp-netif instance ip_info -- [out] If successful, IP information will be returned in this argument. - - Returns ESP_OK ESP_ERR_ESP_NETIF_INVALID_PARAMS - - esp_err_t esp_netif_get_old_ip_info(esp_netif_t *esp_netif, esp_netif_ip_info_t *ip_info)
Get interface's old IP information. Returns an "old" IP address previously stored for the interface when the valid IP changed. If the IP lost timer has expired (meaning the interface was down for longer than the configured interval) then the old IP information will be zero. - Parameters esp_netif -- [in] Handle to esp-netif instance ip_info -- [out] If successful, IP information will be returned in this argument. - - Returns ESP_OK ESP_ERR_ESP_NETIF_INVALID_PARAMS - - esp_err_t esp_netif_set_ip_info(esp_netif_t *esp_netif, const esp_netif_ip_info_t *ip_info) Set interface's IP address information. This function is mainly used to set a static IP on an interface. If the interface is up, the new IP information is set directly in the TCP/IP stack. The copy of IP information kept in the ESP-NETIF instance is also updated (this copy is returned if the IP is queried while the interface is still down.) Note DHCP client/server must be stopped (if enabled for this interface) before setting new IP information. Note Calling this interface for may generate a SYSTEM_EVENT_STA_GOT_IP or SYSTEM_EVENT_ETH_GOT_IP event. - Parameters esp_netif -- [in] Handle to esp-netif instance ip_info -- [in] IP information to set on the specified interface - - Returns ESP_OK ESP_ERR_ESP_NETIF_INVALID_PARAMS ESP_ERR_ESP_NETIF_DHCP_NOT_STOPPED If DHCP server or client is still running - - esp_err_t esp_netif_set_old_ip_info(esp_netif_t *esp_netif, const esp_netif_ip_info_t *ip_info) Set interface old IP information. This function is called from the DHCP client (if enabled), before a new IP is set. It is also called from the default handlers for the SYSTEM_EVENT_STA_CONNECTED and SYSTEM_EVENT_ETH_CONNECTED events. Calling this function stores the previously configured IP, which can be used to determine if the IP changes in the future. If the interface is disconnected or down for too long, the "IP lost timer" will expire (after the configured interval) and set the old IP information to zero. - Parameters esp_netif --
[in] Handle to esp-netif instance ip_info -- [in] Store the old IP information for the specified interface - - Returns ESP_OK ESP_ERR_ESP_NETIF_INVALID_PARAMS - - int esp_netif_get_netif_impl_index(esp_netif_t *esp_netif) Get net interface index from network stack implementation. Note This index could be used in setsockopt()to bind socket with multicast interface - Parameters esp_netif -- [in] Handle to esp-netif instance - Returns implementation specific index of interface represented with supplied esp_netif - esp_err_t esp_netif_get_netif_impl_name(esp_netif_t *esp_netif, char *name) Get net interface name from network stack implementation. Note This name could be used in setsockopt()to bind socket with appropriate interface - Parameters esp_netif -- [in] Handle to esp-netif instance name -- [out] Interface name as specified in underlying TCP/IP stack. Note that the actual name will be copied to the specified buffer, which must be allocated to hold maximum interface name size (6 characters for lwIP) - - Returns ESP_OK ESP_ERR_ESP_NETIF_INVALID_PARAMS - - esp_err_t esp_netif_napt_enable(esp_netif_t *esp_netif) Enable NAPT on an interface. Note Enable operation can be performed only on one interface at a time. NAPT cannot be enabled on multiple interfaces according to this implementation.
- Parameters esp_netif -- [in] Handle to esp-netif instance - Returns ESP_OK ESP_FAIL ESP_ERR_NOT_SUPPORTED - - esp_err_t esp_netif_napt_disable(esp_netif_t *esp_netif) Disable NAPT on an interface. - Parameters esp_netif -- [in] Handle to esp-netif instance - Returns ESP_OK ESP_FAIL ESP_ERR_NOT_SUPPORTED - - esp_err_t esp_netif_dhcps_option(esp_netif_t *esp_netif, esp_netif_dhcp_option_mode_t opt_op, esp_netif_dhcp_option_id_t opt_id, void *opt_val, uint32_t opt_len) Set or Get DHCP server option. - Parameters esp_netif -- [in] Handle to esp-netif instance opt_op -- [in] ESP_NETIF_OP_SET to set an option, ESP_NETIF_OP_GET to get an option.
[in] Length of the option parameter. - - Returns ESP_OK ESP_ERR_ESP_NETIF_INVALID_PARAMS ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED - - esp_err_t esp_netif_dhcpc_start(esp_netif_t *esp_netif) Start DHCP client (only if enabled in interface object) Note The default event handlers for the SYSTEM_EVENT_STA_CONNECTED and SYSTEM_EVENT_ETH_CONNECTED events call this function. - Parameters esp_netif -- [in] Handle to esp-netif instance - Returns ESP_OK ESP_ERR_ESP_NETIF_INVALID_PARAMS ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED ESP_ERR_ESP_NETIF_DHCPC_START_FAILED - - esp_err_t esp_netif_dhcpc_stop(esp_netif_t *esp_netif) Stop DHCP client (only if enabled in interface object) Note Calling action_netif_stop() will also stop the DHCP Client if it is running. - Parameters esp_netif -- [in] Handle to esp-netif instance - Returns ESP_OK ESP_ERR_ESP_NETIF_INVALID_PARAMS ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED ESP_ERR_ESP_NETIF_IF_NOT_READY - - esp_err_t esp_netif_dhcpc_get_status(esp_netif_t *esp_netif, esp_netif_dhcp_status_t *status) Get DHCP client status. - Parameters esp_netif -- [in] Handle to esp-netif instance status -- [out] If successful, the status of DHCP client will be returned in this argument.
- - Returns ESP_OK - - esp_err_t esp_netif_dhcps_get_status(esp_netif_t *esp_netif, esp_netif_dhcp_status_t *status) Get DHCP Server status. - Parameters esp_netif -- [in] Handle to esp-netif instance status -- [out] If successful, the status of the DHCP server will be returned in this argument. - - Returns ESP_OK - - esp_err_t esp_netif_dhcps_start(esp_netif_t *esp_netif) Start DHCP server (only if enabled in interface object) - Parameters esp_netif -- [in] Handle to esp-netif instance - Returns ESP_OK ESP_ERR_ESP_NETIF_INVALID_PARAMS ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED - - esp_err_t esp_netif_dhcps_stop(esp_netif_t *esp_netif) Stop DHCP server (only if enabled in interface object) - Parameters esp_netif -- [in] Handle to esp-netif instance - Returns ESP_OK ESP_ERR_ESP_NETIF_INVALID_PARAMS ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED ESP_ERR_ESP_NETIF_IF_NOT_READY - - esp_err_t esp_netif_dhcps_get_clients_by_mac(esp_netif_t *esp_netif, int num, esp_netif_pair_mac_ip_t *mac_ip_pair)
[in] Handle to esp-netif instance num -- [in] Number of clients with specified MAC addresses in the array of pairs mac_ip_pair -- [inout] Array of pairs of MAC and IP addresses (MAC are inputs, IP outputs) - - Returns ESP_OK on success ESP_ERR_ESP_NETIF_INVALID_PARAMS on invalid params ESP_ERR_NOT_SUPPORTED if DHCP server not enabled - - esp_err_t esp_netif_set_dns_info(esp_netif_t *esp_netif, esp_netif_dns_type_t type, esp_netif_dns_info_t *dns) Set DNS Server information. This function behaves differently if DHCP server or client is enabled If DHCP client is enabled, main and backup DNS servers will be updated automatically from the DHCP lease if the relevant DHCP options are set. Fallback DNS Server is never updated from the DHCP lease and is designed to be set via this API. If DHCP client is disabled, all DNS server types can be set via this API only. If DHCP server is enabled, the Main DNS Server setting is used by the DHCP server to provide a DNS Server option to DHCP clients (Wi-Fi stations). The default Main DNS server is typically the IP of the DHCP server itself. This function can override it by setting server type ESP_NETIF_DNS_MAIN. Other DNS Server types are not supported for the DHCP server. To propagate the DNS info to client, please stop the DHCP server before using this API. - Parameters esp_netif --
[in] Handle to esp-netif instance type -- [in] Type of DNS Server to set: ESP_NETIF_DNS_MAIN, ESP_NETIF_DNS_BACKUP, ESP_NETIF_DNS_FALLBACK dns -- [in] DNS Server address to set - - Returns ESP_OK on success ESP_ERR_ESP_NETIF_INVALID_PARAMS invalid params - - - esp_err_t esp_netif_get_dns_info(esp_netif_t *esp_netif, esp_netif_dns_type_t type, esp_netif_dns_info_t *dns) Get DNS Server information. Return the currently configured DNS Server address for the specified interface and Server type. This may be result of a previous call to esp_netif_set_dns_info(). If the interface's DHCP client is enabled, the Main or Backup DNS Server may be set by the current DHCP lease.
- Parameters esp_netif -- [in] Handle to esp-netif instance type -- [in] Type of DNS Server to get: ESP_NETIF_DNS_MAIN, ESP_NETIF_DNS_BACKUP, ESP_NETIF_DNS_FALLBACK dns -- [out] DNS Server result is written here on success - - Returns ESP_OK on success ESP_ERR_ESP_NETIF_INVALID_PARAMS invalid params - - esp_err_t esp_netif_create_ip6_linklocal(esp_netif_t *esp_netif) Create interface link-local IPv6 address. Cause the TCP/IP stack to create a link-local IPv6 address for the specified interface. This function also registers a callback for the specified interface, so that if the link-local address becomes verified as the preferred address then a SYSTEM_EVENT_GOT_IP6 event will be sent. - Parameters esp_netif -- [in] Handle to esp-netif instance - Returns ESP_OK ESP_ERR_ESP_NETIF_INVALID_PARAMS - - esp_err_t esp_netif_get_ip6_linklocal(esp_netif_t *esp_netif, esp_ip6_addr_t *if_ip6) Get interface link-local IPv6 address. If the specified interface is up and a preferred link-local IPv6 address has been created for the interface, return a copy of it. - Parameters esp_netif -- [in] Handle to esp-netif instance if_ip6 -- [out] IPv6 information will be returned in this argument if successful. - - Returns ESP_OK ESP_FAIL If interface is down, does not have a link-local IPv6 address, or the link-local IPv6 address is not a preferred address. - - esp_err_t esp_netif_get_ip6_global(esp_netif_t *esp_netif, esp_ip6_addr_t *if_ip6) Get interface global IPv6 address. If the specified interface is up and a preferred global IPv6 address has been created for the interface, return a copy of it.
- Parameters esp_netif -- [in] Handle to esp-netif instance if_ip6 -- [out] IPv6 information will be returned in this argument if successful. - - Returns ESP_OK ESP_FAIL If interface is down, does not have a global IPv6 address, or the global IPv6 address is not a preferred address. - - int esp_netif_get_all_ip6(esp_netif_t *esp_netif, esp_ip6_addr_t if_ip6[]) Get all IPv6 addresses of the specified interface. - Parameters esp_netif -- [in] Handle to esp-netif instance if_ip6 -- [out] Array of IPv6 addresses will be copied to the argument - - Returns number of returned IPv6 addresses - void esp_netif_set_ip4_addr(esp_ip4_addr_t *addr, uint8_t a, uint8_t b, uint8_t c, uint8_t d)
Sets IPv4 address to the specified octets. - Parameters addr -- [out] IP address to be set a -- the first octet (127 for IP 127.0.0.1) b -- c -- d -- - - char *esp_ip4addr_ntoa(const esp_ip4_addr_t *addr, char *buf, int buflen) Converts numeric IP address into decimal dotted ASCII representation. - Parameters addr -- ip address in network order to convert buf -- target buffer where the string is stored buflen -- length of buf - - Returns either pointer to buf which now holds the ASCII representation of addr or NULL if buf was too small - uint32_t esp_ip4addr_aton(const char *addr) Ascii internet address interpretation routine The value returned is in network order. - Parameters addr -- IP address in ascii representation (e.g. "127.0.0.1") - Returns ip address in network order - esp_err_t esp_netif_str_to_ip4(const char *src, esp_ip4_addr_t *dst) Converts Ascii internet IPv4 address into esp_ip4_addr_t. - Parameters src -- [in] IPv4 address in ascii representation (e.g. "127.0.0.1") dst -- [out] Address of the target esp_ip4_addr_t structure to receive converted address - - Returns ESP_OK on success ESP_FAIL if conversion failed ESP_ERR_INVALID_ARG if invalid parameter is passed into - - esp_err_t esp_netif_str_to_ip6(const char *src, esp_ip6_addr_t *dst) Converts Ascii internet IPv6 address into esp_ip4_addr_t Zeros in the IP address can be stripped or completely ommited: "2001:db8:85a3:0:0:0:2:1" or "2001:db8::2:1") - Parameters src -- [in] IPv6 address in ascii representation (e.g. ""2001:0db8:85a3:0000:0000:0000:0002:0001") dst -- [out] Address of the target esp_ip6_addr_t structure to receive converted address - - Returns ESP_OK on success ESP_FAIL if conversion failed ESP_ERR_INVALID_ARG if invalid parameter is passed into - - esp_netif_iodriver_handle esp_netif_get_io_driver(esp_netif_t *esp_netif) Gets media driver handle for this esp-netif instance. -
[in] Handle to esp-netif instance - Returns opaque pointer of related IO driver - esp_netif_t *esp_netif_get_handle_from_ifkey(const char *if_key) Searches over a list of created objects to find an instance with supplied if key. - Parameters if_key -- Textual description of network interface - Returns Handle to esp-netif instance - esp_netif_flags_t esp_netif_get_flags(esp_netif_t *esp_netif) Returns configured flags for this interface. - Parameters esp_netif -- [in] Handle to esp-netif instance - Returns Configuration flags - const char *esp_netif_get_ifkey(esp_netif_t *esp_netif) Returns configured interface key for this esp-netif instance. - Parameters esp_netif -- [in] Handle to esp-netif instance - Returns Textual description of related interface - const char *esp_netif_get_desc(esp_netif_t *esp_netif) Returns configured interface type for this esp-netif instance. -
[in] source IP - Structures - struct esp_ip6_addr IPv6 address. - struct _ip_addr IP address. Public Members - esp_ip6_addr_t ip6 IPv6 address type - esp_ip4_addr_t ip4 IPv4 address type - uint8_t type ipaddress type - esp_ip6_addr_t ip6 Macros - esp_netif_htonl(x) - esp_netif_ip4_makeu32(a, b, c, d) - ESP_IP6_ADDR_BLOCK1(ip6addr) - ESP_IP6_ADDR_BLOCK2(ip6addr) - ESP_IP6_ADDR_BLOCK3(ip6addr) - ESP_IP6_ADDR_BLOCK4(ip6addr) - ESP_IP6_ADDR_BLOCK5(ip6addr) - ESP_IP6_ADDR_BLOCK6(ip6addr) - ESP_IP6_ADDR_BLOCK7(ip6addr) - ESP_IP6_ADDR_BLOCK8(ip6addr) - IPSTR - esp_ip4_addr_get_byte(ipaddr, idx) - esp_ip4_addr1(ipaddr) - esp_ip4_addr2(ipaddr) - esp_ip4_addr3(ipaddr) - esp_ip4_addr4(ipaddr) - esp_ip4_addr1_16(ipaddr) - esp_ip4_addr2_16(ipaddr) - esp_ip4_addr3_16(ipaddr) - esp_ip4_addr4_16(ipaddr) - IP2STR(ipaddr) - IPV6STR - IPV62STR(ipaddr) - ESP_IPADDR_TYPE_V4 - ESP_IPADDR_TYPE_V6 - ESP_IPADDR_TYPE_ANY - ESP_IP4TOUINT32(a, b, c, d) - ESP_IP4TOADDR(a, b, c, d) - ESP_IP4ADDR_INIT(a, b, c, d) - ESP_IP6ADDR_INIT(a, b, c, d) - IP4ADDR_STRLEN_MAX - ESP_IP_IS_ANY(addr) Type Definitions - typedef struct esp_ip4_addr esp_ip4_addr_t - typedef struct esp_ip6_addr esp_ip6_addr_t Enumerations Header File This header file can be included with: #include "esp_vfs_l2tap.h" This header file is a part of the API provided by the esp_netifcomponent.
Packet Input/Output According to the diagram shown in the ESP-NETIF Architecture part, the following three API functions for the packet data path must be defined for connecting with ESP-NETIF: The first two functions for transmitting and freeing the rx buffer are provided as callbacks, i.e., they get called from ESP-NETIF (and its underlying TCP/IP stack) and I/O driver provides their implementation. The receiving function on the other hand gets called from the I/O driver, so that the driver's code simply calls esp_netif_receive() on a new data received event. Post Attach Callback A final part of the network interface initialization consists of attaching the ESP-NETIF instance to the I/O driver, by means of calling the following API: esp_err_t esp_netif_attach(esp_netif_t *esp_netif, esp_netif_iodriver_handle driver_handle); It is assumed that the esp_netif_iodriver_handle is a pointer to driver's object, a struct derived from struct esp_netif_driver_base_s, so that the first member of I/O driver structure must be this base structure with pointers to: post-attach function callback related ESP-NETIF instance As a result, the I/O driver has to create an instance of the struct per below: typedef struct my_netif_driver_s { esp_netif_driver_base_t base; /*!< base structure reserved as esp-netif driver */ driver_impl *h; /*!< handle of driver implementation */ } my_netif_driver_t; with actual values of my_netif_driver_t::base.post_attach and the actual drivers handle my_netif_driver_t::h. So when the esp_netif_attach() gets called from the initialization code, the post-attach callback from I/O driver's code gets executed to mutually register callbacks between ESP-NETIF and I/O driver instances. Typically the driver is started as well in the post-attach callback. An example of a simple post-attach callback is outlined below: static esp_err_t