diff --git a/src/main.cpp b/src/main.cpp index b3a9e98e7..91ad24d92 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1503,8 +1503,15 @@ void setup() PowerFSM_setup(); // we will transition to ON in a couple of seconds, FIXME, only do this for cold boots, not waking from SDS powerFSMthread = new PowerFSMThread(); -#if !HAS_TFT - setCPUFast(false); // 80MHz is fine for our slow peripherals +#ifndef ARCH_PORTDUINO + auto cpuFast = false; +#if HAS_TFT + cpuFast |= true; +#endif +#if HAS_WIFI + cpuFast |= !config.power.is_power_saving && isWifiAvailable(); +#endif + setCPUFast(cpuFast); #endif #ifdef ARDUINO_ARCH_ESP32 diff --git a/src/mesh/wifi/WiFiAPClient.cpp b/src/mesh/wifi/WiFiAPClient.cpp index 1133ad424..2ed47c9df 100644 --- a/src/mesh/wifi/WiFiAPClient.cpp +++ b/src/mesh/wifi/WiFiAPClient.cpp @@ -303,8 +303,20 @@ bool initWifi() WiFi.setAutoReconnect(true); WiFi.setSleep(false); - // This is needed to improve performance. - esp_wifi_set_ps(WIFI_PS_NONE); // Disable radio power saving + bool wifi_high_performance = false; + +#if HAS_UDP_MULTICAST + // need to increase WiFi performance (decrease DTIM interval) to avoid missing UDP packet broadcasts + wifi_high_performance |= + udpHandler && (config.network.enabled_protocols & meshtastic_Config_NetworkConfig_ProtocolFlags_UDP_BROADCAST); +#endif + + if (wifi_high_performance) { + esp_wifi_set_ps(config.power.is_power_saving ? WIFI_PS_MIN_MODEM : WIFI_PS_NONE); + + } else { + esp_wifi_set_ps(config.power.is_power_saving ? WIFI_PS_MAX_MODEM : WIFI_PS_MIN_MODEM); + } WiFi.onEvent( [](WiFiEvent_t event, WiFiEventInfo_t info) { @@ -512,4 +524,4 @@ uint8_t getWifiDisconnectReason() { return wifiDisconnectReason; } -#endif // HAS_WIFI \ No newline at end of file +#endif // HAS_WIFI diff --git a/src/sleep.cpp b/src/sleep.cpp index 3c230cae8..7cfcece8a 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -83,21 +83,10 @@ RTC_DATA_ATTR int bootCount = 0; */ void setCPUFast(bool on) { -#if defined(ARCH_ESP32) && !HAS_TFT -#ifdef HAS_WIFI - if (isWifiAvailable()) { -#if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(WIFI_MAX_PERFORMANCE) - LOG_DEBUG("Set CPU to 240MHz because WiFi is in use"); - setCpuFrequencyMhz(240); - return; -#endif - } -#endif - -// The Heltec LORA32 V1 runs at 26 MHz base frequency and doesn't react well to switching to 80 MHz... -#if !defined(ARDUINO_HELTEC_WIFI_LORA_32) && !defined(CONFIG_IDF_TARGET_ESP32C3) - setCpuFrequencyMhz(on ? 240 : 80); -#endif +#ifdef ARCH_ESP32 + uint8_t targetFrequency = on ? 240 : 80; + setCpuFrequencyMhz(targetFrequency); + LOG_INFO("CPU frequency set to %u MHz", targetFrequency); #endif }