Fixed the ability to change CHANNEL (#7154)

* Removed option to change CHANNEL

* Revert "Removed option to change CHANNEL"

This reverts commit b2ec27de1d2d4703a15f6397550a46896413828a.

* Fixed the ability to change CHANNEL

* WiFi scan only on selected channel
This commit is contained in:
Tomáš Pilný 2022-09-14 10:28:42 +02:00 committed by GitHub
parent 67c293dc72
commit 0882ea0919
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View file

@ -31,6 +31,7 @@
#include <esp_now.h>
#include <WiFi.h>
#include <esp_wifi.h> // only for esp_wifi_set_channel()
// Global copy of slave
esp_now_peer_info_t slave;
@ -55,7 +56,7 @@ void InitESPNow() {
// Scan for slaves in AP mode
void ScanForSlave() {
int8_t scanResults = WiFi.scanNetworks();
int16_t scanResults = WiFi.scanNetworks(false, false, false, 300, CHANNEL); // Scan only on one channel
// reset on each scan
bool slaveFound = 0;
memset(&slave, 0, sizeof(slave));
@ -222,9 +223,11 @@ void setup() {
Serial.begin(115200);
//Set device in STA mode to begin with
WiFi.mode(WIFI_STA);
esp_wifi_set_channel(CHANNEL, WIFI_SECOND_CHAN_NONE);
Serial.println("ESPNow/Basic/Master Example");
// This is the mac address of the Master in Station Mode
Serial.print("STA MAC: "); Serial.println(WiFi.macAddress());
Serial.print("STA CHANNEL "); Serial.println(WiFi.channel());
// Init ESPNow with a fallback logic
InitESPNow();
// Once ESPNow is successfully Init, we will register for Send CB to

View file

@ -57,6 +57,7 @@ void configDeviceAP() {
Serial.println("AP Config failed.");
} else {
Serial.println("AP Config Success. Broadcasting with AP: " + String(SSID));
Serial.print("AP CHANNEL "); Serial.println(WiFi.channel());
}
}