fix(companion_radio): apply persisted GPS enabled setting on boot for ui-orig devices#2018
Open
got-root wants to merge 1 commit intomeshcore-dev:devfrom
Open
fix(companion_radio): apply persisted GPS enabled setting on boot for ui-orig devices#2018got-root wants to merge 1 commit intomeshcore-dev:devfrom
got-root wants to merge 1 commit intomeshcore-dev:devfrom
Conversation
The companion_radio example was not restoring the GPS enabled/disabled preference from flash after reboot. The preference was being saved correctly when toggled via the mobile app, but on boot, sensors.begin() -> initBasicGPS() unconditionally sets gps_active=false and nothing subsequently restored the persisted state. Added applyGpsPrefs() (matching the pattern in simple_repeater, simple_sensor, and simple_room_server) and call it from main.cpp after sensors.begin() to ensure the GPS hardware is initialized before the saved preference is applied.
|
Thank you! I was having the same problem. I love open source! 🦾 |
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.
Summary
ui-orig(WisMesh Tag, RAK3112, T1000-E, Minewsemi ME25LS01)applyGpsPrefs()method toMyMeshand calls it frommain.cppaftersensors.begin(), following the established pattern used insimple_repeater,simple_sensor, andsimple_room_serverui-newdevices but leftui-origdevices unaddressedFixes #989
Problem Description
Users reported that the "GPS Mode" setting (Disabled/Enabled) in the mobile app was not retained after reboot on companion_radio devices using
ui-orig. The device always showed "Disabled" after reconnecting, regardless of the setting before reboot. This was confirmed by multiple users across different hardware (WisMesh Tag, Heltec V4, T1000-E, RAK4631) in issue #989.What Was Working
The preference was being saved to flash correctly:
DataStore::savePrefs()writesgps_enabledto the/new_prefsfile (offset 85)DataStore::loadPrefs()reads it back into_prefs.gps_enabledon bootCMD_SET_CUSTOM_VARhandler inMyMesh::handleCmdFrame()correctly updates_prefs.gps_enabledand callssavePrefs()when the app sends a GPS toggleWhat Was Broken
The loaded
_prefs.gps_enabledvalue was never applied to theEnvironmentSensorManagerGPS hardware state after boot. The sensor manager'sinitBasicGPS()unconditionally setsgps_active = false(EnvironmentSensorManager.cpp:586), and nothing in the companion_radio boot sequence restored the persisted state afterward.Root Cause Analysis
PR #1156 added GPS preference persistence for companion_radio, but the runtime state restoration was only added to
ui-new/UITask.cpp::begin(). Devices usingui-orig(which has no equivalent code) were left without GPS state restoration.Additionally, the initialization order in
companion_radio/main.cppdiffers from other examples:simple_repeatersensors.begin()→the_mesh.begin()→applyGpsPrefs()✅simple_sensorsensors.begin()→the_mesh.begin()→applyGpsPrefs()✅simple_room_serversensors.begin()→the_mesh.begin()→applyGpsPrefs()✅companion_radiothe_mesh.begin()→sensors.begin()❌ (noapplyGpsPrefsanywhere)Because
sensors.begin()runs afterthe_mesh.begin()in companion_radio, the GPS preference must be applied aftersensors.begin()to avoid being overwritten byinitBasicGPS().Solution
Added
applyGpsPrefs()method toMyMesh.hand call it frommain.cppaftersensors.begin(), following the exact pattern used in the three other working examples:MyMesh.h— new method (matchessimple_repeater/MyMesh.h:161,simple_sensor/SensorMesh.h:158,simple_room_server/MyMesh.h:156):main.cpp— call after sensor initialization:Impact on ui-new Devices
This change is safe for ui-new devices. On ui-new builds,
applyGpsPrefs()is called frommain.cppaftersensors.begin(), and thenui-new/UITask::begin()applies the same preference again from its own code (added in #1156). The GPS state is set twice to the same value — redundant but harmless.Files Changed
examples/companion_radio/MyMesh.h— AddedapplyGpsPrefs()methodexamples/companion_radio/main.cpp— CallapplyGpsPrefs()aftersensors.begin()Testing
Hardware
RAK_WisMesh_Tag_companion_radio_bleBefore Fix
After Fix
Build Verification
RAK_WisMesh_Tag_companion_radio_bleRAK_WisMesh_Tag_companion_radio_usbRelated Issues & PRs