kamaradclimber / hydrao-dump

A simple script to send data from hydrao shower head to Home Assistant through an MQTT server
8 stars 3 forks source link

After Connecting and reading -> BrokenPipeError #3

Closed giovanne123 closed 2 years ago

giovanne123 commented 2 years ago

Hi, I also got a Hydrao Aloe and I saw your python script for conneting to it.

Do you have an idea why I can't read from the device. Trying with your script (reading the volumes) or trying with my own (for receiving the services) I always get after connecting and trying to access an "BrokenPipeError" ;-(

Have you although had issues with "BrokenPipeError"?

The Pi is round about 2,5m away from the Shower. With Androind Phone (same distance) and using "nrf Connect" I can successful connect and read all the Services. Unfortunatelly at the moment I can't get the Pi more nearby to the Shower :-( But on the other side, the connecting itself seems to be successful. Running in --dry_run mode runs successfull. Other BLE devices can be connected and read from the same Pi.

root@Pi:/home/pi/hydrao/hydrao-dump# python3 receiver.py xx:xx:xx:xx:xx:xx connect and read Connecting... Connected Traceback (most recent call last): File "receiver.py", line 203, in main() File "receiver.py", line 29, in main connect_and_read(mqtt_client) File "receiver.py", line 156, in connect_and_read battery_service = hydrao.getServiceByUUID(so_called_battery_service_uuid) File "/usr/local/lib/python3.7/site-packages/bluepy/btle.py", line 488, in getServiceByUUID rsp = self._getResp('find') File "/usr/local/lib/python3.7/site-packages/bluepy/btle.py", line 407, in _getResp resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout) File "/usr/local/lib/python3.7/site-packages/bluepy/btle.py", line 361, in _waitResp self._stopHelper() File "/usr/local/lib/python3.7/site-packages/bluepy/btle.py", line 293, in _stopHelper self._helper.stdin.flush() BrokenPipeError: [Errno 32] Broken pipe Exception ignored in: <function Peripheral.del at 0xb681b4b0> Traceback (most recent call last): File "/usr/local/lib/python3.7/site-packages/bluepy/btle.py", line 630, in del self.disconnect() File "/usr/local/lib/python3.7/site-packages/bluepy/btle.py", line 453, in disconnect self._writeCmd("disc\n") File "/usr/local/lib/python3.7/site-packages/bluepy/btle.py", line 305, in _writeCmd self._helper.stdin.flush() BrokenPipeError: [Errno 32] Broken pipe

my bluepy is version 1.3:

root@Pi:/home/pi/hydrao/hydrao-dump# pip3 show bluepy Name: bluepy Version: 1.3.0 Summary: Python module for interfacing with BLE devices through Bluez Home-page: https://github.com/IanHarvey/bluepy Author: Ian Harvey Author-email: website-contact@fenditton.org License: UNKNOWN Location: /usr/local/lib/python3.7/site-packages Requires: Required-by:

giovanne123 commented 2 years ago

I think it can be a reason that the Pi/Bluetooth Dongle is to far from the shower :-( Manual test with gatttool also throws an error:

root@Pi:/home/pi# gatttool -I [ ][LE]> connect xx:xx:xx:xx:xx:xx Attempting to connect to xx:xx:xx:xx:xx:xx Connection successful [xx:xx:xx:xx:xx:xx][LE]> (gatttool:1290): GLib-WARNING **: Invalid file descriptor.

[xx:xx:xx:xx:xx:xx][LE]> char-read-uuid 0000ca1c-0000-1000-8000-00805f9b34fb Command Failed: Disconnected

With an USB extention cable to shorten the distance from pi to shower I can connect without the "Invalid file descriptor" error. I think the bluetooth range from the shower is not that far :-(

Unfortunatelly I can't position the Pi closer to the shower because of missing power. I think I need to extend the BT dongle with usb extention cable (not so simple in a bath that it can't be seen) or maybe a BT extender or better BT usb dongle?

kamaradclimber commented 2 years ago

To give you a comparaison, in my setup, the shower head is 3m away from the bluetooth dongle and I don't have any connection issue. In general bluetooth works well within 5 meters

giovanne123 commented 2 years ago

The distance is not the problem. Seems top be some issue in my installation (python), get broken pipe or similiar error when trying to connect with bluepy or pygatt(gatttool) in python 2 or 3. Using gatttool directly is working well, e.g. gatttool -i hci0 -b AA:BB:CC:DD:EE:FF --char-read --handle=0x0012

So I'm currently working with a workaround by calling the gatttool command from within python, until I find more time to deeper look into my problem.