B2: GPS/GNSS not working anymore

Posted on
  • I tried to run with my Bangle.js 2 today but wasn't able to get a GPS/GNSS fix in several minutes, also trying multiple reboots (which helped before most of the time).

    Then i started the GPS info app and see no fix again after being outside for quite some times.

    Then i tried

    Bangle.on('GPS', (f)=>{console.log(f);} );
    Bangle.setGPSPower(1);
    

    from https://github.com/espruino/BangleApps/w­iki/GPS-Issues via the WebIDE but i don't see any GPS event coming in.

    Can it be that my GPS/GNSS module is broke?

  • I tried to update A-GPS data, flashed current edge firmware and also tried to let the battery drain but all three did not bring any success.

  • You could try flattening the battery which would hard-reset the GPS...

    Could this also be related to recent changes in the Gadgetbridge app which attempt to use the phone's GPS via the Gadgetbridge connection if it exists?

  • You could try flattening the battery which would hard-reset the GPS...

    I already tried that but did not help.

    Could this also be related to recent changes in the Gadgetbridge app which attempt to use the phone's GPS via the Gadgetbridge connection if it exists?

    Yes indeed i had this activated. I will try with this disabled in the next days.

  • So today i tried again:
    At home on the window bench running GPS Info, got fix after 2-3 minutes. So far so good.
    Then went outside for a walk and tried to record it using Run app but for the whole walk (> 1h) no fix could be aquired. I tried a reboot after around 10 minutes but didn't help.

    Something is still a bit buggy with the GPS/GNS.

  • Yesterday and today i tried again 20+ minutes under clear sky but not a single GPS/GNS event coming in while having GPS Info app opened.

    I am really not sure what i can do to get it working again.

  • What happens if you do a factory reset (you can backup first), then install just the GPS info app and nothing else?

    It might not be a surprise that this coincides with the GPS functionality being added to Gadgetbridge/Android.

    Yesterday and today i tried again 20+ minutes under clear sky but not a single GPS/GNS event coming in while having GPS Info app opened.

    Are you trying to figure this out based on the packets received measurement you added to GPS Info?

    Because I just tried this and I'm not sure what it's measuring but I'm constantly getting packets from the GPS based on Bangle.on('GPS',print) (just without a fix) but they are not being counted on GPS Info at all.

  • Are you trying to figure this out based on the packets received measurement you added to GPS Info?

    Because I just tried this and I'm not sure what it's measuring but I'm constantly getting packets from the GPS based on Bangle.on('GPS',print) (just without a fix) but they are not being counted on GPS Info at all.

    You are right, there is a bug in the code of GPS Info which i will fix soon.
    But even if i have the following code running for several hours under clear sky i don't see any output in the IDE:

    Bangle.setGPSPower(1, "app");
    Bangle.on('GPS',print);
    

    What happens if you do a factory reset (you can backup first), then install just the GPS info app and nothing else?

    I will try this in the coming days and will report back here.

  • That is very odd. Even without a fix the GPS should be outputting some data.

    What about adding Bangle.on('GPS-raw',print); as well in case the GPS somehow got configured not to output the relevant NMEA sentences

  • So, i reseted my B2 on the weekend and just installed GPS info app. It worked! I got a fix in a couple of minutes.
    Then i restored everything from my backup and it worked again: fix in a short time.
    I was very happy but also a bit confused.

    Today i tried again and it stopped working again. Not a single GPS or GPS-raw event in more than 30 minutes under clear sky.

  • Today i tried again and it stopped working again. Not a single GPS or GPS-raw event in more than 30 minutes under clear sky.

    Hmm. I'm wondering whether this is to do with the recent Gadgetbridge code to allow the phone to access your device's GPS... What happens if you type Bangle.setGPSPower in the IDE? Does it say =function () { [native code] } or something else?

    If it's something else it means that the Android Integration app has jumped in and taken control of the GPS

  • I do not have the Gadgetbridge's GPS functionality enabled.

    It says

    >Bangle.setGPSPower
    =function (on,id) { ... }
    
    >Bangle.setGPSPower.toString()
    ="function (on,id) " ... ";return isGPSon;}"
    
  • Ok, well that's good news then - your hardware is fine.

    What you're seeing is that the GPS function has been overwritten by something. But I don't see any function containing return isGPSon anywhere in the BangleApps repository (assuming your apps were up to date)... So is it maybe something you wrote?

    Could you try running this?

    require("Storage").list().filter(f => require("Storage").read(f).includes("isG­PSOn;"))
    

    Hopefully it'll show the file that contains that code

  • Good idea, sadly no luck:

    >require("Storage").list().filter(f => require("Storage").read(f).includes("isG­PSOn;"))
    =[  ]
    

    My apps are up to date. I don't have sensor tools installed:

    Firmware Version	2v16.45
    Apps Installed	activityreminder (0.10), banglexercise (0.03), owmweather (0.02), poweroff (0.01), qmsched (0.09), run (0.14), waypoints (0.01), kbmulti (0.05), locale (0.17), widgps (0.09), bledetect (0.04), flappy (0.06), magnav (0.05), info (0.03), sevenmin (0.01), mylocation (0.09), wid_a_battery_widget (0.04), widbthide (0.01), widsleepstatus (0.02), openstmap (0.15), sleeplog (0.12), fastload (0.03), wid_edit (0.02), torch (0.11), widhrm (0.06), hrm (0.11), boot (0.55), widalarm (0.01), messages (0.58), iconlaunch (0.15), widlock (0.08), slopeclockpp (0.08), widmessages (0.04), a_dndtoggle (0.01), setting (0.56), alarm (0.37), agenda (0.11), notify (0.12), altimeter (0.02), quicklaunch (0.08), gbmusic (0.11), sched (0.19), stopwatch (0.04), ha (0.09), mtnclock (0.01), mmind (0.02), messageicons (0.04), messagegui (0.64), android (0.21), agpsdata (0.06), health (0.22), recorder (0.21), weather (0.24), gpsinfo (0.12), circlesclock (0.24)
    
  • I grabbed a new backup from the Bangle and greped the files:

    ❯ grep -iRl "isGPSon"
    .boot0
    widgps.wid.js
    android.boot.js
    info.app.js
    
    
    ❯ grep -iR "isGPSon;"
    widgps.wid.js:(ª(){settings=Object.assig­n(require('Storage').readJSON("widgps.de­fault.json",´) {},require('Storage').rea­dJSON("widgps.json",´) {});¬interval;¬ol­dSetGPSPower=Bangle.setGPSPower;Bangle.s­etGPSPower=ª(on,id){¬isGPSon=oldSetGPSPo­wer(on,id);WIDGETS.gps.width=!isGPSonset­tings.hideWhenGpsOff?0:24;Bangle.drawWid­gets();«isGPSon;};WIDGETS.gps={area:"tr"­,width:!Bangle.isGPSOn()settings.hideWhe­nGpsOff?0:24,draw:ª(){g.reset();£(Bangle­.isGPSOn()interval·){interval=setInterva­l(ª(){WIDGETS.gps.draw(WIDGETS.gps);},10­*1000);}¤£(!Bangle.isGPSOn()interval·){c­learInterval(interval);interval=·;}£(set­tings.crossIcon){£(Bangle.isGPSOn()){®gp­sObject=Bangle.getGPSFix();£(gpsObjectgp­sObject.fix>0){g.setColor("#0F0");}¤{g.s­etColor("#FD0");}g.drawImage(atob("GBiBA­AAAAAAAAAAAAA//8B//+BgYGBgYGBgYGBgYGBgYG­BgYGB//+B//+BgYGBgYGBgYGBgYGBgYGBgYGB//+­A//8AAAAAAAAAAAAA=="),¯.x,2+¯.y);}¤{£(!s­ettings.hideWhenGpsOff){g.setColor("#888­");g.drawImage(atob("GBiBAAAAAAAAAAAAAA/­/8B//+BgYGBgYGBgYGBgYGBgYGBgYGB//+B//+Bg­YGBgYGBgYGBgYGBgYGBgYGB//+A//8AAAAAAAAAA­AAA=="),¯.x,2+¯.y);}}}¤{£(Bangle.isGPSOn­()){®gpsObject=Bangle.getGPSFix();£(gpsO­bjectgpsObject.fix>0){g.drawImage(atob("­GBiBAAAAAAAAAAB+AAD/AAHDgAMAwAcAwAY8YAY8­YAY8YAY8YAMAwAMAwAOBwAGBgAHDgADDAABmAAB+­AAA8AAAYAAAAAAAAAAAAAA=="),¯.x,2+¯.y);}¤­{g.drawImage(atob("GBiBAAAAAAAAAAh+AA3/g­A+B4A8AcA+AMAA8GAB+GADnDADDDADDDDDDADBmA­DB+ABg8ABgYAAwB8A4A8AeB8AH/sAB+EAAAAAAAA­A=="),¯.x,2+¯.y);}}¤{£(!settings.hideWhe­nGpsOff){g.drawImage(atob("GBiBAAAAAAAAA­AB+ABj/ABxDgA4AwAcAwAeMYAfEYAbgYAZwYAM4w­AMcQAOOAAGHAAHDgADDwABm4AB+cAA8OAAYGAAAA­AAAAAAAAA=="),¯.x,2+¯.y);}}}}};})();
    
    
    ❯ grep -iRl "return isGPSon;"
    
    
  • I found a code block here:
    https://github.com/espruino/BangleApps/b­lob/master/apps/widgps/widget.js#L12

    After deinstalling the GPS widget the function definition is different:

    >Bangle.setGPSPower.toString()
    ="function (isOn,ap" ... "wr});return pwr;}"
    

    But GPS still not working.

    Then i found that in android.settings.json the key "overwriteGps" was set to true.
    I set it manually to false in the json file via the IDE and GPS works again!

    I am pretty sure that i never turned this on in the Bangle.js android app but who actually knows...

    So if the Bangle.js android app expects GPS coming from GadgetBridge but the setting in GP is turned off then the Bangle.js will never get any GPS.

    I feel sorry for the time the hunt for this consumed.

    Thank you for your help, this seems to be solved!

  • Ahh, thanks! That's so stupid! Looks like I made a typo isGPSOn vs isGPSon - and so my grepping failed!

    So it turns out that widgps was hiding the real implementation!

    Then i found that in android.settings.json the key "overwriteGps" was set to true.

    I've just checked into this - I could be wrong, but I can't see how it could have got enabled unless you'd enabled it.

    I'd have hoped you'd have seen messages like t: "gps_power", status: true } too, from https://github.com/espruino/BangleApps/b­lob/master/apps/android/boot.js#L215

    The frustrating thing is that when disconnected, it should work as normal - but the second you connect to see what's going on it would switch to the Gadgetbridge mode.

    There is a PR for some changes to this at https://github.com/espruino/BangleApps/p­ull/2473 but I wanted to take a bit of time to look into it before merging...

  • I'd have hoped you'd have seen messages like t: "gps_power", status: true}

    Yes i saw that in the log.

    The frustrating thing is that when disconnected, it should work as normal - but the second you connect to see what's going on it would switch to the Gadgetbridge mode.

    That would explain why it worked sometimes but most of the times not.

    There is a PR for some changes to this

    I have seen that. Take your time :)

  • The PR does not fix the behaviour when the GB side is configured not to provide GPS events. At least not yet. Can we check if a GB setting is set? Then it would be easy to integrate a check and prevent this situation. If we can not check the settings, maybe the app should send it's GPS setting state to the bangle when the gps_power message arrives?

  • Maybe we should turn the GPS on by default, report it to Gadgetbridge, and then on the very first GPS event we get from Gadgetbridge turn it off and switch to Gadgetbridge GPS?

    That way if for any reason at all Gadgetbridge isn't providing info, the GPS still works?

  • That seems to be a valid compromise. We could just switch on the first Gadgetbridge GPS event, keep time until the next arrive to get the configured timeout and then set a timeout slightly longer to re-enable builtin GPS. That way no handling of connection events would be necessary and no internal keeping of state besides the expected time to next Gadgetbridge GPS event. Maybe even communicate the configured interval duration in the first or all GPS events to make this easier to do on the bangle.

  • We could just switch on the first Gadgetbridge GPS event, keep time until the next arrive to get the configured timeout and then set a timeout slightly longer to re-enable builtin GPS.

    That sounds great! I'm not sure how often the phone pushes GPS updates, but I'd say that maybe even just a hard-coded 5-10s timeout would be fine.

  • Default in Gadgetbridge is currently 10s, but since that is configurable, we must handle even longer pauses between events. Should be easy by just storing the time between two events and just ignoring the case where the user changes Gadgetbridge config to a significantly higher value while phone GPS is used.

  • Ahh, that's interesting! I guess ideally Gadgetbridge would be pushing updates once a second, as when the GPS is actually on the power usage between 1s and 10s will be minimal, and Bangle.js apps may be expecting a 1s update

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

B2: GPS/GNSS not working anymore

Posted by Avatar for myxor @myxor

Actions