I've not been able to find out the speed at which data can be transmitted with ESP-NOW between 2 ESP32 (close to each other), and my tests concluded for a "low" speed under 1Mbps when I would expect much more.
See simplified code below for the transmitter, I'm reading a file on and sending it over using esp_now_send (250 bytes per packet), but if I don't delay enough between each send (around 3ms) I keep getting out of memory errors (ESP_ERR_ESPNOW_NO_MEM).
Is it a limitation in the protocol, or is there something wrong I'm doing?
Maybe there is a better way to transmit the data (this is for live streaming)?
Many thanks Ben
Code: Select all
#include <WiFi.h>
#include <esp_now.h>
#include <stdint.h>
#include <string.h>
#include <SD.h>
static uint8_t broadcast_mac[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
File file;
typedef struct __attribute__((packed)) esp_now_msg_t
{
char data[250];
} esp_now_msg_t;
void setup() {
Serial.begin(115200);
network_setup();
SD.begin();
file = SD.open("/example.txt");
}
void loop() {
static uint32_t counter = 0;
esp_now_msg_t msg;
while (file.readBytes(msg.data, 250)) {
send_msg(&msg);
delayMicroseconds(3000);
}
file.seek(0);
}
static void send_msg(esp_now_msg_t * msg)
{
uint16_t packet_size = sizeof(esp_now_msg_t);
uint8_t msg_data[packet_size];
memcpy(&msg_data[0], msg, sizeof(esp_now_msg_t));
esp_err_t status = esp_now_send(broadcast_mac, msg_data, packet_size);
if (ESP_OK != status)
{
Serial.println("Error sending message");
handle_error(status);
}
}
static void network_setup(void)
{
//Puts ESP in STATION MODE
WiFi.mode(WIFI_STA);
WiFi.disconnect();
if (esp_now_init() != 0)
{
return;
}
esp_now_peer_info_t peer_info;
peer_info.channel = WIFI_CHANNEL;
memcpy(peer_info.peer_addr, broadcast_mac, 6);
peer_info.ifidx = ESP_IF_WIFI_STA;
peer_info.encrypt = false;
esp_err_t status = esp_now_add_peer(&peer_info);
if (ESP_OK != status)
{
Serial.println("Could not add peer");
handle_error(status);
}
}
static void handle_error(esp_err_t err)
{
switch (err)
{
case ESP_ERR_ESPNOW_NOT_INIT:
Serial.println("Not init");
break;
case ESP_ERR_ESPNOW_ARG:
Serial.println("Argument invalid");
break;
case ESP_ERR_ESPNOW_INTERNAL:
Serial.println("Internal error");
break;
case ESP_ERR_ESPNOW_NO_MEM:
Serial.println("Out of memory");
break;
case ESP_ERR_ESPNOW_NOT_FOUND:
Serial.println("Peer is not found");
break;
case ESP_ERR_ESPNOW_IF:
Serial.println("Current WiFi interface doesn't match that of peer");
break;
default:
break;
}
}