ChristianKuehnel / plantgateway

Bluetooth to mqtt gateway for Xiaomi Mi plant sensors
Apache License 2.0
271 stars 43 forks source link

Cannot read data from my sensors #47

Closed hesspoint closed 3 years ago

hesspoint commented 3 years ago

Hi, I installed plantgateway on a Pi Zero. Then I run plantgateway it seems to work and everything is updated. Home Assistant shows all data. Perfekt. I setup a cronjob to run plantgateway every hour so that HA gets an update once per hour.

However when I look in HA it show the initial data and then nothing. Last update 15h ago or so.

I looked into the logs and for all 3 sensors in the room I get an exception. Actually it says “connection accepted” but then it cannot read data. The strange thing is that it was working at the beginning and I did not change anything after that except setting up the cronjob. Even when I run plantgateway manually now again it also throws the error “Cannot read data from....”

Here is an excerpt from the log (I replaced the real MAC address with XX:XX:XX:XX:XX). It is a bit beyond my skills to make sense of that but hopefully some of you can.

Sun, 15 Nov 2020 01:04:20 INFO MQTT connection returned result: Connection Accepted. Sun, 15 Nov 2020 01:04:21 INFO MQTT connection returned result: Connection Accepted. Sun, 15 Nov 2020 01:04:22 INFO MQTT connection returned result: Connection Accepted. Sun, 15 Nov 2020 01:04:23 INFO MQTT connection returned result: Connection Accepted. Sun, 15 Nov 2020 01:04:24 INFO MQTT connection returned result: Connection Accepted. Sun, 15 Nov 2020 01:04:25 ERROR could not read data from XX:XX:XX:XX:XX:XX (Cactus LivingRoom MQTT) with reason: Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 27, in _func_wrapper return func(*args, **kwargs) File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 56, in connect self._peripheral = Peripheral(mac, iface=iface, addrType=self.address_type) File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 391, in init self._connect(deviceAddr, addrType, iface) File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 439, in _connect raise BTLEDisconnectError("Failed to connect to peripheral %s, addr type: %s" % (addr, addrType), rsp) bluepy.btle.BTLEDisconnectError: Failed to connect to peripheral XX:XX:XX:XX:XX, addr type: public

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 263, in process_all self.process_mac(sensor) File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 241, in process_mac self._publish(sensor_config, poller) File "/usr/local/lib/python3.7/dist-packages/plantgw/plantgw.py", line 213, in _publish MQTTAttributes.BATTERY.value: poller.parameter_value(MI_BATTERY), File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 149, in parameter_value return self.battery_level() File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 119, in battery_level self.firmware_version() File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 127, in firmware_version with self._bt_interface.connect(self._mac) as connection: File "/usr/local/lib/python3.7/dist-packages/btlewrap/base.py", line 45, in enter self._backend.connect(self._mac) File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 33, in _func_wrapper raise BluetoothBackendException() from last_error btlewrap.base.BluetoothBackendException

Thanks very much for your help!

hesspoint commented 3 years ago

Hi, It has been 17 days and no answer. It would be great to get a quick feedback if I can solve this somehow or what I am doing wrong. Thanks :)

ChristianKuehnel commented 3 years ago

This is an open source project. there are no guarantees whatsoever. Also not on responding to issues.

From the logs I guess you Pi can't connect to the sensor. This could be for any reason two bluetooth devices can't connect. So I can't tell you how to fix this.