Fix wifi check#318
Open
pm-ju wants to merge 6 commits into
Open
Conversation
Add assertion for unregistered module commands.
Mark WiFi controller as initialized before connection attempts.
Add initialization check for WiFi controller.
jmadden173
requested changes
Feb 21, 2026
Contributor
jmadden173
left a comment
There was a problem hiding this comment.
Assert statements shouldn't be used in this case. We don't want to hard fault the mcu. Instead propagating the error up in the program to "soft" handle it.
Replace assert with conditional check for wifi_initialized.
Removed assert statement for unregistered module commands.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Name/Affiliation/Title
Name: Pritish Mahato Affiliation: Jadavpur University(RISC-V) Title: Student Contributor
Purpose of the PR:
This PR adds runtime assert checks to prevent the WiFi module from being used when it was not enabled in the firmware configuration. This addresses a recurring bug where attempting to use WiFi functions (e.g.,
ControllerWiFiConnect, ControllerWiFiPost) without WiFi being initialized caused silent failures, the I2C commands would be sent to the ESP32 with no error feedback to the developer.
Changes:
STM32 controller WiFi library (stm32/lib/controller/): Added a wifi_initialized static flag and a new ControllerWiFiSetInitialized() function. An assert(wifi_initialized) guard is placed in WiFiCommandTransaction(), the single choke-point for all ControllerWiFi* functions, ensuring any accidental WiFi usage when not enabled immediately halts with a descriptive assert message.
STM32 WiFi application (stm32/Src/wifi.c): Calls ControllerWiFiSetInitialized() at the start of WiFiInit() to arm the guard.
ESP32 module handler (esp32/lib/module_handler/src/module_handler.cpp): Added assert(false) when an I2C command arrives for an unregistered module, replacing the previous behavior of silently logging and returning.
Development Environment:
OS: Windows 11
PlatformIO: version 6.1.19
Hardware version: N/A
Test Procedure:
This is a defensive programming fix, the asserts fire only when the WiFi module is misused (called without being enabled). Normal operation is unaffected.
Build verification: All STM32 and ESP32 environments compile successfully with pio run in both stm32/ and esp32/ directories.
Existing unit tests: All existing tests in pio test -e tests (STM32) continue to pass since they don't invoke the WiFi controller path without initialization.
Manual verification: Flash the STM32 with a LoRa-only user config. If any code path accidentally calls a ControllerWiFi* function, the firmware now halts at the assert instead of silently failing over I2C.
Additional Context:
The bug was encountered twice by the maintainer when attempting to use the WiFi module without it being enabled in the firmware. The fix is minimal and surgical ,a single assert() in the WiFiCommandTransaction() choke-point guards all 11 public ControllerWiFi* functions without modifying any of their signatures or behavior.
Task List:
Closes #272