ChristianKuehnel / plantgateway

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

Helper exited #15

Closed ghost closed 6 years ago

ghost commented 7 years ago

Hey,

I get the following errors:

pi@raspberrypi:~ $ plantgateway
could not read data from C4:7C:8D:65:B8:FF (Rihanna) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64b2990>> ignored
could not read data from C4:7C:8D:65:B9:06 (otherplant) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64d35a8>> ignored
could not read data from C4:7C:8D:65:B8:FF (Rihanna) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64b2be8>> ignored
could not read data from C4:7C:8D:65:B9:06 (otherplant) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64d3620>> ignored
could not read data from C4:7C:8D:65:B8:FF (Rihanna) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64b2cb0>> ignored
could not read data from C4:7C:8D:65:B9:06 (otherplant) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64d36e8>> ignored
could not read data from C4:7C:8D:65:B8:FF (Rihanna) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64b2c60>> ignored
could not read data from C4:7C:8D:65:B9:06 (otherplant) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64d35d0>> ignored
could not read data from C4:7C:8D:65:B8:FF (Rihanna) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64b2cb0>> ignored
could not read data from C4:7C:8D:65:B9:06 (otherplant) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64d3738>> ignored
could not read data from C4:7C:8D:65:B8:FF (Rihanna) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64b2c38>> ignored
could not read data from C4:7C:8D:65:B9:06 (otherplant) with reason: Helper exited
Exception IOError: (32, 'Broken pipe') in <bound method Peripheral.__del__ of <bluepy.btle.Peripheral instance at 0xb64d3788>> ignored
Could not get data from 2sensor(s): Rihanna, otherplant.
pi@raspberrypi:~ $

hcitool lescan works and I can see the sensors but no go.

bluetoothctl show the following:

