Skip to content
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

Multiple Router with same SSID #1

Open
lilalukas opened this issue Sep 15, 2020 · 4 comments
Open

Multiple Router with same SSID #1

lilalukas opened this issue Sep 15, 2020 · 4 comments

Comments

@lilalukas
Copy link

lilalukas commented Sep 15, 2020

Hey all,

I can confirm that you have to use the same WiFi-Channel for ESPNow-Sender and ESPNow-to-WiFi-Gateways. If you have multiple routers with the same SSID (e.g. in university or company) and you always want to use the best WiFi (so no hardcoded channel) you have to try to send the message on each channel until you get a success reply.

  • Gateway on random channel

`

channel = 1

send = false;

while(!send){

    send = sendOnChannel(channel);

    if(send){

         break;

    }else{

        channel = channel % 13 + 1;

     }

}

`

@Leonos
Copy link

Leonos commented Dec 6, 2020

Have you tested this? I think it's is a very nice and necessary solution indeed, if it works. I am wondering if the channel can be changed on the fly.

We have to keep in mind that ESP-Now is invented to cover longer distances so the chance that the sender (master) is not within reach of the router is not imaginary. In those cases a routine that scans available networks does not work. I am also worried that the sender trying to connect to a Wi-Fi station will be a no-no for battery operated solutions, but I am not sure about the power requirements of ESP-Now, to be honest. Would WiFi.mode(WIFI_MODE_STA); still be necessary?

@Leonos
Copy link

Leonos commented Dec 6, 2020

It works!

bool channelFound = false;
uint8_t channel = 1;

void onDataSent(const uint8_t* mac_addr, esp_now_send_status_t status) {
  if (!channelFound && status != ESP_NOW_SEND_SUCCESS) { 
    tryNextChannel();
  }
  else {
    channelFound = true;
  }
}

void tryNextChannel() {
  channel = channel % 13 + 1;
  esp_wifi_set_promiscuous(true);
  esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
  esp_wifi_set_promiscuous(false);
  Serial.println(channel);
}

It needs more refinement as there can be other reasons that a send fails and then you don't want the channel to be changed again, but it's a start.

EDIT: To answer my own question, yes, WiFi.mode(WIFI_MODE_STA) is still necessary. And I should have mentioned that setup() and initWiFi() remain the same, but without the
// int32_t channel = getWiFiChannel(WIFI_SSID);

@homonto
Copy link

homonto commented Jun 24, 2022

I am not sure about the power requirements of ESP-Now

you can check in my repository the deep dive into the power requirements of ESPnow together with the time to wake up, gather data, send to receiver and go to sleep

@m1cr0lab
Copy link
Member

m1cr0lab commented Aug 9, 2022

@Leonos

First of all, a thousand apologies for not having replied to you all this time. I have too many projects on the go. 😁

You are right to point this out. I used this technique on all my sensors spread around the house for almost two years, and it works great. The router can change the channel anytime, and everyone is tuned in automatically.

I should have updated the code on GitHub a while ago, but I completely forgot to. I'll update it as soon as I have time.

You should know that with WIFI_MODE_STA, the ESP32 periodically enters a power-saving mode and puts its radio communication circuit on standby. In other words, if your sender modules try to transmit their data with ESP-NOW while the receiver’s modem is on standby, then transmissions will inevitably fail. To avoid this, you can force the receiver to keep its radio circuit permanently powered:

WiFi.setSleep(WIFI_PS_NONE);

@homonto

I just looked at your GitHub repo. A great project and very well documented. Congratulations, and thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants