Skip to content

Changing channel breaks ESP-Now Master/Slave example #2653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
skrenes opened this issue Apr 10, 2019 · 24 comments
Closed

Changing channel breaks ESP-Now Master/Slave example #2653

skrenes opened this issue Apr 10, 2019 · 24 comments
Assignees
Labels
Area: BT&Wifi BT & Wifi related issues Area: ESP-IDF related ESP-IDF related issues Area: Libraries Issue is related to Library support.
Milestone

Comments

@skrenes
Copy link
Contributor

skrenes commented Apr 10, 2019

Hardware:

Board: ESP32 D32 v1.0.0
Core Installation version: 1.0.1
IDE name: Arduino IDE
Flash Frequency: 80Mhz
PSRAM enabled: ?
Upload Speed: 921600
Computer OS: Mac OSX 10.14.4

Description:

In the basic example of ESP-Now (and I believe Multi-Slave example too), if the user changes the CHANNEL definitions from 1 to anything else, the example fails.

The definitions are here:

An example of the output from the master is this:

Found 42 devices 
Found a Slave.
1: Slave:30:AE:A4:8B:38:10 [30:AE:A4:8B:38:11] (-32)
Slave Found, processing..
Slave Status: Already Paired
Sending: 2
Send Status: Success
Last Packet Sent to: 30:ae:a4:8b:38:11
Last Packet Send Status: Delivery Fail

Notice the Delivery Fail status. The slave doesn't detect the master at all. Using a channel scan tool on my laptop, I see that the slave is in fact broadcasting its softAP on the properly defined channel. I don't know enough about the underlying SDK to determine what's going on within a reasonable amount of time. I'm hoping someone else can figure out what's going on, especially given how easy it is to replicate.

@skrenes skrenes closed this as completed Apr 10, 2019
@skrenes skrenes reopened this Apr 10, 2019
@stale
Copy link

stale bot commented Aug 1, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Stale Issue is stale stage (outdated/stuck) label Aug 1, 2019
@stale
Copy link

stale bot commented Aug 15, 2019

This stale issue has been automatically closed. Thank you for your contributions.

@stale stale bot closed this as completed Aug 15, 2019
@devSarry
Copy link

Can someone comment on why this occurs?

@skrenes
Copy link
Contributor Author

skrenes commented Dec 2, 2019

Support seems none-existent.

@sheminasalam
Copy link

was this solved?

@VojtechBartoska
Copy link
Contributor

This needs to be checked, reopening.

@VojtechBartoska VojtechBartoska added Status: Needs investigation We need to do some research before taking next steps on this issue and removed Status: Stale Issue is stale stage (outdated/stuck) labels Jun 27, 2022
@VojtechBartoska
Copy link
Contributor

Can you please take a look @me-no-dev?

@me-no-dev
Copy link
Member

@VojtechBartoska I'm not sure what the problem was. it seems like OP tried to set one channel for master and another for slave and expected the code to work. Should be closed IMHO

@VojtechBartoska VojtechBartoska added Area: Libraries Issue is related to Library support. Resolution: Awaiting response Waiting for response of author and removed Status: Needs investigation We need to do some research before taking next steps on this issue labels Jun 28, 2022
@VojtechBartoska
Copy link
Contributor

is anyone able to retest this on v2.0.3? Thanks in advance!

@sheminasalam
Copy link

I had a similar situation with ESP8266. On investigation I found that even when we set channel as anything other than 1 while adding peers, the device doesn't execute that. The solution that I found with esp8266 is that we need to first set the channel with wifi.begin and then disconnect wifi with wifi.disconnect and proceed with adding peer. In Code it would look like below.

    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password, WIFI_CHANNEL,NULL,false);
    WiFi.disconnect(); //we do not want to connect to a WiFi network



    if (esp_now_init() != 0) {
      if (DEBUG_MODE == 1) {
        Serial.println("ESP-NOW initialization failed");
      }
      return;
    }

@reppad
Copy link

reppad commented Jul 20, 2022

Hi,

is anyone able to retest this on v2.0.3? Thanks in advance!

@VojtechBartoska Same on my side on v2.0.4 (not tested before)

I'm not sure what the problem was. it seems like OP tried to set one channel for master and another for slave and expected the code to work. Should be closed IMHO

Indeed if we leave the default channel values in sketches (master=3 and slave=1) we can't expect the code to work !
In this case we got an explicit message in master output :

Found 7 devices
Found a Slave.
1: Slave_1 [XX:XX:XX:XX:XX:XX] (-28)
Slave Found, processing..
Slave Status: Already Paired
Sending: 27
E (205350) ESPNOW: Peer channel is not equal to the home channel, send fail!
Send Status: Invalid Argument

But if I set the same channel for slave and master, it not work better and I got this output

