Integration of Medisana BS440 Connected scale
Moderator: leecollings
-
- Posts: 4
- Joined: Thursday 29 December 2016 22:47
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Integration of Medisana BS440 Connected scale
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.
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.
-
- Posts: 141
- Joined: Thursday 19 February 2015 21:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Integration of Medisana BS440 Connected scale
Any clue if the blood pressure sensors of medisana are using same protocol?
Like the BU 530 connect?
Like the BU 530 connect?
-
- Posts: 141
- Joined: Thursday 19 February 2015 21:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Integration of Medisana BS440 Connected scale
I see the same happening....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?
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.
that solves the issue when connecting manually... but how to make the python script do that?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
Re: Integration of Medisana BS440 Connected scale
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
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

-
- Posts: 141
- Joined: Thursday 19 February 2015 21:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Integration of Medisana BS440 Connected scale
thanks! will give it a try later!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
-
- Posts: 141
- Joined: Thursday 19 February 2015 21:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Integration of Medisana BS440 Connected scale
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...
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...
-
- Posts: 141
- Joined: Thursday 19 February 2015 21:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Integration of Medisana BS440 Connected scale
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
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
-
- Posts: 141
- Joined: Thursday 19 February 2015 21:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Integration of Medisana BS440 Connected scale
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...
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
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)
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)
- remb0
- Posts: 499
- Joined: Thursday 11 July 2013 22:21
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: The Netherlands
- Contact:
Re: Integration of Medisana BS440 Connected scale
I updated bs440 scripts today and got an error, It worked before and I don't know whats's the fault.
or:
Can't see it...
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
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
-
- Posts: 23
- Joined: Thursday 03 March 2016 11:01
- Target OS: Windows
- Domoticz version: V3.4964
- Location: Germany
- Contact:
Re: Integration of Medisana BS440 Connected scale
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
Re: Integration of Medisana BS440 Connected scale
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
Definitely going to play with that, tonight.
(fix remove "self.")

Lots of development going on



Definitely going to play with that, tonight.
(fix remove "self.")
Re: Integration of Medisana BS440 Connected scale
Also wondering has anyone played with other medisane bluetooth products?
-
- Posts: 141
- Joined: Thursday 19 February 2015 21:48
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Integration of Medisana BS440 Connected scale
yes, also got a blood pressure sensor attached to domoticz. (BU530)woodtrix wrote:Also wondering has anyone played with other medisane bluetooth products?
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
- Keptenkurk
- Posts: 103
- Joined: Wednesday 21 August 2013 17:24
- Target OS: -
- Domoticz version:
- Location: Waalre, The Netherlands
- Contact:
Re: Integration of Medisana BS440 Connected scale
You are rightThe code is probably untested


Consider the typo fixed (still untested though)
-
- Posts: 78
- Joined: Wednesday 30 September 2015 19:33
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Integration of Medisana BS440 Connected scale
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.
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.
-
- Posts: 78
- Joined: Wednesday 30 September 2015 19:33
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Integration of Medisana BS440 Connected scale
@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.
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.
- Keptenkurk
- Posts: 103
- Joined: Wednesday 21 August 2013 17:24
- Target OS: -
- Domoticz version:
- Location: Waalre, The Netherlands
- Contact:
Re: Integration of Medisana BS440 Connected scale
Actually, never seen that page beforekman wrote: ...is the data is available to be sent via http_post ("setup->more options -> data push -> http") ?

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
- Keptenkurk
- Posts: 103
- Joined: Wednesday 21 August 2013 17:24
- Target OS: -
- Domoticz version:
- Location: Waalre, The Netherlands
- Contact:
Re: Integration of Medisana BS440 Connected scale
You're right. Added it on github. Still not tested but at least it now has a reasonable chance to work.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"
/paul
-
- Posts: 78
- Joined: Wednesday 30 September 2015 19:33
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Integration of Medisana BS440 Connected scale
@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.
@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.
-
- Posts: 78
- Joined: Wednesday 30 September 2015 19:33
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Integration of Medisana BS440 Connected scale
@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. (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:
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.
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. (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.
Who is online
Users browsing this forum: No registered users and 1 guest