Integration of Medisana BS440 Connected scale

In this subforum you can show projects you have made, or you are busy with. Please create your own topic.
domdomgo
Posts: 4
Joined: Thursday 29 December 2016 23:47
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by domdomgo » Sunday 01 January 2017 20:44

Ok so I'm testing the script on Synology now but I get the following results, the BS440 is found, the scripts tries to connect but thats it. No data seems to be transferred as the connection is not initiated.

I have all the tools running as root for testing.

Log file produces the following data:

Sun, 01 Jan 2017 19:40:33 INFO scan Starting BLE scan
Sun, 01 Jan 2017 19:40:33 ERROR scan Unexpected error when scanning
Sun, 01 Jan 2017 19:40:34 INFO scan Starting BLE scan
Sun, 01 Jan 2017 19:40:44 INFO scan Discovered C8:34:73:58:E0:79 (0202B679E0587334C8)
Sun, 01 Jan 2017 19:40:44 INFO scan Found 1 BLE devices
Sun, 01 Jan 2017 19:40:44 INFO connect Connecting to C8:34:73:58:E0:79 with timeout=5
Sun, 01 Jan 2017 19:40:49 ERROR connect Timed out connecting to C8:34:73:58:E0:79 after 5 seconds.
Sun, 01 Jan 2017 19:40:49 INFO connect Connecting to C8:34:73:58:E0:79 with timeout=5
Sun, 01 Jan 2017 19:40:54 ERROR connect Timed out connecting to C8:34:73:58:E0:79 after 5 seconds.
Sun, 01 Jan 2017 19:40:54 INFO connect Connecting to C8:34:73:58:E0:79 with timeout=5
Sun, 01 Jan 2017 19:40:59 ERROR connect Timed out connecting to C8:34:73:58:E0:79 after 5 seconds.
Sun, 01 Jan 2017 19:40:59 INFO scan Starting BLE scan
Sun, 01 Jan 2017 19:41:00 ERROR scan Unexpected error when scanning
Sun, 01 Jan 2017 19:41:00 INFO scan Starting BLE scan
Sun, 01 Jan 2017 19:41:10 INFO scan Discovered C8:34:73:58:E0:79 (0202B679E0587334C8)
Sun, 01 Jan 2017 19:41:10 INFO scan Found 1 BLE devices
Sun, 01 Jan 2017 19:41:10 INFO connect Connecting to C8:34:73:58:E0:79 with timeout=5
Sun, 01 Jan 2017 19:41:15 ERROR connect Timed out connecting to C8:34:73:58:E0:79 after 5 seconds.
Sun, 01 Jan 2017 19:41:15 INFO connect Connecting to C8:34:73:58:E0:79 with timeout=5
Sun, 01 Jan 2017 19:41:20 ERROR connect Timed out connecting to C8:34:73:58:E0:79 after 5 seconds.
Sun, 01 Jan 2017 19:41:20 INFO connect Connecting to C8:34:73:58:E0:79 with timeout=5
Sun, 01 Jan 2017 19:41:25 ERROR connect Timed out connecting to C8:34:73:58:E0:79 after 5 seconds.
Sun, 01 Jan 2017 19:41:25 INFO scan Starting BLE scan
Sun, 01 Jan 2017 19:41:25 ERROR scan Unexpected error when scanning
Sun, 01 Jan 2017 19:41:26 INFO scan Starting BLE scan

And the console outputs the following for the BS440.py script

Can't init device hci0: Connection timed out (110)
Can't init device hci0: Connection timed out (110)
Can't init device hci0: Connection timed out (110)
Can't init device hci0: Connection timed out (110)

Update:

Got it all running again, the location of the Synology was causing BT reception/transmission errors. Solution was to move the transceiver to a more suitable position.

franzelare
Posts: 148
Joined: Thursday 19 February 2015 22:48
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by franzelare » Sunday 15 January 2017 22:19

Any clue if the blood pressure sensors of medisana are using same protocol?
Like the BU 530 connect?

franzelare
Posts: 148
Joined: Thursday 19 February 2015 22:48
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by franzelare » Saturday 28 January 2017 18:13

scarabee wrote:...
sudo gatttool -i hci0 -b D6:DC:42:2A:B9:A8 -I
connect
Error: connect error: Transport endpoint is not connected (107)

Any iddeaa what is going wrong?
I see the same happening....

