Mespnow API¶
Mespnow (Mesh ESP-NOW) is the encapsulation of ESP-NOW APIs, and it adds to ESP-NOW the retransmission filter, Cyclic Redundancy Check (CRC), and data fragmentation features.
Features¶
- Retransmission filter: Mespnow adds a 16-bit ID to each fragment, and the redundant fragments with the same ID will be discarded.
- Fragmented transmission: When the data packet exceeds the limit of the maximum packet size, Mespnow splits it into fragments before they are transmitted to the target device for reassembly.
- Cyclic Redundancy Check: Mespnow implements CRC when it receives the data packet to ensure the packet is transmitted correctly.
Writing Applications¶
- Prior to the use of Mwifi, Wi-Fi must be initialized;
- Max number of the devices allowed in the network: No more than 20 devices, among which 6 encrypted devices at most, are allowed to be network configured;
- Security: CCMP is used for encrpytion with a 16-byte key.
Application Examples¶
For ESP-MDF examples, please refer to the directory function_demo/mespnow, which includes:
- A simple application that demonstrates how to use Mespnow for the communication between two devices.
API Reference¶
Header File¶
Functions¶
- 
mdf_err_t mespnow_add_peer(wifi_interface_t ifx, const uint8_t *addr, const uint8_t *lmk)¶
- add a peer to espnow peer list based on esp_now_add_peer(…). It is convenient to use simplified MACRO follows. - Return
- ESP_OK
- ESP_FAIL
 
- Parameters
- ifx: Wi-Fi interface that peer uses to send/receive ESPNOW data
- addr: peer mac address
- lmk: local master key. If lmk is NULL, ESPNOW data that this peer sends/receives isn’t encrypted
 
 
- 
mdf_err_t mespnow_del_peer(const uint8_t *addr)¶
- delete a peer from espnow peer list. - Return
- ESP_OK
- ESP_FAIL
 
- Parameters
- addr: peer mac address
 
 
- 
mdf_err_t mespnow_read(mespnow_trans_pipe_e pipe, uint8_t *src_addr, void *data, size_t *size, TickType_t wait_ticks)¶
- read data from espnow - Return
- ESP_OK
- ESP_FAIL
 
- Parameters
- pipe: mespnow packet type
- src_addr: source address
- data: point to received data buffer
- *size: A non-zero pointer to the variable holding the length of out_value. In case out_value is not zero, will be set to the actual length of the value written.
- wait_ticks: wait time if a packet isn’t immediately available
 
 
- 
mdf_err_t mespnow_write(mespnow_trans_pipe_e pipe, const uint8_t *dest_addr, const void *data, size_t size, TickType_t wait_ticks)¶
- write date package to espnow. - It is necessary to add device to espnow_peer befor send data to dest_addr.
- When data_len to write is too long, it may fail duration some package and and the return value is the data len that actually sended.
 - Return
- ESP_OK
- ESP_FAIL
 
- Parameters
- pipe: Pipe of data from espnnow
- dest_addr: Destination address
- data: Point to send data buffer
- size: send data len
- wait_ticks: wait time if a packet isn’t immediately available
 
 
Enumerations¶
- 
enum mespnow_trans_pipe_e¶
- Divide espnnow data into multiple pipes. - Values: - 
MESPNOW_TRANS_PIPE_DEBUG¶
- debug packet: log, coredump, espnow_debug config, ack 
 - 
MESPNOW_TRANS_PIPE_CONTROL¶
- control packet 
 - 
MESPNOW_TRANS_PIPE_MCONFIG¶
- network configuration packet 
 - 
MESPNOW_TRANS_PIPE_RESERVED¶
- reserved for other functiond 
 - 
MESPNOW_TRANS_PIPE_MAX¶
 
-