polar icon indicating copy to clipboard operation
polar copied to clipboard

gps alp file (suggestion)

Open ghost opened this issue 5 years ago • 10 comments

Hello, I have managed to use your code to get the data from a polar M400, and then successfully convert a training session into a gpx file and then upload it to Strava (btw, I tried first with a tcx but Strava did not like it.) This was done in Ubuntu 20.04. So many thanks for giving life back to my watch, which, not having any Windows or Mac, and not being able to make the Android app work, which is a total crap, was like a miracle.

So, I thought, now I can get rid of the app forever and do everything manually. But there is a remaining issue. The GPS rapidly loses precision unless you update the satellite data regularly (through the app, for example). I have done some research and inside my M400 the key file is /SYS/GPS/UBLOX.ALP

This file seems to be extracted from this address: https://alp.u-blox.com/ where, if I am not wrong, polar uses the 14 days file (the last one)

My suggestion is: wouldn't be ideal to be able to just grab the ALP file and directly put it in the watch memory? That would allow us to completely get rid of the app.

I have seen that the script polar_ftp can be followed by get or sync but not by put.

In the loophole site, https://github.com/rsc-dev/loophole, I have been playing with its cli and there is an (undocumented) command put_file, but I have not been able to successfully use it (yet).

I am not sure how plausible would be to have a script to grab the ALP file and use loophole or polar_ftp to put the file there and having an updated GPS data.

In my M400, the expiration of this GPS data can be checked with Settings -> General Settings -> About your product -> A-GPS exp.date

Thanks

ghost avatar Dec 28 '20 12:12 ghost

Hi,

Upload to the M400 should be doable.

@Antash did fork my code a while ago to add some support for upload. I never looked at this, but you may want to take a look yourself. Did you try to compare the UBLOX.ALP (structure, size...) file with what is provided on https://alp.u-blox.com/?

cmaion avatar Dec 30 '20 14:12 cmaion

Thanks, I will look into @Antash code.

Since ALP files are binary, I don't know how to compare them beyond seeing their size is really similar and some strings at the beginning are identical. I am not sure whether just uploading the alp file to the watch, renamed as UBLOX.ALP would work, but it would be worth trying.

Thanks for the answer.

ghost avatar Dec 31 '20 14:12 ghost

Worth trying indeed.

No idea how safe Antash upload code is, but feel free to report back if you give it a go!

cmaion avatar Dec 31 '20 15:12 cmaion

@al-al-physics hi, yes I made some progress with the Strava segments upload but I wasn't able to get it work. Polar does a lot of stuff during data sync and I wasn't able to fake this process completely so watch data remains consistent. You may check my code for some ideas and also I could elaborate it with you more.

Antash avatar Jan 01 '21 09:01 Antash

I have done two tests with my M400 so far:

  1. with both the original (cmaion) and the forked (Antash) I was able to sync the watch's content and then convert a training session into both tcx and gpx formats. Then I went to Strava and tried to manually upload them (click on the orange plus sign on top right and then select "file"). Strava did not like the tcx, saying it was empty. But it accepted the gpx. In fact, I have repeated this process with both codes for 3 trainings and the process is so flawless that I am planning to write a custom bash script to automate the whole thing. Thank you again to both for such an effort. Thanks to you I can use my watch again. I think the M400 is a good watch trapped in a creepy company.

  2. the second test concerns the GPS data, which according to Polar you need to renew at least each 14 days. The first days after an update the GPS precision is supposed to be very good and it gets worse as days pass. So without being able to update the GPS data we cannot get free from the app or the windows/mac software (I have only GNU/Linux and LineageOS without Google Play Store). As I said in the previous post, there is a binary file called UBLOX.ALP that is in /SYS/GPS/ and that is suspiciously the same binary file that https://alp.u-blox.com/ offers. In this website you can choose among different ALP files, with the 14 days being the longest available. I thought, if Polar is so lazy doing their app, will they tamper with such binary file. I wonder if they just take the alp file and use it as such. So thanks to Antash code I was able to remove the UBLOX.ALP file from the watch, then downloaded the new ALP file (the 14d) from the mentioned web, renamed as UBLOX.ALP, and then uploaded to the watch. After this, I went to the watch settings, general settings, about your product, and the expiration date written there had not changed from my last update with the app. But maybe such info will not update itself with our manual update of the alp file. The good news is that I went for a walk and the GPS worked perfectly. After that I converted to gpx and uploaded to Strava. The path I took is perfectly recognized. Two things can happen here (at least): a) the method works and updating manually the alp file solves our problem, or b) the watch is still using the old gps data somehow and is not reading the new alp file. The only way to discern between a) and b) is to continue using the updated file and see whether after a couple of weeks the gps data from my paths starts to become very unprecise. I will update after such time period.