Code: Select all

Sat, 28 Jan 2017 16:59:48 INFO     <module> BS440 Started
Sat, 28 Jan 2017 16:59:48 INFO     init_ble_mode hci0 Set Low Energy complete, settings: powered bondable ssp br/edr le 
Sat, 28 Jan 2017 16:59:48 DEBUG    start gatttool_cmd=gatttool -i hci0 -I
Sat, 28 Jan 2017 16:59:48 INFO     run Running...
Sat, 28 Jan 2017 16:59:48 INFO     scan Starting BLE scan
Sat, 28 Jan 2017 16:59:58 INFO     scan Discovered CB:3A:59:CB:75:A0 (0202B6A075CB593ACB)
Sat, 28 Jan 2017 16:59:58 INFO     scan Found 1 BLE devices
Sat, 28 Jan 2017 16:59:58 INFO     connect Connecting to CB:3A:59:CB:75:A0 with timeout=5
Sat, 28 Jan 2017 17:00:04 ERROR    connect Timed out connecting to CB:3A:59:CB:75:A0 after 5 seconds.
Sat, 28 Jan 2017 17:00:04 INFO     connect Connecting to CB:3A:59:CB:75:A0 with timeout=5
Sat, 28 Jan 2017 17:00:09 ERROR    connect Timed out connecting to CB:3A:59:CB:75:A0 after 5 seconds.
Sat, 28 Jan 2017 17:00:09 INFO     connect Connecting to CB:3A:59:CB:75:A0 with timeout=5
Sat, 28 Jan 2017 17:00:14 ERROR    connect Timed out connecting to CB:3A:59:CB:75:A0 after 5 seconds.
Keptenkurk wrote:Hi Scarabee,
1. Try running gatttool with the "random" option like:
sudo gatttool -i hci0 -t random -b D6:DC:42:2A:B9:A8 -I
that solves the issue when connecting manually... but how to make the python script do that?

trixwood
Posts: 510
Joined: Friday 18 March 2016 8:20
Target OS: -
Domoticz version: Offline
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by trixwood » Saturday 28 January 2017 18:40

You're manual run of gatttool doesn;t have a timeout.

https://github.com/keptenkurk/BS440/blo ... 440.py#L66

Change 5 to whatever timeout you think works... it seems 5 is to short for you distance to you device...

Hope that helps/works :-)

franzelare
Posts: 148
Joined: Thursday 19 February 2015 22:48
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by franzelare » Saturday 28 January 2017 19:44

trixwood wrote:You're manual run of gatttool doesn;t have a timeout.

https://github.com/keptenkurk/BS440/blo ... 440.py#L66

Change 5 to whatever timeout you think works... it seems 5 is to short for you distance to you device...

Hope that helps/works :-)
thanks! will give it a try later!

franzelare
Posts: 148
Joined: Thursday 19 February 2015 22:48
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by franzelare » Sunday 29 January 2017 14:40

still no luck on this side, gatttool from the command line connects when I add -t random..
added this to the line
adapter= pygatt.backends.GATTToolBackend(cli_options='-t random')
what gives me in the log file:
start gatttool_cmd=gatttool -t random -i hci0 -I

but still only getting timeouts when I try to run the script...

franzelare
Posts: 148
Joined: Thursday 19 February 2015 22:48
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by franzelare » Monday 30 January 2017 13:44

I think i found the issue... tried an other device that also works with gatttool but without -t random, that shows the same issue when connecting using pygatt.
looking in gattttool.py and reading a bit about other issues, by gatttool version likely returns a slightly different connect message than pygatt expects and is so not recognizing that the device is connected

franzelare
Posts: 148
Joined: Thursday 19 February 2015 22:48
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by franzelare » Sunday 12 February 2017 17:02

i did a full re-install of my test setup and now gatttool is reporting back to pygatt that the connection is established (without me editing the backend code)

I have the BS440 working, only issue now is in the BS440domoticz.py when a new person steps on the scale and is first reported to domoticz.
this piece of code makes the new person use the same id's as the previous person, since it always picks the default id's when the person is not yet listed in the config file...

