Giter Club home page Giter Club logo

ttblue's Introduction

Build Status

Table of Contents

Introduction

The TomTom Multi-Sport and Runner are nice GPS watches and quite affordable, but they suffer from subpar official software. There is no official desktop app for interfacing wirelessly with the TomTom GPS watches, (only for Android and iPhone).

Now you can use ttblue to download your activites wirelessly and keep the QuickFix GPS ephemeris data up-to-date.

Building

Requirements

You need to be running a recent Linux kernel, with a Bluetooth 4.0 adapter supporting Bluetooth Low Energy. Many newer PCs include built in Bluetooth 4.0 adapters; if you need one, I've had good success with this $6 dongle, which works out-of-the-box with the btusb driver from recent Linux kernels.

The libbluetooth (BlueZ), libcurl, and popt libraries are required. On Debian/Ubuntu-based systems, these can be installed with:

$ sudo apt-get install libbluetooth-dev libcurl4-gnutls-dev libpopt-dev

Compiling

Compilation with gcc should be straightforward:

$ make
$ make setcap # requires sudo/root access

To fix the issue with very slow file transfers, the most secure solution I've been able to come up with so far is to give the binary elevated capabilities as discussed on StackExchange: make setcap will do this automatically or you can do it manually as follows:

sudo setcap 'cap_net_raw,cap_net_admin+eip' ttblue

(Note that this is more secure than giving the binary setuid root permissions, because it only allows root-like privileges for these specific capabilities.)

Use it

For initial pairing, you'll need to go to the Phone|Pair New menu on the watch.

For subsequent reconnection, ensure that Phone|Sync is enabled, and you may need to "wake up" the device's BLE radio by pressing a few buttons.

Try the following command line:

./ttblue -a [-d <bluetooth-address>] [-c <pairing-code>] [-s <activity-store>]
  • bluetooth-address is the MAC address of your TomTom GPS watch, for example E4:04:39:17:62:B1. If not specified, ttblue will attempt to scan for BLE devices, and try to connect to the first one matching TomTom's vendor ID (E4:04:39).

  • The pairing-code is a previously-used pairing code (can be from one of the "official" TomTom mobile apps). If left blank, ttblue will try to create a new pairing.

  • The -a/--auto option tells ttblue to download all activities and update QuickFixGPS.

  • The -s/--activity-store option specifies a location for .ttbin activity files to be output (current directory is the default).

As invoked above, ttblue will download your activity files (saved as 0091000n_YYYYMMDD_HHmmSS.ttbin), and attempt to download the QuickGPSFix update and send it to the watch. (You can then use ttbincnv to convert the TTBIN files to GPX/TCX format.)

$ ./ttblue -a -d E4:04:39:17:62:B1 -c 123456
Opening L2CAP LE connection on ATT channel:
	 src: 00:00:00:00:00:00
	dest: E4:04:39:17:62:B1
Connected to HC4354G00150.
  maker     : TomTom Fitness
  serial    : HC4354G00150
  user_name : Lenski
  model_name: Runner
  model_num : 1001
  firmware  : 1.8.42
  rssi      : -90 dB
Setting PHONE menu to 'dlenski-ultra-0'.
Found 1 activity files on watch.
  Reading activity file 00910000 ...
11: read 55000 bytes from watch (1807/sec)
    Saved 55000 bytes to ./00910000_20150801_123616.ttbin
    Deleting activity file 00910000 ...
Updating QuickFixGPS...
  Last update was at at Sat Aug 1 04:11:03 2015.
  Downloading http://gpsquickfix.services.tomtom.com/fitness/sifgps.f2p3enc.ee?timestamp=1439172006
  Sending update to watch (32150 bytes)...
7: wrote 32150 bytes to watch (1891/sec)

There's also a fairly rudimentary "daemon" mode wherein ttblue just loops over and over (by default it waits an hour to retry after a successful connection, but only 10 seconds after a failed one), and a -p/--post option to specify a command to be run on each successfully downloaded .ttbin file (see ttbin2strava.sh) for an example):

