From 3f8f3eb1ad70c57ef8d06de1e53d8c226a89d508 Mon Sep 17 00:00:00 2001 From: tablatronix Date: Thu, 12 Sep 2019 09:56:37 -0500 Subject: [PATCH] fixes #936, adds setWiFiAPChannel --- WiFiManager.cpp | 27 ++++++++++++++++++++------- WiFiManager.h | 4 ++++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 41c5fc4..c1f944f 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -360,30 +360,35 @@ bool WiFiManager::startAP(){ } //@todo add callback here if needed to modify ap but cannot use setAPStaticIPConfig + //@todo rework wifi channelsync as it will work unpredictably when not connected in sta + + int32_t channel = 0; + if(_channelSync) channel = WiFi.channel(); + else channel = _apChannel; - if(_channelSync){ - DEBUG_WM(DEBUG_VERBOSE,"Starting AP on channel:",WiFi.channel()); + if(channel>0){ + DEBUG_WM(DEBUG_VERBOSE,"Starting AP on channel:",channel); } // start soft AP with password or anonymous if (_apPassword != "") { - if(_channelSync){ - ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str(),WiFi.channel()); + if(channel>0){ + ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str(),channel); } else{ ret = WiFi.softAP(_apName.c_str(), _apPassword.c_str());//password option } } else { DEBUG_WM(DEBUG_VERBOSE,F("AP has anonymous access!")); - if(_channelSync){ - ret = WiFi.softAP(_apName.c_str(),"",WiFi.channel()); + if(channel>0){ + ret = WiFi.softAP(_apName.c_str(),"",channel); } else{ ret = WiFi.softAP(_apName.c_str()); } } - if(_debugLevel > DEBUG_DEV) debugSoftAPConfig(); + if(_debugLevel >= DEBUG_DEV) debugSoftAPConfig(); if(!ret) DEBUG_WM(DEBUG_ERROR,"[ERROR] There was a problem starting the AP"); // @todo add softAP retry here @@ -2257,6 +2262,14 @@ bool WiFiManager::setHostname(const char * hostname){ return true; } +/** + * set the soft ao channel, ignored if channelsync is true and connected + * @param int32_t wifi channel, 0 to disable + */ +void WiFiManager::setWiFiAPChannel(int32_t channel){ + _apChannel = channel; +} + /** * toggle showing erase wifi config button on info page * @param boolean enabled diff --git a/WiFiManager.h b/WiFiManager.h index 72e4c3a..18e76ba 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -255,6 +255,9 @@ class WiFiManager bool setHostname(const char * hostname); // show erase wifi onfig button on info page, true void setShowInfoErase(boolean enabled); + // set ap channel + void setWiFiAPChannel(int32_t channel); + // set custom menu // set custom menu items and order @@ -334,6 +337,7 @@ class WiFiManager bool _disableSTA = false; // disable sta when starting ap, always bool _disableSTAConn = true; // disable sta when starting ap, if sta is not connected ( stability ) bool _channelSync = false; // use wifi channel when starting ap + int32_t _apChannel = 0; // channel to use for ap #ifdef ESP32 static uint8_t _lastconxresulttmp; // tmp var for esp32 callback