Skip to content

Commit 0882ea0

Browse files
authored
Fixed the ability to change CHANNEL (#7154)
* Removed option to change CHANNEL * Revert "Removed option to change CHANNEL" This reverts commit b2ec27d. * Fixed the ability to change CHANNEL * WiFi scan only on selected channel
1 parent 67c293d commit 0882ea0

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Diff for: libraries/ESP32/examples/ESPNow/Basic/Master/Master.ino

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include <esp_now.h>
3333
#include <WiFi.h>
34+
#include <esp_wifi.h> // only for esp_wifi_set_channel()
3435

3536
// Global copy of slave
3637
esp_now_peer_info_t slave;
@@ -55,7 +56,7 @@ void InitESPNow() {
5556

5657
// Scan for slaves in AP mode
5758
void ScanForSlave() {
58-
int8_t scanResults = WiFi.scanNetworks();
59+
int16_t scanResults = WiFi.scanNetworks(false, false, false, 300, CHANNEL); // Scan only on one channel
5960
// reset on each scan
6061
bool slaveFound = 0;
6162
memset(&slave, 0, sizeof(slave));
@@ -222,9 +223,11 @@ void setup() {
222223
Serial.begin(115200);
223224
//Set device in STA mode to begin with
224225
WiFi.mode(WIFI_STA);
226+
esp_wifi_set_channel(CHANNEL, WIFI_SECOND_CHAN_NONE);
225227
Serial.println("ESPNow/Basic/Master Example");
226228
// This is the mac address of the Master in Station Mode
227229
Serial.print("STA MAC: "); Serial.println(WiFi.macAddress());
230+
Serial.print("STA CHANNEL "); Serial.println(WiFi.channel());
228231
// Init ESPNow with a fallback logic
229232
InitESPNow();
230233
// Once ESPNow is successfully Init, we will register for Send CB to

Diff for: libraries/ESP32/examples/ESPNow/Basic/Slave/Slave.ino

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void configDeviceAP() {
5757
Serial.println("AP Config failed.");
5858
} else {
5959
Serial.println("AP Config Success. Broadcasting with AP: " + String(SSID));
60+
Serial.print("AP CHANNEL "); Serial.println(WiFi.channel());
6061
}
6162
}
6263

0 commit comments

Comments
 (0)