On Fri, Jan 01, 2021 at 01:11:27AM -0800, Anton Ashmarin wrote:

@al-al-physics hi, yes I made some progress with the Strava segments upload but I wasn't able to get it work. Polar does a lot of stuff during data sync and I wasn't able to fake this process completely so watch data remains consistent. You may check my code for some ideas and also I could elaborate it with you more.

-- You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub: https://github.com/cmaion/polar/issues/26#issuecomment-753290287

ghost avatar Jan 01 '21 21:01 ghost

@al-al-physics cool, thanks for the update! The issue with the expiry date you see is something about data consistency that I was experiencing as well. Although it seems that put file operation works fine watch might ignore your changes and even consider them as a system failure. In my case it even force reset/restore itself. If you could try an additional test to download old gps file, than replace it with new one from the site, do a workout and then download the current gps file from the watch memory and compare it with those 2 files (old/site)

Antash avatar Jan 02 '21 07:01 Antash

Two results today:

  1. With the UBLOX.ALP from the site and put to the watch I did a workout. Pace reading were OK during the session. Then downloaded the training and converted to gpx. A weird thing happened: only half (approx) of theh session appears in the gpx. I uploaded this to Strava and this second half appears very OK, with correct paces, times, distances, locations... I have tested this with both forks of the code and same result. There is a weird mixture of events. My workout began at 17:19 and this shows in the gpx data. However, the GPS coordinates at this initial time are those of my already half of the workout. So somehow it has cropped half of the gps data but kept the initial time. I wonder whether there is some bug in the code. Unfortunately I don't know Ruby so I can't properly check. But I can help with tests. The watch still shows about one hour of training while the gpx only shows the last half hour (approx). To be more explanatory, for an abstract path that goes from 0 to 1 and then to 2:

What really happened:

initial time: 17:19 position 0 middle time: 17:50 position 1 final time: 18:20 position 2

What the gpx shows:

initial time: 17:19 position 1 final time: 17:50 position 2

  1. Regarding your suggestion, the ALP file uploaded yesterday had a size of 92K while downloading it today showed a size of 2K. Very weird. Perhaps I have done something wrong. I will repeat the experiment soon.

ghost avatar Jan 02 '21 18:01 ghost

@al-al-physics Feel free to share your training session files, I can take a look at the TCX & GPX output. You may also provide the corresponding TCX & GPX files as exported by Polar Flow. Generally speaking, the TCX export is more feature-rich than the GPX one and should be the preferred format (and Strava should have no trouble importing them).

@Antash regarding the upload protocol: did you capture USB packets from Polar Flow? The watch might need to be sent some kind of notification to ask it to check/apply updates (eg, START_SYNC, STOP_SYNC...?)

cmaion avatar Jan 03 '21 17:01 cmaion

@al-al-physics also, you may not need to update the UBLOX.ALP at all, as long as you regularly let your watch sync itself with the satellites (eg, leave it outside for a while with GPS on, before going on for your run/ride). From my understanding, this file is here to help acquiring a GPS lock, and reduce the time needed to do so, but it not strictly required. Don't take my words for granted, but that's also what the current fiasco with Sony chipset would infer (https://www.dcrainmaker.com/2021/01/gps-accuracy-impacting-devices.html)

cmaion avatar Jan 03 '21 17:01 cmaion

@cmaion I made attempt to sniff the sync workflow but wasn't able to determine any special commands polarsync sends.

Antash avatar Jan 03 '21 17:01 Antash