Skip to content

Fix GPS coordinate consistency between mesh ping and API post#67

Merged
MrAlders0n merged 3 commits intodevfrom
copilot/fix-gps-coordinate-consistency
Dec 19, 2025
Merged

Fix GPS coordinate consistency between mesh ping and API post#67
MrAlders0n merged 3 commits intodevfrom
copilot/fix-gps-coordinate-consistency

Conversation

Copy link
Contributor

Copilot AI commented Dec 19, 2025

GPS coordinates were not synchronized between mesh ping transmission and API post 7 seconds later. During the listening window, the GPS watch continuously updates state.lastFix, causing API posts to use coordinates different from the original mesh ping.

Changes

  • Added state.capturedPingCoords to explicitly store coordinates at ping time
  • Capture coordinates immediately before mesh transmission (line 1631)
  • Use captured coordinates for API post after 7-second window (lines 1685-1696)
  • Clear coordinates after API post and on disconnect cleanup

Example

Before: Closure variables could become stale during 7-second window

// In sendPing():
const coords = await getGpsCoordinatesForPing(...);
const { lat, lon, accuracy } = coords;
// ... send ping

setTimeout(async () => {
  await postApiAndRefreshMap(lat, lon, accuracy, heardRepeats); // Uses closure vars
}, 7000);

After: Explicit state capture ensures consistency

// Capture at ping time
state.capturedPingCoords = { lat, lon, accuracy };

// 7 seconds later
const { lat: apiLat, lon: apiLon, accuracy: apiAccuracy } = state.capturedPingCoords;
await postApiAndRefreshMap(apiLat, apiLon, apiAccuracy, heardRepeats);
state.capturedPingCoords = null; // Clear after use

This guarantees mesh ping coordinates match API post coordinates regardless of GPS updates during the listening window.

Original prompt

Problem: GPS Coordinate Synchronization Between Mesh Ping and API Post

There is a logic error introduced in recent pull requests affecting GPS coordinate consistency.

Current Behavior

  1. Web app sends a ping on the mesh network
  2. Waits 7 seconds to listen for heard repeaters/channel echoes
  3. Posts results to the API

The Issue

The GPS coordinates used when sending the ping on the mesh are not the same coordinates being posted to the API.

Required Behavior

  1. When a ping is sent on the mesh network, capture and store the exact GPS coordinates at that moment
  2. After the 7-second listening period, post those same stored coordinates to the API along with the ping results
  3. Only after the API post is complete should the coordinate variables be cleared/reset in preparation for the next ping cycle

Goal

Ensure GPS coordinate consistency between the mesh ping transmission and the API post by capturing coordinates once at ping time and using those same coordinates throughout the entire ping-listen-post cycle.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 19, 2025 14:47
- Add capturedPingCoords field to state to store GPS coordinates at ping time
- Capture coordinates immediately when mesh ping is sent
- Use stored coordinates for API post after 7-second listening window
- Clear captured coordinates after API post completes
- Ensure coordinates are cleared during cleanup

Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com>
- Move coordinate clearing outside if-else block for consistency
- Remove fallback to closure variables to prevent stale coordinates
- Add critical error logging if coordinates are missing
- Skip API post if coordinates unavailable to prevent incorrect data

Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix GPS coordinate synchronization between mesh ping and API post Fix GPS coordinate consistency between mesh ping and API post Dec 19, 2025
Copilot AI requested a review from MrAlders0n December 19, 2025 14:53
@MrAlders0n MrAlders0n marked this pull request as ready for review December 19, 2025 14:59
@MrAlders0n MrAlders0n merged commit f1da8cd into dev Dec 19, 2025
@MrAlders0n MrAlders0n deleted the copilot/fix-gps-coordinate-consistency branch December 20, 2025 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants