Skip to content

fix(5ghz): Rework WiFi LR logic for 5GHz chips#12202

Merged
me-no-dev merged 5 commits intomasterfrom
bugfix/long_range_5ghz
Jan 12, 2026
Merged

fix(5ghz): Rework WiFi LR logic for 5GHz chips#12202
me-no-dev merged 5 commits intomasterfrom
bugfix/long_range_5ghz

Conversation

@me-no-dev
Copy link
Member

@me-no-dev me-no-dev commented Jan 5, 2026

This pull request refactors and enhances how Long Range (LR) WiFi mode is enabled and disabled, especially for platforms supporting multiple bands (2.4GHz and 5GHz) and newer ESP-IDF versions. The changes introduce helper functions to manage LR mode more robustly and update the logic in the main WiFi mode handler to use these helpers, improving maintainability and compatibility.

Long Range (LR) WiFi Protocol Handling:

  • Introduced helper functions _wifi_is_lr_enabled, _wifi_enable_lr, and _wifi_disable_lr to encapsulate the logic for detecting, enabling, and disabling Long Range WiFi mode, with special handling for platforms supporting both 2.4GHz and 5GHz bands and ESP-IDF >= 5.4.2.
  • Defined new protocol bitmask macros (WIFI_PROTOCOL_DEFAULT, WIFI_PROTOCOL_DEFAULT_5G) to simplify protocol selection based on hardware and configuration support.

Refactoring of WiFi mode logic:

  • Updated the WiFiGenericClass::mode method to use the new helper functions for enabling/disabling LR mode, replacing direct protocol manipulation with more robust and readable code. This ensures correct protocol handling and better error reporting.
  • Removed duplicated protocol macro definitions from inside the function, centralizing them at the top for clarity and maintainability.

Fixes: #12200

@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2026

Messages
📖 🎉 Good Job! All checks are passing!

👋 Hello me-no-dev, we appreciate your contribution to this project!


📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more.

🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project.

Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against 055873e

@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2026

Test Results

 90 files   90 suites   31m 50s ⏱️
 67 tests  62 ✅ 0 💤 5 ❌
751 runs  745 ✅ 0 💤 6 ❌

For more details on these failures, see this check.

Results for commit 055873e.

♻️ This comment has been updated with latest results.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors WiFi Long Range (LR) mode handling to support dual-band ESP32 chips (2.4GHz and 5GHz) with ESP-IDF >= 5.4.2. The changes introduce helper functions to encapsulate LR protocol detection and configuration, replacing direct protocol manipulation with more maintainable code.

Key Changes:

  • Introduced three helper functions (_wifi_is_lr_enabled, _wifi_enable_lr, _wifi_disable_lr) to manage LR protocol state with special handling for dual-band configurations
  • Defined protocol bitmask macros (WIFI_PROTOCOL_DEFAULT, WIFI_PROTOCOL_DEFAULT_5G) to centralize protocol definitions
  • Refactored WiFiGenericClass::mode to use helper functions instead of direct ESP-IDF API calls

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2026

Memory usage test (comparing PR against master branch)

The table below shows the summary of memory usage change (decrease - increase) in bytes and percentage for each target.

