未验证 提交 0882ea09 编写于 作者: T Tomáš Pilný 提交者: GitHub

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
上级 67c293dc
......@@ -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
......
......@@ -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());
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册