Skip to content

Add GPS geofence and distance-based ping filtering for Ottawa region#53

Merged
MrAlders0n merged 6 commits intodevfrom
copilot/add-gps-filtering-for-pings
Dec 18, 2025
Merged

Add GPS geofence and distance-based ping filtering for Ottawa region#53
MrAlders0n merged 6 commits intodevfrom
copilot/add-gps-filtering-for-pings

Conversation

Copy link
Contributor

Copilot AI commented Dec 18, 2025

GPS Ping Controls Implementation - COMPLETE ✅

All requirements have been successfully implemented and tested.

✅ Implementation Summary

1. Ottawa Regional Geofence (150 km)

  • Center: Parliament Hill (45.4215°N, 75.6972°W)
  • Radius: 150,000 meters (150 km)
  • Implementation: Haversine distance calculation for accurate GPS measurements
  • Behavior: Blocks ALL ping operations (Mesh + API) when device is outside geofence
  • Applies to: First ping after app start AND all subsequent pings

2. Distance-Based Ping Filtering (25 m)

  • Threshold: 25 meters minimum movement required between pings
  • Tracking: lastSuccessfulPingLocation updated only after successful ping (Mesh + API complete)
  • First Ping: Distance check skipped if no previous successful ping exists
  • Behavior: Reduces unnecessary network traffic when device hasn't moved significantly

3. Validation Order (ENFORCED)

  1. Geofence validation - FIRST priority, must pass
  2. Distance validation - SECOND priority, must pass (if previous ping exists)
  3. Ping execution - Only if both validations pass

4. UI Enhancements

  • New Field: "Distance from last ping:" showing distance from last successful ping
  • Real-time Updates: Updates every 3 seconds or when GPS position changes
  • Battery Optimized: Main updates triggered by GPS changes, timer is fallback only

UI with Distance Field

5. Status Messages (Per Requirements)

Manual Ping - Geofence Skip

  • Message: Ping skipped, outside of geo fenced region
  • Persists until next successful ping

Auto Ping - Geofence Skip

  • Message: Ping skipped, outside of geo fenced region, waiting for next ping (Xs)
  • Shows countdown timer, persists until successful ping

Manual Ping - Distance Skip

  • Message: Ping skipped, too close to last ping
  • Persists until next successful ping

Auto Ping - Distance Skip

  • Message: Ping skipping, too close to last ping, waiting for next ping (Xs)
  • Shows countdown timer, persists until successful ping

6. Debug Logging (Comprehensive)

  • ✅ GPS coordinates logged at validation points
  • ✅ Geofence distance calculation + pass/fail result
  • ✅ Last successful ping location tracked
  • ✅ Movement distance calculation + pass/fail result
  • ✅ Ping execution or skip decision with reason
  • ✅ All new functions include debug logging
  • ✅ Follows existing DEBUG_ENABLED pattern

🔒 Security

  • ✅ CodeQL security scan passed (0 alerts)
  • ✅ No new vulnerabilities introduced
  • ✅ Input validation on GPS coordinates

✅ Testing Performed

  • ✅ Haversine distance calculation verified (tested with known coordinates)
  • ✅ JavaScript syntax validation passed
  • ✅ UI rendering verified with new distance field
  • ✅ Code review completed and addressed

📝 Core Requirements Met

  • Ottawa geofence (45.4215, -75.6972, 150km)
  • Haversine distance calculation
  • Geofence validation (FIRST)
  • Distance validation (SECOND, ≥25m)
  • Last successful ping location tracking
  • UI field for Distance from last ping
  • Manual geofence skip message
  • Auto geofence skip message with countdown
  • Manual distance skip message
  • Auto distance skip message with countdown
  • Skip messages persist until successful ping
  • GPS tracking continues regardless of skip state
  • First ping after app start respects geofence
  • Debug logging throughout
  • Battery optimization for distance updates
Original prompt

MeshCore WarDriver — GPS Ping Controls (AI Agent Task Brief)

Repository: MrAlders0n/MeshCore-GOME-WarDriver
Branch: dev
Stack: JavaScript / CSS / HTML
Goal: Add GPS-based filtering to (1) reduce unnecessary pings and (2) restrict ping capability to the Ottawa region.


Definition: “Ping Operation”

A “ping” is one combined operation consisting of:

  • Mesh message send
  • MeshMapper API call

These two actions must always execute together or be skipped together.


Core Rules (Must Hold)

  • GPS tracking continues regardless of skip/block state.
  • Every ping attempt (manual or auto) validates in this exact order:
    1. Geofence check (Ottawa, 150 km) — FIRST
    2. Moved ≥ 25 m since last successful ping — SECOND (skip if no previous successful ping)
    3. If both pass → execute ping (Mesh + API) and update last successful ping location

