You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 gps section of the new config format):
key
custom var
default
meaning
gps.od
gps_od
0
enable GPS on demand
gps.od_to
gps_od_to
120
max seconds to search for a fix (10–600)
The mode is only active when gps_on_demand == 1, gps_enabled == 0, gps_period == 0 (no periodic acquisition) and the board has a LocationProvider.
When a REQ_TYPE_GET_TELEMETRY_DATA arrives and the requester's effective permissions include TELEM_PERM_LOCATION:
Immediate reply (unchanged protocol): base and environment telemetry is sent at once, without location. The requester sees the node is alive and gets the battery level.
GPS is powered up via the existing sensors.setSettingValue("gps", "1"), and the request (requester key, tag, permissions) is queued (max 4).
As soon as a fresh fix is available (isValid() and a GPS timestamp newer than at power-up, so stale NMEA state is ignored), plus 2 s for sensors.loop() to update node_lat/lon, a second PAYLOAD_TYPE_RESPONSE with 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 stays on for 30 s (follow-up requests are then answered at once with location), then powers down. If no fix arrives within 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_loc plus per-contact flags plus the request's inverse mask). Nobody without location permission can wake the GPS.
Compatibility
Off by default. With gps_od = 0 the code path is identical to today. Telemetry reply building was only moved into buildTelemetryReply(), with no change in content.
Requester side needs no change. The second response carries the original tag:
if the requester is still waiting (pending_telemetry matches, e.g. the first reply was lost), it is handled as a normal telemetry response;
otherwise it falls through to the existing unhandled response path and reaches the app as 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.
Users who switch GPS on permanently while a demand is pending take over seamlessly: the on-demand logic stops managing the GPS.
The new pref fields are only in the new key/value config format, so the legacy binary prefs layout is untouched.
Files
src/helpers/CompanionNodePrefs.h: two new fields plus serializer defs
examples/companion_radio/MyMesh.h: demand queue and state
examples/companion_radio/MyMesh.cpp:
buildTelemetryReply() refactor
gpsOnDemandApplies(), queueGpsDemand(), checkGpsOnDemand() (called from loop()), stopGpsOnDemand()
custom vars gps_od / gps_od_to (get and set)
Testing
Tested on T1000-E (t1000e_companion_radio_usb build; _ble builds 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 the gps custom var.
Case
Result
Location-permitted request, GPS off, outdoors
1st reply after 1.0 s without location; 2nd reply with location after 4–55 s (first fix 46 s, warm 10 s, recent fix 4 s)
Repeat request within 30 s hold
location in 1st reply (1.0 s), no 2nd reply
GPS power-down after fix
off ~30 s after 2nd reply (total GPS on-time 84 s for one position)
Indoors, no fix
1st reply only; GPS off after 120 s (gps_od_to)
Requester without base permission
no reply at all (unchanged behaviour)
Requester with base but no location permission
1st reply without location; GPS stays off
gps_od = 0
unchanged: immediate reply with last stored position (may be stale), GPS stays off
gps = 1 (permanently on) + gps_od = 1
location in 1st reply; GPS is not switched off by on-demand logic
Power cycle
gps_od / gps_od_to persisted
The 2nd reply arrives with the original tag and reaches the app as PUSH_CODE_BINARY_RESPONSE; it decodes fine with meshcore_py lpp_parse().
Update
Rebased onto dev. Location on demand is skipped when gps_period (periodic acquisition) is set.
A new request while GPS is already searching restarts the search window.
Re-tested on dev (T1000-E): outdoors 2nd reply with location after 58 s and 37.5 s; indoors GPS off after gps_od_to.
Not yet tested
a board using EnvironmentSensorManager (e.g. Wio Tracker L1 as responder)
multiple simultaneous requesters
current measurement (my meter setup measured mostly the T1000-E charging current)
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
Would you prefer the deferred location to go through the new 1.18 telemetry push/subscription mechanism instead of a second response with the same tag?
Is 4 queued requesters / 30 s hold reasonable, or should the hold time also be a pref?
Should the immediate reply carry an explicit "location pending" marker (e.g. a reserved LPP channel) so apps can show "waiting for GPS…"?
+1, nice one. I tried the same idea a while ago (never got to a PR) and hit two things on hardware that may apply here:
Indoors, the AT6558R on my T114 mixes estimated epochs into its output (GGA quality 6, RMC status A with mode E). MicroNMEA counts those RMC sentences as valid, so isValid() plus a newer timestamp can pick an estimated epoch as the fresh fix. Not sure the T1000-E GNSS does the same, but it might be worth checking the fix quality before sending the second reply.
Each request restarts the search window, and there's no backoff after a timeout. Indoors with no sky view, a station that polls every 2-3 min would keep the GPS on for about 120 s out of every 180 s. A backoff after a timeout (I used 10 min) and at most one wake per minute kept that in check for me.
+1, nice one. I tried the same idea a while ago (never got to a PR) and hit two things on hardware that may apply here:
1. Indoors, the AT6558R on my T114 mixes estimated epochs into its output (GGA quality 6, RMC status A with mode E). MicroNMEA counts those RMC sentences as valid, so `isValid()` plus a newer timestamp can pick an estimated epoch as the fresh fix. Not sure the T1000-E GNSS does the same, but it might be worth checking the fix quality before sending the second reply.
2. Each request restarts the search window, and there's no backoff after a timeout. Indoors with no sky view, a station that polls every 2-3 min would keep the GPS on for about 120 s out of every 180 s. A backoff after a timeout (I used 10 min) and at most one wake per minute kept that in check for me.
Thanks, both points were valid and are addressed in the latest commit:
Fix quality: the second reply now uses getLastFix() and requires a fix stored
during the current wake-up with >= 4 satellites and a GSA mode other than "no fix",
so estimated epochs that MicroNMEA counts as valid are not reported.
Backoff: after a wake-up that ends without a fix, GPS is not woken again for 10 min
(a successful fix clears it), wake-ups are limited to one per minute, and a single
wake-up never searches longer than 2 x gps_od_to even if new requests keep
arriving. The immediate base reply is always sent. Backoff, wake interval and
minimum satellites can be overridden with build flags (GPS_OD_BACKOFF_MILLIS, GPS_OD_MIN_WAKE_MILLIS, GPS_OD_MIN_SATS).
Re-tested on T1000-E: indoors the GPS timed out after 120 s and an immediate re-poll
did not wake it (backoff); outdoors, after the backoff had expired, the 2nd reply came
with a position after 39 s.
This branch has not been deployed
No deployments
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
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