$ ./ttblue -a --daemon -d e4:04:39:17:62:b1 -c 123456 -s ~/ttbin -p ttbin2strava.sh

Why so slow?

By default, Linux (as of 3.19.0) specifies a very intermittent connection interval for BLE devices. This makes sense for things like beacons and thermometers, but it is bad for devices that use BLE to transfer large files because the transfer rate is directly limited by the BLE connection interval.

If you run as root or if you give the ttblue binary elevated capabilities, it will attempt to set the minimum connection interval (7.5 ms) and activity file downloads will proceed much faster (about 1800 B/s vs. 500 B/s for me).

Unfortunately, elevated permissions are required to configure this feature of a BLE connection. For gory details, see this thread on the BlueZ mailing list.

TODO

  • More command line options?
  • Real config file?
  • Better daemon mode that actually puts itself in the background and writes output to a log file?
  • Integrate with ttwatch which already does all these things, but over USB?

Protocol documentation

See tt_bluetooth.md for reverse-engineered protocol documentation.

Credits

@ryanbinns did a lot of the heavy lifting by writing his excellent ttwatch utility to sync with TomTom GPS watches over USB, and in the process documenting the ttbin binary format of the activity files, as well as many of the internal data structures of the units.

@Grimler91 for adding support for TomTom GPS watches using the "v2" protocol. (Spark, Runner v2, etc.)

License

I'd like to license it as GPLv3 or later, but it uses snippets from the BlueZ source which are GPLv2 so... let's call it GPLv2 or later?

By Dan Lenski <[email protected]> © 2015

ttblue's People

Contributors

dlenski avatar grimler91 avatar wcbonner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ttblue's Issues

Failed to set BLE scan parameters: Input/output error (5)

Hello Dan,

Since TomTom stopped support, I am using the USB tool from https://github.com/scubajorgen/TomTomWatch. And I wanted to try out your app, it looks very promising as it may provide the more user friendly bluetooth functionality (and my USB connection is not that stable anymore).

When I follow your instructions, I encounter the following error. Did something get broken over time maybe? Or is the app still working for you and is something wrong on my system configuration?

user@ubuntu:~/ttblue$ ./ttblue -a -d E4:04:39:77:A8:46 
****************************************************************
Please put device in pairing mode (MENU -> PHONE -> PAIR NEW)...
****************************************************************
Press Enter to continue: 

Scanning for TomTom BLE device E4:04:39:77:A8:46...
Failed to set BLE scan parameters: Input/output error (5)
BLE scan failed: Input/output error (5)
Fatal error, exiting.

Thanks for doing all this work already, I really hope I will be able to use it in the end!

Best regards,
Thomas

Requirements for data retrieval via android app?

This is more a query than an issue....hope you don't mind

I don't use the mysports site, but being able to retrieve the ttbin files is useful. From a desktop I can use ttwatch to extract them over USB and upload to strava, but over bluetooth & android I currently have a problem:

When I try to retrieve data from my watch via the android app, it complains that it is not linked to a mysports account, and at that point gives up on retrieval of a ttbin file.

I have checked, and the app comes to this conclusion even in the absence of any internet connection. So my assumption is that it must base this conclusion on the contents (or lack thereof) of the preferences file 0x000f2000 ....

Can you shed any light on this...? I don't suppose you have any plans in the pipeline for a basic "connect, download data, disconnect" android release :-)

v2 devices don't work with firmware v1.20

@drkingpo's device was working with the v2_devices branch and firmware v1.19, but after firmware v1.20 upgrade it hangs at the end of downloading a ~72KiB activity file.

Possible timing issue? Maybe the device is just slow to output the success message after download is completed?

Failing to write QuickFixGPS (file size?)

@weechatter alerted me to this issue. On August 26-27, ttblue is failing to write QuickFixGPS file that is 0x7970 bytes long.

