From 2685a6d71be6c76d55a2f3a813d8fa825b5b79f2 Mon Sep 17 00:00:00 2001 From: rpriven Date: Mon, 22 Jun 2026 12:59:04 -0600 Subject: [PATCH] Hold screen wake-lock during GPS capture (firmware-todo #1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Phone screen-sleep suspends the dashboard page and stops geolocation — the main cause of detections logged without coords while walking. Add Screen Wake Lock API: acquire on GPS start, re-acquire on visibilitychange when the page returns to foreground. Keeps watchPosition alive with the screen on. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/main.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 066771e..ae3fc5f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1520,6 +1520,12 @@ h+='

Raven UUIDs ('+p.raven.length+')

'+p document.getElementById('pC').innerHTML=h;window._pL=1;}).catch(()=>{});} // === GPS === let _gW=null,_gOk=false,_gTried=false; +// Screen Wake Lock — keep the screen on during GPS capture. Phone screen-sleep suspends the +// page and stops geolocation (the #1 cause of GPS-less detections while walking). Re-acquire +// when the page returns to the foreground. Needs a secure context (same flag GPS already needs). +let _wl=null; +async function acquireWake(){try{if('wakeLock' in navigator){_wl=await navigator.wakeLock.request('screen');_wl.addEventListener('release',function(){_wl=null;});}}catch(e){}} +document.addEventListener('visibilitychange',function(){if(document.visibilityState==='visible'&&_gW!==null&&_wl===null){acquireWake();}}); function sendGPS(p){_gOk=true;let g=document.getElementById('sG');g.textContent='OK';g.style.color='#22c55e'; fetch('/api/gps?lat='+p.coords.latitude+'&lon='+p.coords.longitude+'&acc='+(p.coords.accuracy||0)).catch(()=>{});} function gpsErr(e){_gOk=false;let g=document.getElementById('sG'); @@ -1530,7 +1536,7 @@ g.textContent=msg;} function startGPS(){if(!navigator.geolocation){return false;} if(_gW!==null){navigator.geolocation.clearWatch(_gW);_gW=null;} let g=document.getElementById('sG');g.textContent='...';g.style.color='#facc15'; -_gW=navigator.geolocation.watchPosition(sendGPS,gpsErr,{enableHighAccuracy:true,maximumAge:5000,timeout:15000});return true;} +_gW=navigator.geolocation.watchPosition(sendGPS,gpsErr,{enableHighAccuracy:true,maximumAge:5000,timeout:15000});acquireWake();return true;} function reqGPS(){if(!navigator.geolocation){alert('GPS not available in this browser.');return;} if(_gOk){return;} if(!window.isSecureContext){alert('GPS requires a secure context (HTTPS). This HTTP page may not get GPS permission.\\n\\nAndroid Chrome: try chrome://flags and enable "Insecure origins treated as secure", add http://192.168.4.1\\n\\niPhone: GPS will not work over HTTP.');}