Compare commits
2 Commits
658624ffa9
...
d8f3956991
Author | SHA1 | Date | |
---|---|---|---|
d8f3956991 | |||
a5ff904e0d |
@ -7,7 +7,7 @@
|
||||
|
||||
## Features
|
||||
|
||||
1. The maximum size of transmitted data is up to 250 / 1490 bytes. Please see attention for details.
|
||||
1. The maximum size of the transmitted data is up to 250 / 1490 bytes. Please see attention for details.
|
||||
2. Support of any data types.
|
||||
3. All nodes are not visible to the network scanner.
|
||||
4. Not required a pre-pairings for data transfer.
|
||||
@ -18,7 +18,8 @@
|
||||
|
||||
1. For correct operation in ESP-NOW + STA mode, your WiFi router must be set to the same channel as ESP-NOW.
|
||||
2. All devices on the network must have the same WiFi channel.
|
||||
3. ESP-NOW supports two versions: v1.0 (RTOS_SDK and ESP-IDF v5.3 and below) and v2.0 (ESP-IDF v5.4 and highter). The maximum packet length supported by v2.0 devices is 1490 bytes, while the maximum packet length supported by v1.0 devices is 250 bytes. The v2.0 devices are capable of receiving packets from both v2.0 and v1.0 devices. In contrast, v1.0 devices can only receive packets from other v1.0 devices. However, v1.0 devices can receive v2.0 packets if the packet length is less than or equal to 250 bytes. For packets exceeding this length, the v1.0 devices will either truncate the data to the first 250 bytes or discard the packet entirely.
|
||||
3. For use encrypted messages, use the application layer.
|
||||
4. ESP-NOW supports two versions: v1.0 (RTOS_SDK and ESP-IDF v5.3 and below) and v2.0 (ESP-IDF v5.4 and highter). The maximum packet length supported by v2.0 devices is 1490 bytes, while the maximum packet length supported by v1.0 devices is 250 bytes. The v2.0 devices are capable of receiving packets from both v2.0 and v1.0 devices. In contrast, v1.0 devices can only receive packets from other v1.0 devices. However, v1.0 devices can receive v2.0 packets if the packet length is less than or equal to 250 bytes. For packets exceeding this length, the v1.0 devices will either truncate the data to the first 250 bytes or discard the packet entirely.
|
||||
|
||||
## Using
|
||||
|
||||
|
@ -11,9 +11,9 @@
|
||||
|
||||
#define ZH_ESPNOW_INIT_CONFIG_DEFAULT() \
|
||||
{ \
|
||||
.task_priority = 15, \
|
||||
.task_priority = 10, \
|
||||
.stack_size = 3072, \
|
||||
.queue_size = 32, \
|
||||
.queue_size = 64, \
|
||||
.wifi_interface = WIFI_IF_STA, \
|
||||
.wifi_channel = 1, \
|
||||
.attempts = 3}
|
||||
@ -25,7 +25,7 @@ extern "C"
|
||||
|
||||
typedef struct // Structure for initial initialization of ESP-NOW interface.
|
||||
{
|
||||
uint8_t task_priority; // Task priority for the ESP-NOW messages processing. @note It is not recommended to set a value less than 10.
|
||||
uint8_t task_priority; // Task priority for the ESP-NOW messages processing. @note It is not recommended to set a value less than 5.
|
||||
uint16_t stack_size; // Stack size for task for the ESP-NOW messages processing. @note The minimum size is 2048 bytes.
|
||||
uint8_t queue_size; // Queue size for task for the ESP-NOW messages processing. @note The size depends on the number of messages to be processed. It is not recommended to set the value less than 16.
|
||||
wifi_interface_t wifi_interface; // WiFi interface (STA or AP) used for ESP-NOW operation. @note The MAC address of the device depends on the selected WiFi interface.
|
||||
|
12
zh_espnow.c
12
zh_espnow.c
@ -146,13 +146,12 @@ esp_err_t IRAM_ATTR zh_espnow_send(const uint8_t *target, const uint8_t *data, c
|
||||
{
|
||||
memcpy(queue.data.mac_addr, target, ESP_NOW_ETH_ALEN);
|
||||
}
|
||||
queue.data.payload = heap_caps_malloc(data_len, MALLOC_CAP_8BIT);
|
||||
queue.data.payload = heap_caps_calloc(1, data_len, MALLOC_CAP_8BIT);
|
||||
if (queue.data.payload == NULL)
|
||||
{
|
||||
ESP_LOGE(TAG, "Adding outgoing ESP-NOW data to queue fail. Memory allocation fail or no free memory in the heap.");
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
memset(queue.data.payload, 0, data_len);
|
||||
memcpy(queue.data.payload, data, data_len);
|
||||
queue.data.payload_len = data_len;
|
||||
if (target == NULL)
|
||||
@ -206,13 +205,12 @@ static void IRAM_ATTR _recv_cb(const esp_now_recv_info_t *esp_now_info, const ui
|
||||
#else
|
||||
memcpy(queue.data.mac_addr, esp_now_info->src_addr, ESP_NOW_ETH_ALEN);
|
||||
#endif
|
||||
queue.data.payload = heap_caps_malloc(data_len, MALLOC_CAP_8BIT);
|
||||
queue.data.payload = heap_caps_calloc(1, data_len, MALLOC_CAP_8BIT);
|
||||
if (queue.data.payload == NULL)
|
||||
{
|
||||
ESP_LOGE(TAG, "Adding incoming ESP-NOW data to queue fail. Memory allocation fail or no free memory in the heap.");
|
||||
return;
|
||||
}
|
||||
memset(queue.data.payload, 0, data_len);
|
||||
memcpy(queue.data.payload, data, data_len);
|
||||
queue.data.payload_len = data_len;
|
||||
#if defined CONFIG_IDF_TARGET_ESP8266 || ESP_IDF_VERSION_MAJOR == 4
|
||||
@ -236,14 +234,13 @@ static void IRAM_ATTR _processing(void *pvParameter)
|
||||
{
|
||||
case TO_SEND:
|
||||
ESP_LOGI(TAG, "Outgoing ESP-NOW data to MAC %02X:%02X:%02X:%02X:%02X:%02X processing begin.", MAC2STR(queue.data.mac_addr));
|
||||
esp_now_peer_info_t *peer = heap_caps_malloc(sizeof(esp_now_peer_info_t), MALLOC_CAP_8BIT);
|
||||
esp_now_peer_info_t *peer = heap_caps_calloc(1, sizeof(esp_now_peer_info_t), MALLOC_CAP_8BIT);
|
||||
if (peer == NULL)
|
||||
{
|
||||
ESP_LOGE(TAG, "Outgoing ESP-NOW data processing fail. Memory allocation fail or no free memory in the heap.");
|
||||
heap_caps_free(queue.data.payload);
|
||||
break;
|
||||
}
|
||||
memset(peer, 0, sizeof(esp_now_peer_info_t));
|
||||
peer->ifidx = _init_config.wifi_interface;
|
||||
memcpy(peer->peer_addr, queue.data.mac_addr, ESP_NOW_ETH_ALEN);
|
||||
err = esp_now_add_peer(peer);
|
||||
@ -261,7 +258,7 @@ static void IRAM_ATTR _processing(void *pvParameter)
|
||||
heap_caps_free(peer);
|
||||
break;
|
||||
}
|
||||
zh_espnow_event_on_send_t *on_send = heap_caps_malloc(sizeof(zh_espnow_event_on_send_t), MALLOC_CAP_8BIT);
|
||||
zh_espnow_event_on_send_t *on_send = heap_caps_calloc(1, sizeof(zh_espnow_event_on_send_t), MALLOC_CAP_8BIT);
|
||||
if (on_send == NULL)
|
||||
{
|
||||
ESP_LOGE(TAG, "Outgoing ESP-NOW data processing fail. Memory allocation fail or no free memory in the heap.");
|
||||
@ -269,7 +266,6 @@ static void IRAM_ATTR _processing(void *pvParameter)
|
||||
heap_caps_free(peer);
|
||||
break;
|
||||
}
|
||||
memset(on_send, 0, sizeof(zh_espnow_event_on_send_t));
|
||||
memcpy(on_send->mac_addr, queue.data.mac_addr, ESP_NOW_ETH_ALEN);
|
||||
SEND:
|
||||
++_attempts;
|
||||
|
Loading…
x
Reference in New Issue
Block a user