root@raspberrypi:/home/pi# sudo bluetoothctl
[NEW] Controller B8:27:EB:A1:25:D2 raspberrypi [default]
[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:A1:25:D2 Discovering: yes
[NEW] Device C4:7C:8D:65:B9:06 C4-7C-8D-65-B9-06
[NEW] Device C4:7C:8D:65:B8:FF Flower care
[NEW] Device 04:52:C7:B0:EB:23 04-52-C7-B0-EB-23
[CHG] Device C4:7C:8D:65:B9:06 RSSI: -88
[CHG] Device C4:7C:8D:65:B9:06 Name: Flower care
[CHG] Device C4:7C:8D:65:B9:06 Alias: Flower care
[CHG] Device C4:7C:8D:65:B8:FF RSSI: -64
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Key: 0000fe95-0000-1000-8000-00805f9b34fb
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x71
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x20
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x98
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x00
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x81
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0xff
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0xb8
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x65
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x8d
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x7c
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0xc4
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x0d
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x04
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x10
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x02
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0xc7
[CHG] Device C4:7C:8D:65:B8:FF ServiceData Value: 0x00
[CHG] Device C4:7C:8D:65:B9:06 RSSI: -74
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Key: 0000fe95-0000-1000-8000-00805f9b34fb
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x71
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x20
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x98
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x00
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x27
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x06
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0xb9
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x65
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x8d
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x7c
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0xc4
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x0d
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x08
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x10
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x01
[CHG] Device C4:7C:8D:65:B9:06 ServiceData Value: 0x19
[CHG] Device C4:7C:8D:65:B8:FF RSSI: -82
[CHG] Device C4:7C:8D:65:B9:06 RSSI: -97
ChristianKuehnel commented 7 years ago

Hi,

I haven't seen that error message so far. It seems to be a problem with the Bluetooth LE communication between your RasPi and the sensor. I have it working on a "RaspberryPi W Zero", but I'm not sure if they both use the same Bluetooth hardware...

How far are the RasPi and the Sensor apart? If it's more than 3 meters you might try moving it closer. But apart from that I'm not sure how I can help you there...

ghost commented 7 years ago

Hey, it was indeed an issues with the raspbian image. I've reinstalled it and the bluetooth is now working as it should. However I still cant communicate with the sensors.

If I run it now I get the following:

root@plantgateway:~# plantgateway
[Errno 104] Connection reset by peer
[Errno 104] Connection reset by peer
could not read data from C4:7C:8D:65:B8:FF (Rihanna) with reason: Error from Bluetooth stack (comerr)
[Errno 104] Connection reset by peer
[Errno 104] Connection reset by peer
[Errno 104] Connection reset by peer
[Errno 104] Connection reset by peer
could not read data from C4:7C:8D:65:B9:06 (otherplant) with reason: Failed to connect to peripheral C4:7C:8D:65:B9:06, addr type: public
could not read data from C4:7C:8D:65:B8:FF (Rihanna) with reason: Error from Bluetooth stack (comerr)
[Errno 104] Connection reset by peer
could not read data from C4:7C:8D:65:B9:06 (otherplant) with reason: Failed to connect to peripheral C4:7C:8D:65:B9:06, addr type: public
could not read data from C4:7C:8D:65:B8:FF (Rihanna) with reason: Error from Bluetooth stack (comerr)
[Errno 104] Connection reset by peer
could not read data from C4:7C:8D:65:B9:06 (otherplant) with reason: Failed to connect to peripheral C4:7C:8D:65:B9:06, addr type: public
could not read data from C4:7C:8D:65:B8:FF (Rihanna) with reason: Error from Bluetooth stack (comerr)
could not read data from C4:7C:8D:65:B9:06 (otherplant) with reason: Failed to connect to peripheral C4:7C:8D:65:B9:06, addr type: public
could not read data from C4:7C:8D:65:B8:FF (Rihanna) with reason: Error from Bluetooth stack (comerr)
could not read data from C4:7C:8D:65:B9:06 (otherplant) with reason: Error from Bluetooth stack (comerr)
could not read data from C4:7C:8D:65:B8:FF (Rihanna) with reason: Error from Bluetooth stack (comerr)
[Errno 104] Connection reset by peer
could not read data from C4:7C:8D:65:B9:06 (otherplant) with reason: Error from Bluetooth stack (comerr)
Could not get data from 2sensor(s): Rihanna, otherplant.

the debug log looks like this (over and over):

Sat, 23 Sep 2017 20:00:12 INFO     loaded config file from /root/.plantgw.yaml
Sat, 23 Sep 2017 20:00:12 INFO     Getting data from sensor Rihanna
Sat, 23 Sep 2017 20:00:14 DEBUG    connected to device C4:7C:8D:65:B8:FF
Sat, 23 Sep 2017 20:00:14 ERROR    could not read data from C4:7C:8D:65:B8:FF (Rihanna) with reason: Error from Bluetooth stack (comerr)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/plantgw/__init__.py", line 192, in process_all
    self.process_mac(sensor)
  File "/usr/local/lib/python2.7/dist-packages/plantgw/__init__.py", line 169, in process_mac
    sensor.get_data()
  File "/usr/local/lib/python2.7/dist-packages/plantgw/misensor.py", line 34, in get_data
    self._fetch_35()
  File "/usr/local/lib/python2.7/dist-packages/plantgw/misensor.py", line 52, in _fetch_35
    self.peripheral.writeCharacteristic(0x33, bytes([0xA0, 0x1F]), True)
  File "/usr/local/lib/python2.7/dist-packages/bluepy/btle.py", line 502, in writeCharacteristic
    return self._getResp('wr')
  File "/usr/local/lib/python2.7/dist-packages/bluepy/btle.py", line 369, in _getResp
    resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
  File "/usr/local/lib/python2.7/dist-packages/bluepy/btle.py", line 332, in _waitResp
    raise BTLEException(BTLEException.COMM_ERROR, "Error from Bluetooth stack (%s)" % errcode)
BTLEException: Error from Bluetooth stack (comerr)

I'm using a RaspberryPi W Zero I will try moving them closer (they are about 3m apart)

Edit: after moving them to about 50cm apart nothing has changed. Could it be that I have installed the latest firmware on the sensors?

I have Bluez 5.47 running

Amir974 commented 7 years ago

I am seeing similar problems on my pi Zero W.... can I ask, which image are you using and how you got it to work with BT ?

I am now seeing the following (but had the "Helper Exited" earlier:

pi@raspberrypi:~ $ plantgateway
Exception ignored in: <bound method Peripheral.__del__ of <bluepy.btle.Peripheral object at 0xb64f0ef0>>
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 520, in __del__
    self.disconnect()
  File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 416, in disconnect
    self._writeCmd("disc\n")
  File "/usr/local/lib/python3.5/dist-packages/bluepy/btle.py", line 268, in _writeCmd
    self._helper.stdin.flush()
BrokenPipeError: [Errno 32] Broken pipe
ghost commented 7 years ago

I am using the raspbian lite, but I think it could have been because I also updated my raspberry's firmware and then flashed it with pi baker.

I made my own gateway now with this https://github.com/open-homeautomation/miflora and a bit of python code. Its not as fancy as the plantgateway but it gets the job done for me.

You can use the demo.py to see if you can get it working that way.

ChristianKuehnel commented 7 years ago

I'm running:

$ cat /etc/issue
Raspbian GNU/Linux 8 \n \l
$ cat /etc/debian_version
8.0
ChristianKuehnel commented 6 years ago

I guess this was a bug in bluepy: https://github.com/IanHarvey/bluepy/issues/223#issuecomment-343994711

I just updated the requirements to version 1.1.4 of bluepy

syphernl commented 6 years ago

I'm experiencing the same after upgrading plantgateway (on a pi2). Bluepy is installed by plantgateway and meets the required version.

Sun, 26 Nov 2017 15:33:28 INFO     try 3 of 6: could not process sensor(s) aloevera. Waiting 4 sec for next try
Sun, 26 Nov 2017 15:33:32 INFO     Getting data from sensor aloevera
Sun, 26 Nov 2017 15:33:34 DEBUG    connected to device XX:XX:XX:XX:XX:XX:XX
Sun, 26 Nov 2017 15:33:34 ERROR    could not read data from XX:XX:XX:XX:XX:XX(aloevera) with reason: Error from Bluetooth stack (comerr)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/plantgw/__init__.py", line 195, in process_all
    self.process_mac(sensor)
  File "/usr/local/lib/python2.7/dist-packages/plantgw/__init__.py", line 172, in process_mac
    sensor.get_data()
  File "/usr/local/lib/python2.7/dist-packages/plantgw/misensor.py", line 34, in get_data
    self._fetch_35()
  File "/usr/local/lib/python2.7/dist-packages/plantgw/misensor.py", line 52, in _fetch_35
    self.peripheral.writeCharacteristic(0x33, bytes([0xA0, 0x1F]), True)
  File "/usr/local/lib/python2.7/dist-packages/bluepy/btle.py", line 502, in writeCharacteristic
    return self._getResp('wr')
  File "/usr/local/lib/python2.7/dist-packages/bluepy/btle.py", line 369, in _getResp
    resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
  File "/usr/local/lib/python2.7/dist-packages/bluepy/btle.py", line 332, in _waitResp
    raise BTLEException(BTLEException.COMM_ERROR, "Error from Bluetooth stack (%s)" % errcode)
BTLEException: Error from Bluetooth stack (comerr)
ChristianKuehnel commented 6 years ago

@syphernl that seems to be an issue in bluetooth communication within bluepy. I'm not sure what I can do there. Please file the bug report with https://github.com/IanHarvey/bluepy

syphernl commented 6 years ago

@ChristianKuehnel Problem seems to have been that I was using a python2.7 version of Plantgateway (and thus bluepy). Removing and reinstalling using pip3 seems to have fixed the issue!