$ ttblue -D -D # packet-by-packet output for file writing
...
7948: c2b375d30eceeca039ed35c5000001be0807262b
795c: 10890cb420d00c6700e3e20d0f440b4100000020
at file position 0x7970
fail: Resource temporarily unavailable
Failed to send QuickFixGPS update to watch.
Opening L2CAP LE connection on ATT channel:
     src: 20:16:D8:CE:76:9B
    dest: E4:04:39:17:62:B1

tt_reboot doesn't work anymore

tt_reboot currently doesn't work for either watch version.
How did it work before? Sending lots of zeros causes device to freeze and reboot?

First error is

Rebooting watch...
Expected ATT WRITE response opcode (0x13) but received 0x1b

Looking at the bluetooth traffic I can see that this happens because the watch sends both a 0x13 and a 0x1b, i.e. traffic is something like

25 <-- 00 00 00 00 (write req)
25 ->  00 13           (write response)
25 ->  00 00 00 00 (value notification handle (0x1b))

And when we flood the device the order is messed up which causes this error:

25 <-- 00 00 00 00 (write req)
25 ->  00 13           (write response)
25 <-- 00 00 00 00 (write req)
25 ->  00 00 00 00 (0x1b)

I tried fixing this by using write instead of wrreq and to change so that wrreq allows 0x1b as response but I haven't been able to cause a reboot, it doesn't seem to be possible in the same way anymore.

Does combined version work for v2 devices?

I've combined the v1 and v2 device support together. It's working just fine for me on my v1 device, but I'd like to get some feedback as to whether the new version works on v2 devices as well.

Besides heavily reorganizing the code, I made some changes to the scanning procedure which make for more reliable connection with the v1 devices.

Please let me know if the combined branch works for anyone with a v2 device!

/cc @drkingpo, @wsxarcher, @mplusband

invalid numeric value

Hi, I want to thank you for this, even if I didn't manage to have it run so far.

I manage to pair to a Spark 3 watch but when I want to update the GPS with

./ttblue -d E4:04:39:82:7E:A0 --code=093203 --update-gps

I get the error

--code=093203: invalid numeric value

QuickFixGPS updates fail for some users

After fixing #1, QFG update still fails for at least one user, with errno of EAGAIN.

$ ttblue -D -D # show write packet-by-packet
...
Updating QuickFixGPS...
  Saved 72 bytes to 00020001_20150827_221935.bin
  Downloading http://gpsquickfix.services.tomtom.com/fitness/sifgps.f2p3enc.ee?timestamp=1440706775
  Sending update to watch (31088 bytes)...
0000: 62123307430407df081b00011a6ed6fa00000000
0014: 0000013c7cd00d03fffe3107fffb06bb06bb06bb
0028: 06bb06bb06bb06bb06bb06bb06bb06bb06bb06bb
003c: 06bb06bb06bb06bb06bb67b6462000000000ffff
...
13c4: 03670000000c138a080000190095ecd21d47564f
13d8: c00003bd841c553a4304c987c045f1f595000004
13ec: 16080cd3ce096d66e5662e106c00301af412df24
at file position 0x13fe
fail: Resource temporarily unavailable
Failed to send QuickFixGPS update to watch.

It seems that the forced 20 ms delay between packets in tt_write_file (ttops.c#L207-L212) is not sufficient for all devices, and I don't understand exactly how the Android app figures out the correct timing, though "trial-and-error like I'm doing" seems likely.

[Question] Phone/linux notifications

Hi, thanks for your work in this project.
Firmware update 1.6.26 (changelog) introduced the possibility of getting notifications from native mobile apps for some watches.

Have you looked into/considered looking into incorporating this feature into ttblue? I'm thinking that it would be interesting to be able to send notifications from linux to the watch (when I get a new mail, new calender event, or something).

I understand that it isn't trivial though, I might look into it more when I have some spare time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.