Repository navigation
Gps on demand - #3877
Open
dhandzic wants to merge 2 commits into
Open
Gps on demand#3877dhandzic wants to merge 2 commits into
dhandzic wants to merge 2 commits into
Conversation
Open
dhandzic
force-pushed
the
gps-on-demand
branch
from
November 23, 2026 09:41
9924286 to
e86c0c7
Compare
This branch has not been deployed
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.
Companion: GPS on demand for permitted location telemetry requests
Motivation
GPS-equipped companions (e.g. T1000-E) currently have two options: GPS permanently on (battery life drops from weeks to days) or GPS off (a location telemetry request returns nothing, or a stale/manual position on some boards).
Use case: a volunteer emergency-messaging network in rural Sweden. Many users work in the forest, and when someone sends an alert the receiving station needs their real position, but nobody can afford to keep GPS on all day. The station is a contact with location permission and polls the sender's telemetry after receiving an alert.
This PR adds an opt-in mode: GPS stays off, and is powered up only when a contact that is allowed to read location requests telemetry.
Behaviour
New companion prefs (persisted in the
gpssection of the new config format):gps.odgps_odgps.od_togps_od_toThe mode is only active when
gps_on_demand == 1,gps_enabled == 0,gps_period == 0(no periodic acquisition) and the board has aLocationProvider.When a
REQ_TYPE_GET_TELEMETRY_DATAarrives and the requester's effective permissions includeTELEM_PERM_LOCATION:sensors.setSettingValue("gps", "1"), and the request (requester key, tag, permissions) is queued (max 4).isValid()and a GPS timestamp newer than at power-up, so stale NMEA state is ignored), plus 2 s forsensors.loop()to updatenode_lat/lon, a secondPAYLOAD_TYPE_RESPONSEwith full telemetry including location is sent to each queued requester. It is sent direct if a path is known, flood-scoped otherwise, and reuses the original tag.gps_od_to, GPS powers down and nothing more is sent. A new request while GPS is still searching restarts the search window.Permissions are evaluated exactly as today (
telemetry_mode_locplus per-contact flags plus the request's inverse mask). Nobody without location permission can wake the GPS.Compatibility
gps_od = 0the code path is identical to today. Telemetry reply building was only moved intobuildTelemetryReply(), with no change in content.pending_telemetrymatches, e.g. the first reply was lost), it is handled as a normal telemetry response;PUSH_CODE_BINARY_RESPONSE(tag + LPP). This is the same path already used for pushed telemetry, so host tools (e.g. meshcore_py) can decode it.Files
src/helpers/CompanionNodePrefs.h: two new fields plus serializer defsexamples/companion_radio/MyMesh.h: demand queue and stateexamples/companion_radio/MyMesh.cpp:buildTelemetryReply()refactorgpsOnDemandApplies(),queueGpsDemand(),checkGpsOnDemand()(called fromloop()),stopGpsOnDemand()gps_od/gps_od_to(get and set)Testing
Tested on T1000-E (
t1000e_companion_radio_usbbuild;_blebuilds and runs) as responder, with a Wio Tracker L1 USB companion as requester,gps_od=1,gps_od_to=120. GPS on/off state was observed through thegpscustom var.gps_od_to)gps_od = 0gps = 1(permanently on) +gps_od = 1gps_od/gps_od_topersistedThe 2nd reply arrives with the original tag and reaches the app as
PUSH_CODE_BINARY_RESPONSE; it decodes fine with meshcore_pylpp_parse().Update
dev. Location on demand is skipped whengps_period(periodic acquisition) is set.dev(T1000-E): outdoors 2nd reply with location after 58 s and 37.5 s; indoors GPS off aftergps_od_to.Not yet tested
EnvironmentSensorManager(e.g. Wio Tracker L1 as responder)Side note: with
gps_od = 0, the T1000-E answers location requests with the last stored position and no age indication, which can be hours old. For safety use cases that is a further argument for on-demand fixes.Open questions for maintainers
Closes #3919