Code: Select all

        # Mass
        weightid = get_realid('weight_id',79)
        fatmassid = get_realid('fat_mass_id',80)
        watermassid = get_realid('watermass_id',81)
        musclemassid = get_realid('muscle_mass_id',82)
        bonemassid = get_realid('bone_mass_id',83)
        lbmid = get_realid('lbm_id',84)
        weightunit = get_realid('weight_unit',1)
        fatmassunit = get_realid('fatmass_unit',1)
        watermassunit = get_realid('watermass_unit',1)
        musclemassunit = get_realid('musclemass_unit',1)
        bonemassunit = get_realid('bonemass_unit',1)
        lbmunit = get_realid('lbm_unit',1)
in order to solve this, the id's need to be created and requested on initial presentation, or unique id has to be in the code for every person id.
i decide to generate an id based on the preson id in the code as easy fix

Code: Select all

        # Mass
        personpref = 10 * (weightdata[0]['person'])

        weightid = get_realid('weight_id',(personpref))
        fatmassid = get_realid('fat_mass_id',(personpref+1))
        watermassid = get_realid('watermass_id',(personpref+2))
        musclemassid = get_realid('muscle_mass_id',(personpref+3))
        bonemassid = get_realid('bone_mass_id',(personpref+4))
        lbmid = get_realid('lbm_id',(personpref+5))
        weightunit = get_realid('weight_unit',1)
        fatmassunit = get_realid('fatmass_unit',1)
        watermassunit = get_realid('watermass_unit',1)
        musclemassunit = get_realid('musclemass_unit',1)
        bonemassunit = get_realid('bonemass_unit',1)
        lbmunit = get_realid('lbm_unit',1)

User avatar
remb0
Posts: 1002
Joined: Thursday 11 July 2013 22:21
Target OS: Raspberry Pi
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by remb0 » Sunday 05 March 2017 18:43

I updated bs440 scripts today and got an error, It worked before and I don't know whats's the fault.

Code: Select all

pi@Domoticz:~/domoticz/scripts/python/BS440 $ sudo python BS440test.py
Traceback (most recent call last):
  File "BS440test.py", line 60, in <module>
    mod = __import__(fname)
  File "plugins/BS440domoticz.py", line 75
    def self.exists_id(self, sensorid):
        
SyntaxError: invalid syntax
or:

Code: Select all

pi@Domoticz:~/domoticz/scripts/python/BS440 $ sudo python BS440.py
Traceback (most recent call last):
  File "BS440.py", line 112, in <module>
    mod = __import__(fname)
  File "plugins/BS440domoticz.py", line 75
    def self.exists_id(self, sensorid):
            ^
SyntaxError: invalid syntax
Can't see it...

Cornholio1234
Posts: 29
Joined: Thursday 03 March 2016 12:01
Target OS: Windows
Domoticz version: V3.4964
Location: Germany
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by Cornholio1234 » Friday 17 March 2017 9:24

I am not really into python but I assume its just a typo. Remove the self in the method declaration in line 75 and see what happens ;-)
Windows Server, Aeotec Z-Stick Gen5, V3.4964

woodtrix
Posts: 37
Joined: Saturday 18 February 2017 18:54
Target OS: -
Domoticz version:
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by woodtrix » Friday 17 March 2017 13:02

Yup, typo in the new plugin system :-) The code is probably untested.

Lots of development going on :-) way cool! I haven't looked into into this for a couple of months. And now it has a Runalyze plugin and a webapp :o :shock:

Definitely going to play with that, tonight.

(fix remove "self.")

woodtrix
Posts: 37
Joined: Saturday 18 February 2017 18:54
Target OS: -
Domoticz version:
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by woodtrix » Friday 17 March 2017 13:05

Also wondering has anyone played with other medisane bluetooth products?

franzelare
Posts: 148
Joined: Thursday 19 February 2015 22:48
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by franzelare » Friday 17 March 2017 14:15

woodtrix wrote:Also wondering has anyone played with other medisane bluetooth products?
yes, also got a blood pressure sensor attached to domoticz. (BU530)
was fairly easy based on the explanation about the scale, only had to extend the script to detect both devices.
only issue is that you have to wait a bit after using one device to complete the data transfer and processing before you use the next device

User avatar
Keptenkurk
Posts: 440
Joined: Wednesday 21 August 2013 17:24
Target OS: -
Domoticz version:
Location: Waalre, The Netherlands
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by Keptenkurk » Friday 17 March 2017 19:01

The code is probably untested
You are right :oops: Didn't test that... sorry for the inconvenience. Planned to set up a separate Domoticz to play/test with but then we started to renovate our entire bathroom :(
Consider the typo fixed (still untested though)

