esp-now channel setting when in wifi station mode.

Ivo.Tisch
Posts: 14
Joined: Tue Nov 05, 2019 7:59 pm

esp-now channel setting when in wifi station mode.

Postby Ivo.Tisch » Wed Mar 04, 2020 1:21 am

I have an esp-now network operating with the wifi set to station mode. The wifi is only used for esp-now and doesn't connect to any access point. I am currently using the release/v4.1 branch of the repository (commit 328c659c) which includes fixes for channel checking in the peer() process. I note that the wifi station defaults to channel 1 and peer(), is satisfied when the channel member of esp_now_peer_info_t, is set to either 0,1. My question is, what do I do to change the channel? I presume if I allowed the station to connect to an AP, that would force it to use the same channel as the AP. However, I don't want to operate this network with a connection to an AP. I have tried the following, but it has no affect on channel:

wifi_config_t wifi_config = {
.sta = {
.channel = ESPNOW_CHANNEL,
},
};

ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) );
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );

I do not want to use the wifi in soft AP mode, where I should be able to set the channel, as that will reduce the number of possible encrypted nodes in the network.

Any help or insight would be very much appreciated

Thanks
Ivo

iParcelBox
Posts: 22
Joined: Sun Oct 27, 2019 3:12 pm

Re: esp-now channel setting when in wifi station mode.

Postby iParcelBox » Thu Mar 05, 2020 1:30 pm

I'm afraid I don't have a solution to this, but am very interested as I'm having issues whenever my 'master' ESP32 (in STA mode) connects to an AP with channel other than 1. when adding a peer I set .channel=0 but sending messages fails.

I'd also be very interested in your experience with encryption. As soon as I set .encrypt=true even with LMK and PMK the same on both devices, send_cb reports OK but the message is never received.

Ivo.Tisch
Posts: 14
Joined: Tue Nov 05, 2019 7:59 pm

Re: esp-now channel setting when in wifi station mode.

Postby Ivo.Tisch » Thu Mar 05, 2020 8:33 pm

As a matter of interest, what branch/commit of the repository are you using?

I don't have experience with my esp-now network also connecting to an AP. Do you get a send error if you feed peer() with .channel set to anything other than 0 or the AP channel?

If I have understood you correctly, it could be that when one of your esp-now nodes connects to the AP, that node channel is now set to the AP channel, but the other esp-now node is still on channel 1, and will not be able to receive messages from a node on a different channel. You can test this theory with:

esp_wifi_get_channel(&primary_channel, &secondary_channel); //you are interested in the primary channel.

