Use case: Connecting a bathroom body (fat) scale (e.g. Medisana BS440) via Bluetooth / MQTT to openHAB - Step by step instruction

Hello everyone,

Since I also have a Medisana body scale (BS430), I tried to set up a RaspberryPi following the instructions. Since I still had an old Raspberry Pi 1 at home, I tried it with this one. I gave the Pi a USB WiFi adapter and a USB Bluetooth 4.0 adapter. I then flashed a current Raspberry Pi OS 12 Lite 32-bit onto an SD card and used it to boot the Pi. The Pi recognized both the WiFi adapter and the Bluetooth adapter. So everything is ok up to this point.

In point 1.3 (Test the connectivity) I had to add the -t random parameter to the gattool command, otherwise I could not establish a connection to my scale. After that the connection worked.

In point 1.8 (Install Pygatt) I received the error message “externally-managed-environment” after executing the command sudo pip install “Pygatt[GATTTOOL]”. To fix this, I had to delete the EXTERNALLY-MANAGED file under /usr/lib/python3.11. The pip packages could then be installed.

But now I’m stuck on executing the Pythen script BS440.py. When I start the script interactively I get the following output:

root@bodyscalepi01:/opt/BS440# python BS440.py 
2024-03-29 14:18:25,774 INFO     <module> Configured plugins: BS440mqtt
2024-03-29 14:18:25,782 INFO     <module> Loading plugin: BS440mqtt
2024-03-29 14:18:27,415 INFO     <module> All plugins loaded.
2024-03-29 14:18:27,421 INFO     <module> BS440 Started
2024-03-29 14:18:27,604 INFO     init_ble_mode b'hci0 Set Low Energy complete, settings: powered ssp br/edr le secure-conn \n'

Nothing happens after that. When I then activate the scale, nothing is detected.

If I call journalctl -f in parallel in a second console window, I get the following log entries:

Mar 29 14:18:27 bodyscalepi01 sudo[2047]:     root : TTY=pts/0 ; PWD=/opt/BS440 ; USER=root ; COMMAND=/usr/bin/btmgmt le on
Mar 29 14:18:27 bodyscalepi01 sudo[2047]: pam_unix(sudo:session): session opened for user root(uid=0) by pi(uid=0)
Mar 29 14:18:27 bodyscalepi01 sudo[2047]: pam_unix(sudo:session): session closed for user root
Mar 29 14:18:27 bodyscalepi01 sudo[2050]:     root : TTY=pts/0 ; PWD=/opt/BS440 ; USER=root ; COMMAND=/usr/bin/systemctl restart bluetooth
Mar 29 14:18:27 bodyscalepi01 sudo[2050]: pam_unix(sudo:session): session opened for user root(uid=0) by pi(uid=0)
Mar 29 14:18:28 bodyscalepi01 systemd[1]: Stopping bluetooth.service - Bluetooth service...
Mar 29 14:18:28 bodyscalepi01 bluetoothd[2012]: Terminating
Mar 29 14:18:28 bodyscalepi01 bluetoothd[2012]: Stopping SDP server
Mar 29 14:18:28 bodyscalepi01 bluetoothd[2012]: Exit
Mar 29 14:18:28 bodyscalepi01 systemd[1]: bluetooth.service: Deactivated successfully.
Mar 29 14:18:28 bodyscalepi01 systemd[1]: Stopped bluetooth.service - Bluetooth service.
Mar 29 14:18:28 bodyscalepi01 systemd[1]: bthelper@hci0.service: Deactivated successfully.
Mar 29 14:18:28 bodyscalepi01 systemd[1]: Stopped bthelper@hci0.service - Raspberry Pi bluetooth helper.
Mar 29 14:18:28 bodyscalepi01 systemd[1]: Stopping bthelper@hci0.service - Raspberry Pi bluetooth helper...
Mar 29 14:18:28 bodyscalepi01 systemd[1]: hciuart.service - Configure Bluetooth Modems connected by UART was skipped because of an unmet condition check (ConditionFileNotEmpty=/proc/device-tree/soc/gpio@7e200000/bt_pins/brcm,pins).
Mar 29 14:18:28 bodyscalepi01 systemd[1]: Starting bthelper@hci0.service - Raspberry Pi bluetooth helper...
Mar 29 14:18:28 bodyscalepi01 bthelper[2056]: Not a UART-attached BT Modem
Mar 29 14:18:28 bodyscalepi01 systemd[1]: Finished bthelper@hci0.service - Raspberry Pi bluetooth helper.
Mar 29 14:18:28 bodyscalepi01 (uetoothd)[2060]: ConfigurationDirectory 'bluetooth' already exists but the mode is different. (File system: 755 ConfigurationDirectoryMode: 555)
Mar 29 14:18:28 bodyscalepi01 systemd[1]: Starting bluetooth.service - Bluetooth service...
Mar 29 14:18:29 bodyscalepi01 bluetoothd[2060]: Bluetooth daemon 5.66
Mar 29 14:18:29 bodyscalepi01 systemd[1]: Started bluetooth.service - Bluetooth service.
Mar 29 14:18:29 bodyscalepi01 sudo[2050]: pam_unix(sudo:session): session closed for user root
Mar 29 14:18:29 bodyscalepi01 bluetoothd[2060]: Starting SDP server
Mar 29 14:18:29 bodyscalepi01 bluetoothd[2060]: profiles/audio/vcp.c:vcp_init() D-Bus experimental not enabled
Mar 29 14:18:29 bodyscalepi01 bluetoothd[2060]: src/plugin.c:plugin_init() Failed to init vcp plugin
Mar 29 14:18:29 bodyscalepi01 bluetoothd[2060]: profiles/audio/mcp.c:mcp_init() D-Bus experimental not enabled
Mar 29 14:18:29 bodyscalepi01 bluetoothd[2060]: src/plugin.c:plugin_init() Failed to init mcp plugin
Mar 29 14:18:29 bodyscalepi01 bluetoothd[2060]: profiles/audio/bap.c:bap_init() D-Bus experimental not enabled
Mar 29 14:18:29 bodyscalepi01 bluetoothd[2060]: src/plugin.c:plugin_init() Failed to init bap plugin
Mar 29 14:18:30 bodyscalepi01 dbus-daemon[326]: [system] Activating via systemd: service name='org.freedesktop.hostname1' unit='dbus-org.freedesktop.hostname1.service' requested by ':1.41' (uid=0 pid=2060 comm="/usr/libexec/bluetooth/bluetoothd")
Mar 29 14:18:30 bodyscalepi01 sudo[2061]:     root : TTY=pts/0 ; PWD=/opt/BS440 ; USER=root ; COMMAND=/usr/bin/hciconfig hci0 reset
Mar 29 14:18:30 bodyscalepi01 bluetoothd[2060]: Bluetooth management interface 1.22 initialized
Mar 29 14:18:30 bodyscalepi01 sudo[2061]: pam_unix(sudo:session): session opened for user root(uid=0) by pi(uid=0)
Mar 29 14:18:30 bodyscalepi01 bluetoothd[2060]: profiles/sap/server.c:sap_server_register() Sap driver initialization failed.
Mar 29 14:18:30 bodyscalepi01 bluetoothd[2060]: sap-server: Operation not permitted (1)
Mar 29 14:18:30 bodyscalepi01 systemd[1]: Starting systemd-hostnamed.service - Hostname Service...
Mar 29 14:18:30 bodyscalepi01 sudo[2061]: pam_unix(sudo:session): session closed for user root
Mar 29 14:18:30 bodyscalepi01 bluetoothd[2060]: Failed to set privacy: Rejected (0x0b)
Mar 29 14:18:32 bodyscalepi01 dbus-daemon[326]: [system] Successfully activated service 'org.freedesktop.hostname1'
Mar 29 14:18:32 bodyscalepi01 systemd[1]: Started systemd-hostnamed.service - Hostname Service.
Mar 29 14:19:02 bodyscalepi01 systemd[1]: systemd-hostnamed.service: Deactivated successfully.
Mar 29 14:19:02 bodyscalepi01 systemd[1]: systemd-hostnamed.service: Consumed 1.357s CPU time.

Unfortunately I’m stuck at this point and hope someone can give me a tip.

Thank you in advance for your help.
Christian

In case no one can help consider opening an issue here.