From 2f54640b2900c3456c77c7bf80c2e7475adf5612 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Sat, 6 Jul 2019 13:52:46 +0200 Subject: [PATCH] lock ap channel for faster reconnect --- src/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 1b23d80..52bede2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -106,6 +106,7 @@ unsigned long lastSuccess = 0; IPAddress ip, dns, gateway, subnet; char ssid[64]; char password[64]; +int32_t channel; struct __attribute__((packed)) SENSOR_DATA { float temperature; @@ -282,6 +283,8 @@ void ICACHE_FLASH_ATTR sendValues() { WiFi.forceSleepWake(); delay(1); // yield(); WiFi.mode(WIFI_STA); + //wifi_country_t wc = { .cc="DE", .schan=1, .nchan=13, .policy=WIFI_COUNTRY_POLICY_AUTO}; + //wifi_set_country(&wc); if ( ip != INADDR_NONE && dns != INADDR_NONE && gateway != INADDR_NONE && subnet != INADDR_NONE && ((ip[0] == 192 && ip[1] == 168) || (ip[0] == 172 && ip[1] == 16)) @@ -291,7 +294,7 @@ void ICACHE_FLASH_ATTR sendValues() { DEBUG_MSG("[WiFi] STATIC IP\n"); WiFi.config(ip, dns, gateway, subnet); - WiFi.begin(ssid, password); + WiFi.begin(ssid, password, channel); int tries = 0; constexpr unsigned int retry_delay = 500; constexpr unsigned int max_retry_delay = 10000; @@ -335,6 +338,7 @@ void ICACHE_FLASH_ATTR sendValues() { subnet = WiFi.subnetMask(); strncpy(ssid, WiFi.SSID().c_str(), 64); strncpy(password, WiFi.psk().c_str(), 64); + channel = WiFi.channel(); last_dhcp = rtcMillis(); }