Skip to content

Commit

Permalink
Fixed the ability to change CHANNEL (#7154)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
PilnyTomas authored Sep 14, 2022
1 parent 67c293d commit 0882ea0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion libraries/ESP32/examples/ESPNow/Basic/Master/Master.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libraries/ESP32/examples/ESPNow/Basic/Slave/Slave.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down

0 comments on commit 0882ea0

Please sign in to comment.