I have re-written my esp-now code; there is no longer any master and every message received is acknowledged allowing for re-transmission in the event of an acknowledgement timeout. So it is hard to be useful in sharing my experience with encryption. I have had no trouble; but at this stage I have not played with LMK or PMK values - they are still the Espressif defaults.
From the documentation, it appears that the send_cb returning a status of OK, means only that a message was received at the MAC layer (the documentation is not very comprehensive, so I'm not even sure what that really means). There is no guarantee that it is received by the application and Espressif do suggest, if guaranteed communication is required, that the application uses an ack/re-transmission sequence.

I'm sorry I can't be of more help really.

Cheers
Ivo

iParcelBox
Posts: 22
Joined: Sun Oct 27, 2019 3:12 pm

Re: esp-now channel setting when in wifi station mode.

Postby iParcelBox » Fri Mar 06, 2020 4:49 pm

Thanks Ivo.

What I've found is that my AP tends to switch between Channels 1 and 11. When my ESP32 connects on channel 1, ESP-NOW works fine and I can send to the 'slave' device and correctly receive ESP_OK messages from the callback. However, when on channel 11 I get failure messages (even though sometimes the message is received).

Catching the wifi_channel on GOT_IP event and updating peer.channel to match this seems to make no difference. Perhaps this is because on the 'slave' device, peer.channel is set to 0 so can't cope with receiving data on channel 11?

Although I understand how to set the peer channel of the 'master' device, I'm not sure how the 'slave' is supposed to know what channel to use?

If I manually set peer.channel to be e.g. 6, I get an error when trying to send: `ESPNOW: Peer channel is not equal to the home channel, send fail!`

Ivo.Tisch
Posts: 14
Joined: Tue Nov 05, 2019 7:59 pm

Re: esp-now channel setting when in wifi station mode.

Postby Ivo.Tisch » Fri Mar 06, 2020 9:18 pm

As I understand things, setting . channel in peer() has no effect on setting the radio channel - implied in the documentation. It must however be set to 0 or the same as the radio channel or you get a send error. Hence my original question, how do you set the radio channel when it is set up as a station? You have the same problem. Your master node sets its channel to the connected AP, but there is no way to set the channel in the slave node radio! This is a big limitation..if you use esp-now as a standalone network, unconnected to any AP, it can only operate on channel 1. If you use it in AP mode, you should be able to set the channel, but then all nodes would have to be in AP mode with the same channel setting - which is nuts!
Im going to try some experimentation with scan, to see if that can permanently change the channel.
How do we get Espressif to enter the discussion? Is there another avenue of communication?

iParcelBox
Posts: 22
Joined: Sun Oct 27, 2019 3:12 pm

Re: esp-now channel setting when in wifi station mode.

Postby iParcelBox » Fri Mar 06, 2020 9:24 pm

Ah, OK. Somehow I assumed that setting peer.channel would force the peer device to use the same channel! In that case I might just as well set it to 0.

What I've found slightly wierd is that, when my 'master' device connects to the AP and is given a channel other than 1, when I try and send ESP-Now commands to the 'slave', the callback always returns 'failed', but about 30% of the time the message does get received, and quite often the response messages also get back to the master.

ESP-NOW looks as though it could be really useful function, but we could really do with some support and guidance from Espressif on this forum to work through the un-documented requirements to get it working in the real world.

iParcelBox
Posts: 22
Joined: Sun Oct 27, 2019 3:12 pm

Re: esp-now channel setting when in wifi station mode.

Postby iParcelBox » Sat Mar 07, 2020 11:25 am

I was thinking about this overnight. On boot and before connecting to wifi, could the 'master' scan wifi networks, retrieve the scanned channel for the AP ssid, then broadcast this as a message to every subscribed peer over channel 1 (default). On receipt, the slave device could then (somehow?) set their channel to be the same (perhaps by setting up a wifi connection to a 'dummy' network using that channel but not actually connecting. The Master could then connect to the AP using that channel and in theory everything would be in sync?

iParcelBox
Posts: 22
Joined: Sun Oct 27, 2019 3:12 pm

Re: esp-now channel setting when in wifi station mode.

Postby iParcelBox » Sat Mar 07, 2020 11:33 am


Ivo.Tisch
Posts: 14
Joined: Tue Nov 05, 2019 7:59 pm

Re: esp-now channel setting when in wifi station mode.

Postby Ivo.Tisch » Sat Mar 07, 2020 7:29 pm

The issue report is hopeful:

"We are trying to modify this function to let it can set the channel as long as the wifi initialized, thus you can set the channel in STA mode. But we will still don't support setting channel when the STA has connected to an AP, or when STA is scanning, or STA is connecting to an AP."

Your idea should work. I don't like the idea of the dummy network to set the slave channels. esp-now has the potential to work quite long range, especially if nodes can act like repeaters or range extenders. So all nodes may not be able to connect to your dummy network. I think the best solution would be the one Espressif are working on. Hopefully it will come soon.

zhangyanjiao
Posts: 34
Joined: Mon Aug 28, 2017 3:27 am

Re: esp-now channel setting when in wifi station mode.

Postby zhangyanjiao » Tue Mar 24, 2020 9:36 am

sorry to reply so late.

Currently, the `esp_wifi_set_channel()` can be called in staion mode, please refer to the branch https://github.com/espressif/esp-idf/co ... 2440ed82ef

Who is online

Users browsing this forum: No registered users and 113 guests