Page 1 of 1

ESP-NOW speed / out of memory error

Posted: Sun Dec 08, 2019 2:28 pm
by benjavita
Hello,

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;
  }
}

Re: ESP-NOW speed / out of memory error

Posted: Mon Dec 09, 2019 8:14 am
by zhangyanjiao
hi benjavita,
The default ESP-NOW bit data is 1Mbps. We are thinking about adding this to the ESP-NOW doc.
As for the memory error, I have tested with the espnow example in IDF, and I have set the send delay time to 1ms in menuconfig, there is no memory error. Can you confirm that the memory error is related to the send delay time?

Re: ESP-NOW speed / out of memory error

Posted: Wed Mar 25, 2020 12:37 pm
by zhangyanjiao
Please refer to this info:
If there is a lot of ESP-NOW data to send, call esp_now_send() to send less than or equal to 250 bytes of data once a time. Note that too short interval between sending two ESP-NOW data may lead to disorder of sending callback function. So, it is recommended that sending the next ESP-NOW data after the sending callback function of the previous sending has returned. The sending callback function runs from a high-priority Wi-Fi task. So, do not do lengthy operations in the callback function. Instead, post the necessary data to a queue and handle it from a lower priority task.

Re: ESP-NOW speed / out of memory error

Posted: Wed Mar 25, 2020 12:46 pm
by zhangyanjiao
hi ,
you can also refer to the ESP-NOW example in IDF:
https://github.com/espressif/esp-idf/bl ... ain.c#L187