MemoryFLASH [bytes]FLASH [%]RAM [bytes]RAM [%]
TargetDECINCDECINCDECINCDECINC
ESP32💚 -36⚠️ +320.000.00000.000.00
ESP32C30⚠️ +120.000.00000.000.00
ESP32C50⚠️ +12200.00⚠️ +0.12000.000.00
ESP32C60⚠️ +120.000.00000.000.00
ESP32H2000.000.00000.000.00
ESP32P40⚠️ +120.000.00000.000.00
ESP32S20⚠️ +160.000.00000.000.00
ESP32S30⚠️ +120.000.00000.000.00
Click to expand the detailed deltas report [usage change in BYTES]
TargetESP32ESP32C3ESP32C5ESP32C6ESP32H2ESP32P4ESP32S2ESP32S3
ExampleFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAM
libraries/ArduinoOTA/examples/BasicOTA⚠️ +16000⚠️ +12200⚠️ +100--⚠️ +100⚠️ +120⚠️ +120
libraries/ArduinoOTA/examples/SignedOTA💚 -40⚠️ +100⚠️ +12200⚠️ +100--⚠️ +120⚠️ +120⚠️ +120
libraries/AsyncUDP/examples/AsyncUDPClient⚠️ +160⚠️ +120⚠️ +12160⚠️ +120--⚠️ +120⚠️ +120⚠️ +120
libraries/AsyncUDP/examples/AsyncUDPMulticastServer⚠️ +40⚠️ +120--⚠️ +120--⚠️ +120⚠️ +120⚠️ +120
libraries/AsyncUDP/examples/AsyncUDPServer⚠️ +160⚠️ +120------⚠️ +120⚠️ +120⚠️ +120
libraries/DNSServer/examples/CaptivePortal⚠️ +160⚠️ +100------⚠️ +120⚠️ +120--
libraries/ESP32/examples/Camera/CameraWebServer00----------⚠️ +120--
ESP32/examples/Camera/CameraWebServer (2)⚠️ +120----------⚠️ +40--
libraries/ESP32/examples/Time/SimpleTime⚠️ +160⚠️ +120------⚠️ +120⚠️ +120--
libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Master⚠️ +160⚠️ +120--------⚠️ +120--
libraries/ESP_NOW/examples/ESP_NOW_Broadcast_Slave⚠️ +160⚠️ +100--------⚠️ +120--
libraries/ESP_NOW/examples/ESP_NOW_Network⚠️ +160⚠️ +120--------⚠️ +120--
libraries/ESP_NOW/examples/ESP_NOW_Serial⚠️ +160⚠️ +120--------⚠️ +120--
libraries/ESPmDNS/examples/mDNS-SD_Extended⚠️ +160⚠️ +120------⚠️ +120⚠️ +120--
libraries/ESPmDNS/examples/mDNS_Web_Server⚠️ +160⚠️ +100------⚠️ +120⚠️ +120--
libraries/Ethernet/examples/ETH_WIFI_BRIDGE⚠️ +160⚠️ +120------⚠️ +120⚠️ +120--
libraries/FFat/examples/FFat_time⚠️ +160⚠️ +120------⚠️ +100⚠️ +120--
libraries/HTTPClient/examples/Authorization⚠️ +120⚠️ +120------⚠️ +12000--
libraries/HTTPClient/examples/BasicHttpClient⚠️ +120⚠️ +120------⚠️ +12000--
libraries/HTTPClient/examples/BasicHttpsClient⚠️ +120⚠️ +120------⚠️ +12000--
libraries/HTTPClient/examples/CustomHeaders⚠️ +120⚠️ +100------⚠️ +12000--
libraries/HTTPClient/examples/HTTPClientEnterprise⚠️ +12000--------00--
libraries/HTTPClient/examples/ReuseConnection⚠️ +120⚠️ +120------⚠️ +12000--
libraries/HTTPClient/examples/StreamHttpClient⚠️ +120⚠️ +120------⚠️ +10000--
libraries/HTTPUpdate/examples/httpUpdate⚠️ +16000------⚠️ +120⚠️ +120--
libraries/HTTPUpdate/examples/httpUpdateSPIFFS⚠️ +160⚠️ +120------⚠️ +100⚠️ +40--
libraries/HTTPUpdate/examples/httpUpdateSecure⚠️ +120⚠️ +120------⚠️ +12000--
libraries/HTTPUpdateServer/examples/WebUpdater⚠️ +120⚠️ +120------⚠️ +120⚠️ +120--
libraries/Insights/examples/DiagnosticsSmokeTest⚠️ +120⚠️ +100--------00--
libraries/Insights/examples/MinimalDiagnostics⚠️ +160⚠️ +120--------00--
libraries/LittleFS/examples/LITTLEFS_time⚠️ +160⚠️ +120------⚠️ +120⚠️ +120--
libraries/Matter/examples/MatterColorLight⚠️ +12000----00--00--
libraries/Matter/examples/MatterCommissionTest⚠️ +12000----00--⚠️ +120--
libraries/Matter/examples/MatterComposedLights⚠️ +12000----00--00--
libraries/Matter/examples/MatterContactSensor⚠️ +12000----00--00--
libraries/Matter/examples/MatterDimmableLight⚠️ +12000----00--00--
libraries/Matter/examples/MatterDimmablePlugin⚠️ +12000----00--00--
libraries/Matter/examples/MatterEnhancedColorLight⚠️ +16000----00--00--
libraries/Matter/examples/MatterEvents⚠️ +12000----00--00--
libraries/Matter/examples/MatterFan⚠️ +12000----00--00--
libraries/Matter/examples/MatterHumiditySensor⚠️ +16000----00--00--
libraries/Matter/examples/MatterLambdaSingleCallbackManyEPs⚠️ +12000----00--00--
libraries/Matter/examples/MatterMinimum⚠️ +12000----00--00--
libraries/Matter/examples/MatterOccupancySensor💚 -32000----00--00--
libraries/Matter/examples/MatterOccupancyWithHoldTime⚠️ +4000----00--00--
libraries/Matter/examples/MatterOnIdentify⚠️ +12000----00--00--
libraries/Matter/examples/MatterOnOffLight⚠️ +12000----00--00--
libraries/Matter/examples/MatterOnOffPlugin⚠️ +12000----00--⚠️ +40--
libraries/Matter/examples/MatterPressureSensor💚 -36000----00--00--
libraries/Matter/examples/MatterRainSensor⚠️ +12000----00--00--
libraries/Matter/examples/MatterSimpleBlinds⚠️ +12000----00--00--
libraries/Matter/examples/MatterSmartButton⚠️ +12000----00--00--
libraries/Matter/examples/MatterStatus⚠️ +12000----00--00--
libraries/Matter/examples/MatterTemperatureControlledCabinet⚠️ +12000----00--00--
libraries/Matter/examples/MatterTemperatureControlledCabinetLevels⚠️ +12000----00--00--
libraries/Matter/examples/MatterTemperatureLight⚠️ +12000----00--00--
libraries/Matter/examples/MatterTemperatureSensor⚠️ +12000----00--00--
libraries/Matter/examples/MatterThermostat⚠️ +12000----00--00--
libraries/Matter/examples/MatterWaterFreezeDetector⚠️ +12000----00--00--
libraries/Matter/examples/MatterWaterLeakDetector⚠️ +12000----00--00--
libraries/Matter/examples/MatterWindowCovering⚠️ +12000----00--⚠️ +120--
libraries/NetBIOS/examples/ESP_NBNST⚠️ +120⚠️ +120------⚠️ +120⚠️ +120--
libraries/NetworkClientSecure/examples/WiFiClientInsecure⚠️ +120⚠️ +120------⚠️ +120⚠️ +120--
libraries/NetworkClientSecure/examples/WiFiClientPSK⚠️ +120⚠️ +120------⚠️ +120⚠️ +120--
libraries/NetworkClientSecure/examples/WiFiClientSecure⚠️ +120⚠️ +120------⚠️ +120⚠️ +120--
libraries/NetworkClientSecure/examples/WiFiClientSecureEnterprise⚠️ +120⚠️ +120--------00--
libraries/NetworkClientSecure/examples/WiFiClientSecureProtocolUpgrade⚠️ +120⚠️ +120------⚠️ +100⚠️ +120--
libraries/NetworkClientSecure/examples/WiFiClientShowPeerCredentials⚠️ +120⚠️ +120------⚠️ +12000--
libraries/NetworkClientSecure/examples/WiFiClientTrustOnFirstUse⚠️ +120⚠️ +120------⚠️ +120⚠️ +120--
libraries/PPP/examples/PPP_WIFI_BRIDGE⚠️ +160⚠️ +120------⚠️ +12000--
libraries/SD/examples/SD_time⚠️ +160⚠️ +120------⚠️ +120⚠️ +120--
libraries/SD_MMC/examples/SDMMC_time⚠️ +160--------⚠️ +120----
libraries/SPIFFS/examples/SPIFFS_time⚠️ +160⚠️ +120------⚠️ +120⚠️ +160--
libraries/Update/examples/AWS_S3_OTA_Update⚠️ +160⚠️ +120------⚠️ +120⚠️ +120--
libraries/Update/examples/HTTPS_OTA_Update00⚠️ +120------⚠️ +120⚠️ +120--
libraries/Update/examples/HTTP_Client_AES_OTA_Update⚠️ +160⚠️ +100------⚠️ +120⚠️ +120--
libraries/Update/examples/HTTP_Server_AES_OTA_Update⚠️ +120⚠️ +120------⚠️ +120⚠️ +120--
libraries/Update/examples/OTAWebUpdater⚠️ +120⚠️ +120------⚠️ +120⚠️ +120--
libraries/Update/examples/Signed_OTA_Update⚠️ +120⚠️ +120------⚠️ +12000--
libraries/WebServer/examples/AdvancedWebServer⚠️ +160⚠️ +120------⚠️ +120⚠️ +120--
libraries/WebServer/examples/ChunkWriting⚠️ +160⚠️ +120------⚠️ +120⚠️ +120--
libraries/WebServer/examples/FSBrowser⚠️ +120⚠️ +120------⚠️ +12000--
libraries/WebServer/examples/Filters⚠️ +160⚠️ +120------⚠️ +120⚠️ +120--
libraries/WebServer/examples/HelloServer⚠️ +160⚠️ +120------⚠️ +120⚠️ +120--
libraries/WebServer/examples/HttpAdvancedAuth⚠️ +120⚠️ +120------⚠️ +120⚠️ +120--
libraries/WebServer/examples/HttpAuthCallback⚠️ +120⚠️ +100------⚠️ +120⚠️ +120--
libraries/WebServer/examples/HttpAuthCallbackInline⚠️ +120⚠️ +120------⚠️ +100⚠️ +120--
libraries/WebServer/examples/HttpBasicAuth⚠️ +120⚠️ +120------⚠️ +120⚠️ +120--
libraries/WebServer/examples/HttpBasicAuthSHA1⚠️ +120⚠️ +120------⚠️ +100⚠️ +40--
libraries/WebServer/examples/HttpBasicAuthSHA1orBearerToken⚠️ +120⚠️ +120------⚠️ +120⚠️ +40--
libraries/WebServer/examples/Middleware⚠️ +200⚠️ +120--------⚠️ +120--
libraries/WebServer/examples/MultiHomedServers⚠️ +160⚠️ +120------⚠️ +120⚠️ +120--
libraries/WebServer/examples/PathArgServer00⚠️ +120------⚠️ +120⚠️ +120--
libraries/WebServer/examples/SDWebServer⚠️ +120⚠️ +120------⚠️ +12000--
libraries/WebServer/examples/SimpleAuthentification⚠️ +160⚠️ +120------⚠️ +120⚠️ +120--
libraries/WebServer/examples/UploadHugeFile⚠️ +160⚠️ +120------⚠️ +120⚠️ +120--
libraries/WebServer/examples/WebServer⚠️ +160⚠️ +120------⚠️ +120⚠️ +120--
libraries/WebServer/examples/WebUpdate⚠️ +120⚠️ +120------⚠️ +120⚠️ +120--
libraries/WiFi/examples/FTM/FTM_Initiator⚠️ +200⚠️ +120------⚠️ +120⚠️ +120--
libraries/WiFi/examples/FTM/FTM_Responder⚠️ +160⚠️ +100------⚠️ +100⚠️ +160--
libraries/WiFi/examples/SimpleWiFiServer⚠️ +200⚠️ +120------⚠️ +120⚠️ +120--
libraries/WiFi/examples/WPS⚠️ +160⚠️ +120--------⚠️ +120--
libraries/WiFi/examples/WiFiAccessPoint⚠️ +160⚠️ +120------⚠️ +120⚠️ +120--
libraries/WiFi/examples/WiFiBlueToothSwitch⚠️ +160⚠️ +120------------
libraries/WiFi/examples/WiFiClient⚠️ +160⚠️ +100------⚠️ +120⚠️ +120--
libraries/WiFi/examples/WiFiClientBasic⚠️ +160⚠️ +120------⚠️ +10000--
libraries/WiFi/examples/WiFiClientConnect⚠️ +200⚠️ +120------⚠️ +120⚠️ +120--
libraries/WiFi/examples/WiFiClientEnterprise⚠️ +160⚠️ +120--------00--
libraries/WiFi/examples/WiFiClientEvents⚠️ +160⚠️ +100------⚠️ +120⚠️ +120--
libraries/WiFi/examples/WiFiClientStaticIP⚠️ +320⚠️ +100------⚠️ +120⚠️ +120--
libraries/WiFi/examples/WiFiExtender⚠️ +120⚠️ +100------⚠️ +120⚠️ +120--
libraries/WiFi/examples/WiFiIPv6⚠️ +160⚠️ +120------⚠️ +120⚠️ +120--
libraries/WiFi/examples/WiFiMulti⚠️ +160⚠️ +120------⚠️ +120⚠️ +120--
libraries/WiFi/examples/WiFiMultiAdvanced⚠️ +120⚠️ +100------⚠️ +12000--
libraries/WiFi/examples/WiFiScan⚠️ +160⚠️ +120------⚠️ +120⚠️ +120--
libraries/WiFi/examples/WiFiScanAsync⚠️ +160⚠️ +120------⚠️ +120⚠️ +120--
libraries/WiFi/examples/WiFiScanDualAntenna⚠️ +40⚠️ +100------⚠️ +120⚠️ +120--
libraries/WiFi/examples/WiFiScanTime⚠️ +160⚠️ +120------⚠️ +10000--
libraries/WiFi/examples/WiFiSmartConfig⚠️ +160⚠️ +100--------⚠️ +160--
libraries/WiFi/examples/WiFiTelnetToSerial⚠️ +160⚠️ +100------⚠️ +120⚠️ +120--
libraries/WiFi/examples/WiFiUDPClient⚠️ +160⚠️ +120------⚠️ +100⚠️ +120--
libraries/WiFiProv/examples/WiFiProv⚠️ +120⚠️ +120--------⚠️ +160--
libraries/Zigbee/examples/Zigbee_Gateway⚠️ +120⚠️ +120--------00--
libraries/RainMaker/examples/RMakerCustom--⚠️ +120--------00--
libraries/RainMaker/examples/RMakerCustomAirCooler--⚠️ +120--------00--
libraries/RainMaker/examples/RMakerSonoffDualR3--⚠️ +120--------00--
libraries/RainMaker/examples/RMakerSwitch--⚠️ +100--------00--
libraries/ESP_HostedOTA/examples/ESP_HostedOTA----------⚠️ +120----
ESP32/examples/Camera/CameraWebServer (3)----------------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@me-no-dev me-no-dev added the Status: Review needed Issue or PR is awaiting review label Jan 5, 2026
Copy link
Member

@lucasssvaz lucasssvaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@SuGlider SuGlider self-requested a review January 12, 2026 12:55
@SuGlider SuGlider removed the Status: Review needed Issue or PR is awaiting review label Jan 12, 2026
@me-no-dev me-no-dev added the Status: Pending Merge Pull Request is ready to be merged label Jan 12, 2026
@me-no-dev me-no-dev merged commit 79741e9 into master Jan 12, 2026
78 of 81 checks passed
@me-no-dev me-no-dev deleted the bugfix/long_range_5ghz branch January 12, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Pending Merge Pull Request is ready to be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ESP32-C5 Runtime error on WiFi.mode()

4 participants