Feature 1 — Ottawa Regional Geofence (150 km)

Configuration (Constants)

  • Center: Ottawa Parliament Hill
    • Latitude: 45.4215
    • Longitude: -75.6972
  • Radius: 150_000 meters (150 km)

Behavior

  • Compute Haversine distance from current GPS position to Ottawa center.
  • If distance > 150 km, block all ping operations (Mesh + API), including the first ping after app start.
  • GPS tracking continues even when blocked.

Status Message Behavior

Manual Ping

  • Display: Ping skipped, outside of geo fenced region
  • Must remain as the “reason for last failure” until a successful ping occurs (i.e., do not revert back to a neutral/idle state; it may still temporarily show “sending ping…” etc. during subsequent attempts)

Auto Ping

  • Display: Ping skipped, outside of geo fenced region with countdown timer
  • Replace the normal “waiting for next ping” message.
  • Only return to normal “waiting for next ping” status after a successful ping.

Feature 2 — Distance-Based Ping Filtering (25 m)

Purpose

Reduce unnecessary pings and network traffic when the device hasn’t meaningfully moved.

Behavior

  • Track lastSuccessfulPingLocation (lat/lon) after a ping succeeds (Mesh + API).
  • On each ping attempt:
    • Compute Haversine distance between current GPS position and lastSuccessfulPingLocation
    • If distance < 25 m, skip ping (Mesh + API)
  • If no previous successful ping exists, skip this distance check.

Distance Since Last Valid Ping (UI Field)

  • Add a dedicated UI field that displays the current computed distance from the last successful ping.
  • Condense the field label so it matches existing short labels (e.g., similar to “GPS”, “Status”).
    • Example label options (pick one that fits your UI style): ΔDist, Dist, Move, or LastΔ

Status Message Behavior (Too-Close Skip)

Manual Ping

  • Display: Ping skipped, too close to last ping
  • Must remain as the “reason for last failure” until a successful ping occurs (do not revert to idle)

Auto Ping

  • Replace the normal “waiting for next ping” message with:
    • Ping skipping, too close to last ping, waiting for next ping (Xs)
    • Where Xs is the countdown derived from the selected interval

Debug Logging (Required)

  • Add debug logging to every new function introduced by this change and to key decision points in modified functions.
  • Use the repo’s existing debug logging mechanism (follow the current patterns in the codebase, including how debug mode is enabled/disabled).
  • At minimum, log:
    • Current GPS coordinates used for validation
    • Geofence distance calculation + pass/fail outcome
    • Last successful ping location (when present)
    • Movement distance calculation + pass/fail outcome
    • Whether the ping operation was executed or skipped (and why)

Acceptance Criteria

  • Geofence validation runs first on every ping attempt (manual + auto), including first ping after startup
  • If device is outside 150 km: skip all ping operations (Mesh + API)
  • If device is within 150 km but < 25 m from last successful ping: skip all ping operations (Mesh + API)
  • Manual skip status remains as the last-failure reason until the next successful ping (no return to neutral/idle)
  • Auto “too close” skip status uses: Ping skipping, too close to last ping, waiting for next ping (Xs)
  • GPS tracking continues regardless of skip state
  • A compactly-labeled distance field is displayed to the user showing movement since last successful ping
  • First ping after app start succeeds only if device is within Ottawa geofence

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits December 18, 2025 20:06
Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com>
Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com>
Copilot AI changed the title [WIP] Add GPS-based filtering for Ottawa region pings Add GPS geofence and distance-based ping filtering for Ottawa region Dec 18, 2025
Copilot AI requested a review from MrAlders0n December 18, 2025 20:13
@MrAlders0n
Copy link
Collaborator

@copilot Update
Auto geofence skip: "Ping skipped, outside of geo fenced region (Xs)" with countdown

With

Auto distance skip: "Ping skipped, outside of geo fenced region, waiting for next ping (Xs)"

Copilot AI and others added 2 commits December 18, 2025 20:26
Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com>
Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com>
@MrAlders0n
Copy link
Collaborator

@copilot distance from last ping:

Captilize D

@MrAlders0n MrAlders0n marked this pull request as ready for review December 18, 2025 20:31
Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 18, 2025

@copilot distance from last ping:

...

Updated in commit 1d2ebe1. The field now displays "Distance from last ping:" with a capital D.

UI with capitalized field

@MrAlders0n MrAlders0n merged commit aeb7814 into dev Dec 18, 2025
@MrAlders0n MrAlders0n deleted the copilot/add-gps-filtering-for-pings branch December 19, 2025 01:25
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