Found 7 devices
Found a Slave.
1: Slave_1 [XX:XX:XX:XX:XX:XX] (-28)
Slave Found, processing..
Slave Status: Already Paired
Sending: 4
Send Status: Success
Last Packet Sent to: xx:xx:xx:xx:xx:xx
Last Packet Send Status: Delivery Fail

On the slave side I don't have any output after init :

ESPNow/Basic/Slave Example
AP Config Success. Broadcasting with AP: Slave_1
AP MAC: XX:XX:XX:XX:XX:XX
ESPNow Init Success

I tried a simpler way to get working ESPNow: 2 ESPs in STA mode and hardcoding the peer address on sender side but without success.

My setup:
Win10 / Arduino 1.8.19 / arduino-esp32 2.0.4
Master: Lolin C3 mini (ESP32-C3FH4) / Slave: Lilygo ESP32_S2_WOOR (ESP32-S2-WROOM)

@VojtechBartoska
Copy link
Contributor

Adding this to our Roadmap as it needs further testing.

@PilnyTomas
Copy link
Contributor

PilnyTomas commented Aug 9, 2022

Hi, I have opened PR to fix the small problem with the channel, but I could not replicate your issue with Delivery Fail
Tested on ESP32 DevKit.
Can you please provide more info to reproduce this issue on my side?

@PilnyTomas PilnyTomas removed the Status: Test needed Issue needs testing label Aug 9, 2022
@PilnyTomas PilnyTomas added Resolution: More info needed More info must be provided in this issue Resolution: Unable to reproduce With given information issue is unable to reproduce Resolution: Awaiting response Waiting for response of author labels Aug 9, 2022
@reppad
Copy link

reppad commented Aug 9, 2022

Of course,

Here is the basic informations :

My setup:
Win10
Arduino 1.8.19
arduino-esp32 2.0.4
Master: Lolin C3 mini (ESP32-C3FH4)
Slave: Lilygo ESP32_S2_WOOR (ESP32-S2-WROOM)

If it works on your side with 2 ESP32, maybe the problem is related to ESP32-S2 or C3, or an incompatibility between the two?
What information can I provide to help you?

@PilnyTomas
Copy link
Contributor

Thanks for the info.
I have tried using the same chips as you (different boards) - Master C3; Slave S2 - and it is working for me ok.
Can you please try compiling it with a verbose debug level?
Maybe changing both channels to different number might do something.

@reppad
Copy link

reppad commented Aug 14, 2022

Hi,

Some news after several tests.

ESPNow does not work with the Lolin C3 Mini board specifically, I was able to get it to work successfully on another ESP32-C3 based board with native USB.
It may be related to the fact that the Lolin C3 Mini uses an ESP32-C3FH4 chip with built-in flash memory ? The working board uses an external SPI flash chip.

Here are the "verbose" logs of the Lolin C3 Mini running "Master" sketch

