Send a packet over the mesh network - Send a packet to any device in the mesh network. - Send a packet to external IP network. @attention This API is not reentrant. Generally, we suggest esp_mesh_recv_toDS() is called after a connection with IP network is created. Thus data outgoing to external IP network via socket is just from reading esp_mesh_recv_toDS() which avoids unnecessary memory copy.
the address of the final destination of the packet - If the packet is to the root, set this parameter to NULL. - If the packet is to an external IP network, set this parameter to the IPv4:PORT combination. This packet will be delivered to the root firstly, then users need to call esp_mesh_recv_toDS() on the root node to forward this packet to the final IP server address.
pointer to a sending mesh packet - Field size should not exceed MESH_MPS. Note that the size of one mesh packet should not exceed MESH_MTU. - Field proto should be set to data protocol in use (default is MESH_PROTO_BIN for binary). - Field tos should be set to transmission tos (type of service) in use (default is MESH_TOS_P2P for point-to-point reliable). - If the packet is to the root, MESH_TOS_P2P must be set to ensure reliable transmission. - As long as the MESH_TOS_P2P is set, the API is blocking, even if the flag is set with MESH_DATA_NONBLOCK. - As long as the MESH_TOS_DEF is set, the API is non-blocking.
flag
int
bitmap for data sent - Flag is at least one of the three MESH_DATA_P2P/MESH_DATA_FROMDS/MESH_DATA_TODS, which represents the direction of packet sending. - Speed up the route search - If the packet is to an internal device, MESH_DATA_P2P should be set. - If the packet is to the root ("to" parameter isn't NULL) or to external IP network, MESH_DATA_TODS should be set. - If the packet is from the root to an internal device, MESH_DATA_FROMDS should be set. - Specify whether this API is blocking or non-blocking, blocking by default. - In the situation of the root change, MESH_DATA_DROP identifies this packet can be dropped by the new root for upstream data to external IP network, we try our best to avoid data loss caused by the root change, but there is a risk that the new root is running out of memory because most of memory is occupied by the pending data which isn't read out in time by esp_mesh_recv_toDS().
options - In case of sending a packet to a certain group, MESH_OPT_SEND_GROUP is a good choice. In this option, the value field should be set to the target receiver addresses in this group. - Root sends a packet to an internal device, this packet is from external IP network in case the receiver device responds this packet, MESH_OPT_RECV_DS_ADDR is required to attach the target DS address.
opt_count
int
option count - Currently, this API only takes one option, so opt_count is only supported to be 1.
Receive a packet targeted to self over the mesh network @attention Mesh RX queue should be checked regularly to avoid running out of memory. - Use esp_mesh_get_rx_pending() to check the number of packets available in the queue waiting to be received by applications. flag could be MESH_DATA_FROMDS or MESH_DATA_TODS.
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. @attention This API is only called by the root. flag could be MESH_DATA_TODS.