openambitproject / openambit

openambit
277 stars 82 forks source link

Support for Suunto Spartan models #232

Open panumaijala opened 4 years ago

panumaijala commented 4 years ago

@vascotenner: You asked if I could open a new issue for Spartan models. Here it is. Please find some USB capture files attached (for Wireshark). There is a README file included. BR, panu

SuuntoSpartanSuuntoLinkCaptures.zip

Gerold-R commented 4 years ago

Hi Panu,

I just had a quit look into your capture files but it seems that that the protocol is completly different. I don't have a Spartan and I even don't know if they are still USB HID devices or a driver is needed.

All I know for now is, that SuuntoLink seems to be build with node.js and electron, the communication goes through tcp websocket.

With the "Browser WebSocket Client" addon for Firefox, you can connect to "SDSApplicationServer. exe" from a SuuntoLink subfolder. No need to start "SuuntoLink.exe", only "SDSApplicationServer. exe". Than enter the server URL: ws://localhost:9002 9002 is the default port, but you can define another one as parameter when you start the exe file. Press the "Connect" button to connect to "SDSApplicationServer. exe".

Because SuuntoLink works with the Ambit Kailash, I can also use it with my Ambit 2S. To read the battery level from my connected Ambit 2S, I send the message

{"Type":"Request","Method":"GET","Uri":"suunto://29AE095103001800/Dev/Battery/Level","Body":"","RequestId":260}

And I get

{ "RequestId": 260, "Method": "GET", "Type": "Response", "Status": 200, "TaskId": 40, "Reason": "OK", "Content-Type": "application/json", "Content-Length": 14, "Uri": "suunto://29AE095103001800/Dev/Battery/Level", "Body": { "Level": 100 } }

If you want to test it with your Spartan, replace the SN or send another message like:

{"Type":"Request","Method":"GET","Uri":"suunto://SDS/ConnectedDevices","Body":"","RequestId":259}

All the log files from SuuntoLink are very verbose and helpfull. Maybe you can publish these files too together with the capture files.

Because Suunto use node.js and electron, maybe they plan a UI for Linux too. Not sure if "SDSApplicationServer. exe" runs under Wine or Crossover. Will test it later.

Gerold

Gerold-R commented 4 years ago

"SDSApplicationServer. exe" is running using Wine 4.12.1 (Mint 19.1) and I am able to request data from my Ambit 2S. On the other hand, "SuuntoLink.exe" is not starting. Probably the same problem as with Moveslink: they use the Internet Explorer ActiveX.

panumaijala commented 4 years ago

Hi Gerold, my trials to run SDSApplicationServer.exe ended due to too many missing libraries (14 .dll files). I just wonder, if it was worth of trying to implement a method to automatically download the watch data in Linux using this SDS executable through a websocket client, e.g. https://pypi.org/project/websocket_client/ ? I don't have too much experience, written only small Python apps earlier... Of course, first those Uris and RequestIds of the watch should be found.
If the data could be downloaded to a Dropbox folder, it could be easily synchronized to cloud servers, like Endomondo, Sportstracker etc.. and this all automatically just by plugging the watch in your linux computer (done this for years with my old, different brand, watches). panu

Gerold-R commented 4 years ago

Hi Panu,

why do you have missing DLL's? I never installed SuuntoLink, just downloaded the SuuntoLink installer from here: https://www.suunto.com/en-gb/Support/software-support/suuntolink/ and extracted the EXE with 7-Zip. Than you will have an "nupkg" file. Extract this file and in the subfolder ...Suuntolink_installer\Suuntolink-2.24.3-full\lib\net45\resources\app you have the file "SDSApplicationServer.exe". I could start this file with WINE 4.12.1 on Linux Mint or on Windows of course. No missing DLL's.

Maybe it's not needed to download any data from the watch. I have written my own GUI for Linux which uses one DLL that comes with MovesLink to sync my Ambit 2S on Linux. Of course I need WINE but never needed to analyze the USB protocol. Just used the exported functions from the DLL to sync the watch. And thats what I would to if I would have a Spartan.

Use RawCap to capture the traffic on localhost and Wireshark to view the captured file. You will find the WebSocket request to sync the watch. I already synced my Ambit 2S using SuuntoLink with MovesCount and friends synced their Ambit 3 models successfully with SuuntoLink. I guess for the Spartan models, the commands are similar. Also have a look at all the different LOG files from SuuntoLink. And if you want more details in the LOG files, set the debug level to LOG_LEVEL_TRACE. This debug level also exists in Moveslink. Much more difficult to set, but was very usefull while developping my own GUI.

SuuntoLink creates for the Ambit models SML files like MovesLink. Dont know if this is the case for Spartan models (if yes, could you upload such a file?) There exists a Python script to convert to GPX and a friend of me and myself have written a Windows program (runs on Linux with Wine) to convert to GPX and TCX. I'll upload it on my Google Drive account here: https://drive.google.com/drive/folders/1sZ6sIlQVfwEbOjtQXO3PJJ7PtMy2wTQe

When I got more time, I will send the sync command via WebSocket to my Ambit 2S and see and wait what happens.

Gerold

panumaijala commented 4 years ago

Hi Gerold! No more missing dlls after installing .NET 4.5 to wine! Now I can start the SDSApplicationServer.exe under wine 3.0 (contains hid support) and connect to it using the Browser WebSocket Client - but, apparently, it cannot find the watch. Because SDSApplicationsServer tries to find it first as a UsbHidHost(), then using the addresses listed in Devices.xml, I've also tried: sudo chmod 666 /dev/hidraw* wine cmd net start winebus SDSApplicationServer.exe No success so far... panu BTW. Thanks for this tip too, there's a lot of information in the log files. The commands in suuntoapp.log look similar to what you suggested above.

Gerold-R commented 4 years ago

Hi Panu,

realy strange that you needed to install .NET 4.5 as for me it seems that all the .NET 4.5 DLL's are in the nupkg file and that even more than ones! Do you know the names of the missing DLL files?

Dont know anymore with WINE 3.0. They added HID Support first in WINE 2.x (dont remember the exact version number anymore) and it worked perfectly. Than they changed something and it did not work anymore. I reported this problem several times since I found the bug in WINE 3.x (not sure about the exact version: 3.0.3 was working and 3.17 not, that's all I remember). The bug could be finally resolved in WINE 4.6. But there is another thing to take care of. See also WineHQ Bugzilla: https://bugs.winehq.org/show_bug.cgi?id=46711 Read comment #4 and change the Windows registry entry. Per default, SDL is enabled and you must disable it to detect the watch. At least for an Ambit model. As I said before, I dont know if Spartan models are HID devices or not.

I guess it is possible to write a Python script to sync your Spartan using WebSocket. No need to analyze the Spartan protocol. Using WebSocket, you can create eventlisteners and the SDS AS will inform you, when a watch is connected or how many % from an exercise is downloaded from the watch. In fact the behavior is exactly the same as with Moveslink.

Example: Create eventlisteners that informs you when a watch is detected. This works also in a browser like Firefox using a WebSocket add-on

Send these two commands:

{"Type":"Request","Method":"POST","Uri":"suunto://SDS/EventListener","Body":{"Uri":"SDS/ConnectedDevices"},"RequestId":255}

{"Type":"Request","Method":"POST","Uri":"suunto://SDS/EventListener","Body":{"Uri":"SDS/ConnectingDevices"},"RequestId":256}

You will get these answers:

{"RequestId":255,"Method":"POST","Type":"Response","Status": 200, "TaskId": 38, "Reason": "OK", "Content-Length": 0, "Uri": "suunto://SDS/EventListener", "Location": "SDS/EventListener/38","Body":""}

{"RequestId":256,"Method":"POST","Type":"Response","Status": 200, "TaskId": 39, "Reason": "OK", "Content-Length": 0, "Uri": "suunto://SDS/EventListener", "Location": "SDS/EventListener/39","Body":""}

Now connect your watch (in my case an Ambit 2S) and you will receive messages that shows you information about the connected watch. Using the DLL that comes with Moveslink, it was exactly the same just via CallBacks from the DLL.

So writing an application to support Spartan on Linux should be very easy with the SDS AS running under WINE or CrossOver (I prefer).

vascotenner commented 4 years ago

If you want to install older versions of wine, play on linux has all machinery in place to install different versions of wine for different applications: https://www.playonlinux.com/en/

panumaijala commented 4 years ago

Gerold, before installing .NET 4.5, SDS server was complaining about following 14 missing DLLs:

I tried the commands, that you suggested above, in Ubuntu 18.04 & wine 3.0:
../AppData/Local/Suuntolink/app-2.24.3/resources/app$ wine SDSApplicationServer.exe % in an other window, the same directory $ tail -f suuntoapp.log
% -> Browser WebSocket Client -> Connect
% and sending (watch connected) {"Type":"Request","Method":"POST","Uri":"suunto://SDS/EventListener","Body":{"Uri":"SDS/ConnectedDevices"},"RequestId":255}
----suuntoapp.log--------->
[2019-Jul-30 16:43:28 +0300] [DEBUG] [SDS AS] "connection 1"
[2019-Jul-30 16:43:34 +0300] [DEBUG] [SDS AS] "uri: suunto://SDS/EventListener"
[2019-Jul-30 16:43:34 +0300] [DEBUG] [SDS AS] "contract: {"Uri":"SDS/ConnectingDevices"}"
[2019-Jul-30 16:43:34 +0300] [DEBUG] [SDS AS] "type: Request"
[2019-Jul-30 16:43:34 +0300] [DEBUG] [SDS AS] "calling SDS post()..."
[2019-Jul-30 16:43:34 +0300] [INFO] [SDS REQUEST] type: POST uri: suunto://SDS/EventListener contract: {"Uri":"SDS/ConnectingDevices"}
[2019-Jul-30 16:43:34 +0300] [DEBUG] [SDS AS] "SDS task id: 38"
[2019-Jul-30 16:43:34 +0300] [INFO] Adding EventListener for path: SDS/ConnectingDevices
[2019-Jul-30 16:43:34 +0300] [INFO] [SDS RESPONSE] type: POST status: OK header: {"Status": 200, "TaskId": 38, "Reason": "OK", "Content-Length": 0, "Uri": "suunto://SDS/EventListener", "Location": "SDS/EventListener/38"}
[2019-Jul-30 16:43:34 +0300] [DEBUG] [SDS AS] "type: Response, id=38, header: {"Status": 200, "TaskId": 38, "Reason": "OK", "Content-Length": 0, "Uri": "suunto://SDS/EventListener", "Location": "SDS/EventListener/38"}"
[2019-Jul-30 16:43:34 +0300] [DEBUG] [SDS AS] "uri SDS/EventListener/38 added to book-keeping"
[2019-Jul-30 16:43:34 +0300] [DEBUG] [SDS AS] "{"RequestId":255,"Method":"POST","Type":"Response","Status": 200, "TaskId": 38, "Reason": "OK", "Content-Length": 0, "Uri": "suunto://SDS/EventListener", "Location": "SDS/EventListener/38","Body":""}"
[2019-Jul-30 16:43:34 +0300] [DEBUG] [SDS AS] "validation against schema: ok"

<---------suuntoapp.log---------

Yes, Spartan looks like a HID device, but I cannot get wine to understand it - please have look at the attached suuntoapp.log from a win10 installation: one sync without new data in the watch.

panu

suuntoapp.zip

Gerold-R commented 4 years ago

@panumaijala All these DLL's are inside the file Suunto_Installer.exe from Suunto homepage. To be more exact in the nupkg file that you get after extrating the EXE. As I said, I never installed .NET 4.5 runtime on my Linux Mint 19.1 Cinnamon 64-Bit

SuuntoLink.exe does not work correctly using Wine on Linux but it starts SDSApplicationServer.exe, just with another port 9701 as parameter and overwriting the default port 9002. I have 2 suuntoapp.log files. One created by the SuuntoLink.exe and the other from SDSApplicationServer.exe.

Could you try with Wine 4.12.1? You could use PlayOnLinux. The latest CrossOver beta is also using Wine 4.12.1

Is the Spartan detected using my testprogram if have written for WineHQ? https://bugs.winehq.org/attachment.cgi?id=64043&action=edit

nasichassoulas commented 4 years ago

Hi all,

Not sure if its appropriate to follow on this thread, but I am looking for support for a Suunto Spartan watch. The .fit file seems to import swim sessions I have available perfectly, other than for the lack of any GPS data (assumed from the fact that the Track tab states "No track data available".

I am willing to do any testing or provide .fit files for testing. The Suunto API guide:

https://apizone.suunto.com/fit-description

On Linux, GPXSee opens the .fit file perfectly, showing map and route.

Thanks in advance!

carlosedsferreira commented 3 years ago

Hi,

I have a Suunto Spartan and I was able to connect to "SDSApplicationServer. exe" and get the connected devices. I'm trying to test the other messages in order to read the logbook and if possible change a flag to re-sync an activity from the watch to suunto app again. Can you please help me? I can't send any other messages with success. Even for the battery level.

marguslt commented 3 years ago

and if possible change a flag to re-sync an activity from the watch to suunto app again.

Are you sure sync flag manipulation is actually needed? At least for Ambit3, Suunto App does not set sync flags in watch itself nor cares about previous sync flag states. Meaning that app reads all those activities it doesn't have a record for. So all you have to do for re-syncing a deleted activity is to clear app data or re-install it, at least on Android.

carlosedsferreira commented 3 years ago

That's right @marguslt :man_facepalming: I lost a lot of time before discover that... my bad. But it was a good investigation time that I spent. I was able to find some interesting endpoints for Spartan watch.