3

I just got a Bluetooth LE/Smart bathroom scales (Model Sanitas SBF 70). I can read data from it using the following command:

gatttool --device=(btaddr) -I connect

Then when I stand on it, I get multiple notification messages like this: "Notification handle = 0x002e value: e7 58 01 05 e9" where the last two bytes are is the mass in 50g increments.

I'd like to integrate this into a few application using a TCP or UDP socket service that broadcasts these messages to any listening clients.

But after some research I have no idea what's the best way to stay connected all the time (the connection times out after a few minutes). Or alternatively to be able to re-establish a connection when the scales is used (I notice lots of activity from 'hcitool lescan' whenever someone steps on the scales).

I don't care what language / library is used. If I can push this to a TCP/UDP socket it will be trivial for other applications to consume the information.

jdesbonnet
  • 251
  • 3
  • 7
  • This is a pretty broad question. Shouldn't you get your basic connect and data reading code working first before worrying about staying connected for longer periods? If your question is really about the basic code to connect to the device, read data and push it out an IP socket then perhaps ask that instead. – kaylum Oct 07 '15 at 22:32

1 Answers1

1

The answer is straightforward: You don't. Your scale is most likely battery powered. Therefore the Bluetooth communications will only be enabled for a short period of time after having measured your weight. Your application just needs to try connecting to the scale over and over (catch any "unable to connect timeouts") until you step on it. And when connected get the data from it before BLE is shut down again. In pseudo code:

while true:
  while not_connected:
    try to connect
  receive notifications
  disconnect

gatttool wrapped by the python module pygatt is perfectly usable to solve this chalenge.
In my case scale data (preceding 30 weights) is transferred after enabling indications of 3 different characteristics.

Keptenkurk
  • 81
  • 4
  • You might want to check [this question](http://stackoverflow.com/questions/34271217/solved-connecting-to-a-bluetooth-smart-le-weight-scale-with-bluez-bluetoothctl-g/34559392#34559392) – Keptenkurk Jan 23 '16 at 22:36
  • My concern about this approach is that it will exhaust the battery in a short time. Whenever I try to connect: it succeeds. But when I passively look at bluetooth traffic (without transmitting or interacting with the scales) I see lots of packets being transmitted by the scales when I stand on it. So I was thinking something like: passively monitor bluetooth interface for any packets from scales MAC address. If detected, then (and only then) attempt to connect. – jdesbonnet Jan 24 '16 at 02:45
  • That's way different from the way my BS440 scale works. The pygatt module also wraps hcitool lescan. So code like: adapter = pygatt.backends.GATTToolBackend() // adapter.start() // adapter.scan() and only connect when the scale appears to be active. Would be interesting to know what the activity is you see with hcitool lescan when stepping on the scale. – Keptenkurk Jan 26 '16 at 18:33