[   249][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino EventESPNow/Basic/Master Example
STA MAC: 60:55:F9:29:FE:FC
ESPNow Init Success
[  3112][V][WiFiGeneric.cpp:381] _arduino_event_cb(): SCAN Done: ID: 128, Status: 0, Results: 6
[  3113][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 1 - SCAN_DONE

Found 6 devices 
Found a Slave.
1: Slave_1 [7C:DF:A1:02:DD:8B] (-31)
Slave Found, processing..
Slave Status: Pair success
Sending: 1
Send Status: Success
Last Packet Sent to: 7c:df:a1:02:dd:8b
Last Packet Send Status: Delivery Fail
[ 11041][V][WiFiGeneric.cpp:381] _arduino_event_cb(): SCAN Done: ID: 129, Status: 0, Results: 4
[ 11042][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 1 - SCAN_DONE

Found 4 devices 
Found a Slave.
1: Slave_1 [7C:DF:A1:02:DD:8B] (-33)
Slave Found, processing..
Slave Status: Already Paired
Sending: 2
Send Status: Success
Last Packet Sent to: 7c:df:a1:02:dd:8b
Last Packet Send Status: Delivery Fail

On the slave side, nothing happens.

On the other hand I detected another problem, even with the board for which ESPNow works (by re-reading I think this is the problem initially reported by @skrenes):

If I use a channel other than 1 (same value on the master and slave side of course), the communication does not work and we get the behavior below

[   247][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino EventESPNow/Basic/Master Example
STA MAC: 60:55:F9:79:A4:5C
ESPNow Init Success

Found 10 devices 
Found a Slave.
1: Slave_1 [7C:DF:A1:02:DD:8B] (-47)
Slave Found, processing..
Slave Status: Pair success
Sending: 1
Send Status: Invalid Argument

Fou[ 20394][V][WiFiGeneric.cpp:381] _arduino_event_cb(): SCAN Done: ID: 130, Status: 0, Results: 12
[ 20394][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 1 - SCAN_DONE

Found 12 devices 
Found a Slave.
1: Slave_1 [7C:DF:A1:02:DD:8B] (-33)
Slave Found, processing..
Slave Status: Already Paired
Sending: 2
E (20481) ESPNOW: Peer channel is not equal to the home channel, send fail!
Send Status: Invalid Argument

@reppad
Copy link

reppad commented Aug 17, 2022

There is definitely a hardware design issue with the board I used for my 1st test :
https://www.wemos.cc/en/latest/tutorials/c3/get_started_with_arduino_c3.html#wifi
arendst/Tasmota#15443

So the issue is only about using channel other than 1 :

If I use a channel other than 1 (same value on the master and slave side of course), the communication does not work and we get the behavior below

[   247][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino EventESPNow/Basic/Master Example
STA MAC: 60:55:F9:79:A4:5C
ESPNow Init Success

Found 10 devices 
Found a Slave.
1: Slave_1 [7C:DF:A1:02:DD:8B] (-47)
Slave Found, processing..
Slave Status: Pair success
Sending: 1
Send Status: Invalid Argument

Fou[ 20394][V][WiFiGeneric.cpp:381] _arduino_event_cb(): SCAN Done: ID: 130, Status: 0, Results: 12
[ 20394][D][WiFiGeneric.cpp:929] _eventCallback(): Arduino Event: 1 - SCAN_DONE

Found 12 devices 
Found a Slave.
1: Slave_1 [7C:DF:A1:02:DD:8B] (-33)
Slave Found, processing..
Slave Status: Already Paired
Sending: 2
E (20481) ESPNOW: Peer channel is not equal to the home channel, send fail!
Send Status: Invalid Argument

@PilnyTomas
Copy link
Contributor

Hi, it seems that the WiFi library does not allow changing channel for Station, so it is impossible to use any other channel than 1.
BTW could please explain why you need other channels? It might be possible to add this ability later, but I'm not promising anything...
In ESP-IDF example it is possible to change the channel in menuconfig, however, this results in the same error as for you: ESPNOW: Peer channel is not equal to the home channel, send fail!
I will create an issue for IDF example nad hopefully we will hear more from the IDF team.

@PilnyTomas PilnyTomas added Area: ESP-IDF related ESP-IDF related issues Area: BT&Wifi BT & Wifi related issues and removed Resolution: More info needed More info must be provided in this issue Resolution: Unable to reproduce With given information issue is unable to reproduce Resolution: Awaiting response Waiting for response of author labels Aug 19, 2022
@reppad
Copy link

reppad commented Aug 19, 2022

Hi, it seems that the WiFi library does not allow changing channel for Station, so it is impossible to use any other channel than 1.

OK, that explains the behavior.

BTW could please explain why you need other channels?

In my case, I tried to change to use a channel as less congested as possible.
But honestly it's not critical and if there hadn't been a need to modify the default channel to make the sketch work, I probably wouldn't have tried to configure it!

It might be possible to add this ability later, but I'm not promising anything...

That would be great, in the meantime it might be helpful to put a comment on the CHANNEL constant?

Thanks a lot for the help!

@PilnyTomas
Copy link
Contributor

put a comment on the CHANNEL constant

I will just remove the option to change CHANNEL until the real issue is solved (if ever).

@juantinazzo
Copy link

juantinazzo commented Jan 12, 2023

I had a similar situation with ESP8266. On investigation I found that even when we set channel as anything other than 1 while adding peers, the device doesn't execute that. The solution that I found with esp8266 is that we need to first set the channel with wifi.begin and then disconnect wifi with wifi.disconnect and proceed with adding peer. In Code it would look like below.

    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password, WIFI_CHANNEL,NULL,false);
    WiFi.disconnect(); //we do not want to connect to a WiFi network



    if (esp_now_init() != 0) {
      if (DEBUG_MODE == 1) {
        Serial.println("ESP-NOW initialization failed");     
      }
      return;
    }
    else // Add peer with correct channel

This worked for me.
I needed to change the channel because one of the boards I am using is connected to a WiFi router that changes channels when it sees fit, and thus all the esp_now devices have to jump channels to the one the router is using.

@laverdanny
Copy link

Hi there !
Is this issue still running ?

As [juantinazzo] said the problem is when you need to connect one device (at least) to router, in order to communicate out of local network.

Even if [juantinazzo] workaround works, all ESP-Now devices have to get connected on the same router to synchronise their operating channel, but they often can't be in router's range ....

@VojtechBartoska VojtechBartoska modified the milestones: 3.0.0, 3.1.0 Feb 20, 2024
@VojtechBartoska
Copy link
Contributor

@P-R-O-C-H-Y As you worked on ESP-Now recently, can you please take a look on this issue?

@P-R-O-C-H-Y
Copy link
Member

This issue can be closed as solved by the ESP-NOW library PR #9395.
Channel of the ESP-NOW peer can be specified, but must be same with the Wifi Interface channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: BT&Wifi BT & Wifi related issues Area: ESP-IDF related ESP-IDF related issues Area: Libraries Issue is related to Library support.
Projects
Development

No branches or pull requests

10 participants