How To Enable ESP NOW Long Range Mode in Arduino

IMK123
Posts: 4
Joined: Sat Apr 22, 2023 8:34 am

How To Enable ESP NOW Long Range Mode in Arduino

Postby IMK123 » Sat Apr 22, 2023 9:40 am

Hello,
I am developing a Serial to Serial via WiFi (Radio Modem) using a pair ESP32 WROOM-32 boards.
This project is in test and is running reliable for hours sending 250 byte packets to each other.
This radio modem project is for an autonomous wheeled Robot.
Where one ESP32 is driven by an App in a PC, with the other ESP32 is in the Robot.
Now this is working well although the range seems limited to about 11m through three brick walls before I get lost massages.
So I thought I would try to configure these ESP32 WROOM-32 boards in Long Range Mode.
Well I have researched much and tried many permutations of Arduino setup to enable Long Range Mode but none seem to work.
Can someone take a look at this setup code below to see if correct please.
Many thanks in advance imk

WiFi.mode( WIFI_AP_STA );

// Initilize ESP-NOW
if( esp_now_init() != ESP_OK )
{
Serial.println("Error initializing ESP-NOW");
return;
}
// Set Long Range Mode
esp_wifi_set_protocol( WIFI_IF_STA , WIFI_PROTOCOL_LR);

// Register callback function
esp_now_register_recv_cb( OnDataRecv );
// Register the send callback
esp_now_register_send_cb( OnDataSent );

// Register peer to Send To
memcpy( peerInfo.peer_addr, broadcastAddress, 6 );
peerInfo.channel = 0;
peerInfo.encrypt = false;

// Add peer
if( esp_now_add_peer( &peerInfo ) != ESP_OK )
{
Serial.println("Failed to add peer");
return;
}

SkydiveWags
Posts: 8
Joined: Tue Apr 18, 2023 6:47 pm

Re: How To Enable ESP NOW Long Range Mode in Arduino

Postby SkydiveWags » Mon Jun 26, 2023 2:35 pm

I would also like to know the answer to IMK123's question.

I would like to implement Long Range mode, but everything I see online has completely different code and much of it is in (Python?).
I am using Arduino IDE and would like to know if adding the one line used above to enable it is all I need.
The documentation doesn't make this clear at all.

Thanks.

SkydiveWags
Posts: 8
Joined: Tue Apr 18, 2023 6:47 pm

Re: How To Enable ESP NOW Long Range Mode in Arduino

Postby SkydiveWags » Wed Jun 28, 2023 6:21 pm

I am amazed nobody has replied to this with an answer. I really wonder how many people actually use ESP-NOW.

I would also like to know if long range mode will help with interference issues. I seem to be having some interference that causes me to loose communication between ESP32's.

Does it push more power? If so, how much more? Is it safe to broadcast continuously in LR mode? Or will the processor get too hot?

Fenribel
Posts: 2
Joined: Sat Oct 28, 2023 4:44 pm

Re: How To Enable ESP NOW Long Range Mode in Arduino

Postby Fenribel » Sat Oct 28, 2023 4:47 pm

Hello, colleague! I'm facing the same problem - I'm trying to integrate long-distance mode into my code that uses the esp-now protocol. Do you have any updates on the issue? It's quite difficult to debug it yourself; you'll have to run hundreds of meters with your laptop to try to write the code correctly during range tests...

IMK123
Posts: 4
Joined: Sat Apr 22, 2023 8:34 am

Re: How To Enable ESP NOW Long Range Mode in Arduino

Postby IMK123 » Sun Oct 29, 2023 9:45 pm

Not a squeak of news from anyone.
Only thing I can think is that it is illegal in some territories and therefore no one want to say how to do it.
Or it doesn't actual exist or its default state anyway.
Good luck imk

niklasonfire
Posts: 1
Joined: Thu Nov 09, 2023 2:51 pm

Re: How To Enable ESP NOW Long Range Mode in Arduino

Postby niklasonfire » Thu Nov 09, 2023 2:55 pm

Hey there,

i found that for LR Mode to work in Arduino you also need to

Code: Select all

#include <WiFi.h>
#include <esp_wifi.h
then in Setup you need to set Wifi mode as well as the mode of the Phy like so:

Code: Select all

  WiFi.mode(WIFI_MODE_STA);
  esp_wifi_set_protocol( WIFI_IF_STA , WIFI_PROTOCOL_LR);
Hope this helps somehow. I would also like to know a little more about LR mode as it is quite interesting.

Cheers

juniore
Posts: 3
Joined: Tue May 24, 2022 4:57 pm

Re: How To Enable ESP NOW Long Range Mode in Arduino

Postby juniore » Fri Feb 28, 2025 10:31 am

Hello! I just made an ESP-NOW range test using an ESP32-S3 module with PCB antenna.
For this first test I haven't enabled the LR (the code was written in Arduino and as I found on forums the LR can only be enabled on ESP-IDF. The results are impressive, 650 meters straight line without obstacles.
The second test, enabling LR Long Range using ESP-IDF. The strange think is that the result have not changed, and in theory I should see a 4dB improvement.
My first lecture is that the LR comes already enabled by default (at least on newer module models), but I haven't found any documentation saying this and haven't made tests with older ESP32 modules.
Any idea about this anyone?

ahsrabrifat
Posts: 201
Joined: Sat Jan 18, 2025 2:31 pm

Re: How To Enable ESP NOW Long Range Mode in Arduino

Postby ahsrabrifat » Tue Mar 04, 2025 1:38 pm

Add esp_wifi_set_protocol(WIFI_IF_AP, WIFI_PROTOCOL_LR); to apply Long Range mode in both AP and STA. WIFI_PROTOCOL_LR should be applied after WiFi.mode(WIFI_AP_STA). Register both OnDataRecv and OnDataSent callbacks explicitly.

Code: Select all

#include <WiFi.h>
#include <esp_now.h>
#include <esp_wifi.h>

// Receiver callback function
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
  Serial.print("Received: ");
  Serial.println(len);
}

// Sender callback function
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
  Serial.print("Send Status: ");
  Serial.println(status == ESP_NOW_SEND_SUCCESS ? "Success" : "Fail");
}

uint8_t broadcastAddress[] = {0x24, 0x6F, 0x28, 0xA1, 0xB2, 0xC3};  // Change to your peer's MAC
esp_now_peer_info_t peerInfo;

void setup() {
  Serial.begin(115200);
  
  // Set WiFi to AP+STA mode
  WiFi.mode(WIFI_AP_STA);
  
  // Ensure WiFi is set to 802.11b (needed for LR mode)
  esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_LR);
  esp_wifi_set_protocol(WIFI_IF_AP, WIFI_PROTOCOL_LR);
  
  // Initialize ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }

  // Register ESP-NOW callback functions
  esp_now_register_recv_cb(OnDataRecv);
  esp_now_register_send_cb(OnDataSent);

  // Register peer
  memcpy(peerInfo.peer_addr, broadcastAddress, 6);
  peerInfo.channel = 0;    // Must be the same on both devices
  peerInfo.encrypt = false;

  if (esp_now_add_peer(&peerInfo) != ESP_OK) {
    Serial.println("Failed to add peer");
    return;
  }

  Serial.println("ESP-NOW with Long Range Mode Initialized");
}

void loop() {
  // Example send function (replace with real data)
  uint8_t data[] = "Hello from ESP32";
  esp_err_t result = esp_now_send(peerInfo.peer_addr, data, sizeof(data));

  if (result == ESP_OK) {
    Serial.println("Sent successfully");
  } else {
    Serial.println("Send failed");
  }

  delay(1000);  // Adjust as needed
}
Hope this helps. If you need to print PCBs for this project, you can get some information regarding the cost here:
https://www.allpcb.com/blog/pcb-orderin ... -unit.html

Who is online

Users browsing this forum: Applebot, ChatGPT-User and 2 guests