[WIFI] Added macros for ESP - WifiGMode and WifiPower to reduce/eliminate Wifi interference on sensors like HC-SR501 (#1531)
* Fix WiFi interference on PIR * Added to DOCS re: WiFi interference. * Add sufficx -custom to configs without prod binaries * Add ESP32 Wifi band and tx power to user_config.h --------- Co-authored-by: andre <agreylin@gmail.com>
This commit is contained in:
1 parent
d530841b0e
commit
3b4af96990
4 files changed
+101
No files matched your search
@@ -700,6 +700,48 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
||||
free(p);
|
||||
}
|
||||
|
||||
#if defined(ESP32) && (defined(WifiGMode) || defined(WifiPower))
|
||||
void setESP32WifiPorotocolTxPower() {
|
||||
//Reduce WiFi interference when using ESP32 using custom WiFi mode and tx power
|
||||
//https://github.com/espressif/arduino-esp32/search?q=WIFI_PROTOCOL_11G
|
||||
//https://www.letscontrolit.com/forum/viewtopic.php?t=671&start=20
|
||||
# if WifiGMode == true
|
||||
if (esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G) != ESP_OK) {
|
||||
Log.error(F("Failed to change WifiMode." CR));
|
||||
}
|
||||
# endif
|
||||
|
||||
# if WifiGMode == false
|
||||
if (esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N) != ESP_OK) {
|
||||
Log.error(F("Failed to change WifiMode." CR));
|
||||
}
|
||||
# endif
|
||||
|
||||
uint8_t getprotocol;
|
||||
esp_err_t err;
|
||||
err = esp_wifi_get_protocol(WIFI_IF_STA, &getprotocol);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
Log.notice(F("Could not get protocol!" CR));
|
||||
}
|
||||
if (getprotocol & WIFI_PROTOCOL_11N) {
|
||||
Log.notice(F("WiFi_Protocol_11n" CR));
|
||||
}
|
||||
if (getprotocol & WIFI_PROTOCOL_11G) {
|
||||
Log.notice(F("WiFi_Protocol_11g" CR));
|
||||
}
|
||||
if (getprotocol & WIFI_PROTOCOL_11B) {
|
||||
Log.notice(F("WiFi_Protocol_11b" CR));
|
||||
}
|
||||
|
||||
# ifdef WifiPower
|
||||
Log.notice(F("Requested WiFi power level: %i" CR), WifiPower);
|
||||
WiFi.setTxPower(WifiPower);
|
||||
# endif
|
||||
Log.notice(F("Operating WiFi power level: %i" CR), WiFi.getTxPower());
|
||||
}
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
//Launch serial for debugging purposes
|
||||
Serial.begin(SERIAL_BAUD);
|
||||
@@ -975,7 +1017,11 @@ bool wifi_reconnect_bypass() {
|
||||
while (WiFi.waitForConnectResult() != WL_CONNECTED && wifi_autoreconnect_cnt < maxConnectionRetryWifi) {
|
||||
# endif
|
||||
Log.notice(F("Attempting Wifi connection with saved AP: %d" CR), wifi_autoreconnect_cnt);
|
||||
|
||||
WiFi.begin();
|
||||
# if defined(ESP32) && (defined(WifiGMode) || defined(WifiPower))
|
||||
setESP32WifiPorotocolTxPower();
|
||||
# endif
|
||||
delay(1000);
|
||||
wifi_autoreconnect_cnt++;
|
||||
}
|
||||
@@ -2237,12 +2283,18 @@ void MQTTtoSYS(char* topicOri, JsonObject& SYSdata) { // json object decoding
|
||||
|
||||
Log.warning(F("Attempting connection to new AP" CR));
|
||||
WiFi.begin((const char*)SYSdata["wifi_ssid"], (const char*)SYSdata["wifi_pass"]);
|
||||
# if defined(ESP32) && (defined(WifiGMode) || defined(WifiPower))
|
||||
setESP32WifiPorotocolTxPower();
|
||||
# endif
|
||||
WiFi.waitForConnectResult();
|
||||
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
Log.error(F("Failed to connect to new AP; falling back" CR));
|
||||
WiFi.disconnect(true);
|
||||
WiFi.begin(prev_ssid.c_str(), prev_pass.c_str());
|
||||
# if defined(ESP32) && (defined(WifiGMode) || defined(WifiPower))
|
||||
setESP32WifiPorotocolTxPower();
|
||||
# endif
|
||||
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
|
||||
# if defined(ESP8266)
|
||||
ESP.reset();
|
||||
|
||||
Reference in new issue
Block a user