kman
Posts: 165
Joined: Wednesday 30 September 2015 19:33
Target OS: Linux
Domoticz version:
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by kman » Tuesday 04 April 2017 19:35

Hello,
As I haven't used virtual sensors before, please could you confirm on updating the "virtual sensors" (as done here with weighing scale) is the data is available to be sent via http_post ("setup->more options -> data push -> http") ?

Many thanks.

kman
Posts: 165
Joined: Wednesday 30 September 2015 19:33
Target OS: Linux
Domoticz version:
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by kman » Tuesday 04 April 2017 21:15

@Keptenkurk
In the latest release at https://github.com/keptenkurk/BS440/releases I don't find config related to domoticz that is required for BS440domoticz.py i.e. there is no file called "BS440domoticz.ini" --- nor --- "the config for domoticz in BS440.ini" -- which was present in release 1.

Please advise.

Thank you.

User avatar
Keptenkurk
Posts: 440
Joined: Wednesday 21 August 2013 17:24
Target OS: -
Domoticz version:
Location: Waalre, The Netherlands
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by Keptenkurk » Thursday 06 April 2017 21:49

kman wrote: ...is the data is available to be sent via http_post ("setup->more options -> data push -> http") ?
Actually, never seen that page before :D
No, you don't need to. If the Domoticz plugin works, it will check for the existence of the required virtual sensors. If they don't exist they will be crated automagically. This autocreation feature was added by @trixwood.
Then i decided to separate the data aquisition part from the data processing part because different people want to use the data differently.
So the data processing is taken care of by plugins. Any enabled plugin is presented the full dataset and uses it (by sending it through mail or updates database, or updates csv or updates Domoticz)

But the Domoticz plugin hasn't been tested yet (at least by me) after converting Trixwood's work to the plugin style. So might stil be broken. Really didn't find the chance to give it a go yet but certainly will.
/paul

User avatar
Keptenkurk
Posts: 440
Joined: Wednesday 21 August 2013 17:24
Target OS: -
Domoticz version:
Location: Waalre, The Netherlands
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by Keptenkurk » Friday 07 April 2017 0:12

kman wrote:In the latest release at https://github.com/keptenkurk/BS440/releases I don't find config related to domoticz that is required for BS440domoticz.py"
You're right. Added it on github. Still not tested but at least it now has a reasonable chance to work.
/paul

kman
Posts: 165
Joined: Wednesday 30 September 2015 19:33
Target OS: Linux
Domoticz version:
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by kman » Friday 07 April 2017 8:01

@Keptenkurk: Thanks for the responses and for BS440domoticz.py.

@trixwood: Hi, will the BLE data be available via virtual-sensors to be sent using http_post ("setup->more options -> data push -> http") ?

Many thanks.

kman
Posts: 165
Joined: Wednesday 30 September 2015 19:33
Target OS: Linux
Domoticz version:
Contact:

Re: Integration of Medisana BS440 Connected scale

Post by kman » Thursday 20 April 2017 11:54

@Keptenkurk:
A few quick questions - I am trying to get data out of a smart watch, your answers will be of great help.

1. Did you use some tool to capture the traffic between scale and phone before starting on python? Wireshark/btsnoop_hci.log? When I use the wireshark on my btsnoop_hci.log I don't see the char_write_cmd or char_write_req messages, and there are a lot of unknown messages.
wireshark_btsnoop_hci.jpg
btsnoop_hci.log in wireshark
wireshark_btsnoop_hci.jpg (106.06 KiB) Viewed 2621 times
(I see that you refer to Edmundo's work ) But some of your comments(below) on this site, gave me an impression that you had used few more tools to arrive at the exact sequence:
* Reading handle 0x21 serves no purpose in my experience
* Writing handle 0x23 with 02 followed by the unix timestamp syncs the RTC of the scale
* Use the multibyte modified pygatt (pull 34) to be able to receive multiple bytes in an Indication
*Although writing to 0x23 will not produce any Notification it is required to wait for a Notification to be able to receive the 0x1b and 0x1e Indications. When *the last Indication was received the NotificationTimeout exception is received
-------
Or, if you could just tell on how you arrived at the sequence mentioned in the above the quote, that would be a good pointer for me to proceed. Many thanks.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests