Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No data transfer with RPI 3/4 #135

Open
Chouille opened this issue Mar 20, 2021 · 6 comments
Open

No data transfer with RPI 3/4 #135

Chouille opened this issue Mar 20, 2021 · 6 comments

Comments

@Chouille
Copy link
Contributor

Chouille commented Mar 20, 2021

Hello.
I have some difficulties to run successfully the script. After some issues with MQTT connexion (Remove the space after "=" for login and password in config file), i have this :

root@raspberrypi:/opt/miflora-mqtt-daemon# sudo python miflora-mqtt-daemon.py

Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
Source: https://github.com/ThomDietrich/miflora-mqtt-daemon

[2021-03-20 16:44:00] Connecting to MQTT broker ...
[2021-03-20 16:44:00] MQTT connection established

Adding sensor to device list and testing connection ...
Name:          "Basilic"
[2021-03-20 16:44:01] Attempting initial connection to Mi Flora sensor "Basilic" (C4:7C:XX:XX:XX:XX)

An that's all. Nothing happend.

The script runs on RPI 3, Sensor is detected by the RPI.
I tried to update blueZ with version 5.56 without success.
i tried to switch differents libs.

#from btlewrap import BluepyBackend, GatttoolBackend, BluetoothBackendException
#from bluepy.btle import BTLEException
from btlewrap.bluepy import BluepyBackend

Someone will have an idea on the issue origin, or success to run the script on RPI3 ?

Best regards.

@ThomDietrich
Copy link
Owner

ThomDietrich commented Mar 20, 2021

Hey @Chouille, it's weird you are not seeing any error pop up after a certain timeout. Still, the error is very likely related to the bluetooth setup on your system. You shouldn't change the code. There were quite a few hurdles over the years and I can't help specifically. Did you receive results during the scan? https://github.com/ThomDietrich/miflora-mqtt-daemon#configuration

@Chouille
Copy link
Contributor Author

Chouille commented Mar 21, 2021

Thanks @ThomDietrich for your answer.
I changed the code just in order to try to solve the issue by myself before to open a thread. I recopy your script, and let turn it currently. Wait and see.

My config if you see something strange :

[General]
reporting_method = mqtt-json
adapter = hci0

[Daemon]
enabled = true
period = 300

[MQTT]
hostname = localhost
port = 1883
keepalive = 60
basic_topic = miflora
homie_device_id = miflora-mqtt-daemon

username=XXXXXXXXXXXXXX
password=XXXXXXXXXXXXXX

[Sensors]
Basilic            = C4:7C:XX:XX:XX:XX

After a night, i interrupt the command and i have this :

Adding sensor to device list and testing connection ...
Name:          "Basilic"
^C^CTraceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 128, in firmware_version
    res = connection.read_handle(_HANDLE_READ_VERSION_BATTERY)  # pylint: disable=no-member
  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 75, in read_handle
    return self._peripheral.readCharacteristic(handle)
  File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 530, in readCharacteristic
    resp = self._getResp('rd')
  File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 407, in _getResp
    resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
  File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 347, in _waitResp
    rv = self._helper.stdout.readline()
KeyboardInterrupt

During handling of the above exception, another exception occurred:

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 64, in disconnect
    self._peripheral.disconnect()
  File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 454, in disconnect
    self._getResp('stat')
  File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 407, in _getResp
    resp = self._waitResp(wantType + ['ntfy', 'ind'], timeout)
  File "/usr/local/lib/python3.7/dist-packages/bluepy/btle.py", line 339, in _waitResp
    raise BTLEInternalError("Helper exited")
bluepy.btle.BTLEInternalError: Helper exited

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "miflora-mqtt-daemon.py", line 206, in <module>
    flora_poller.fill_cache()
  File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 85, in fill_cache
    firmware_version = self.firmware_version()
  File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 130, in firmware_version
    _HANDLE_READ_VERSION_BATTERY, format_bytes(res))
  File "/usr/local/lib/python3.7/dist-packages/btlewrap/base.py", line 55, in __exit__
    self._cleanup()
  File "/usr/local/lib/python3.7/dist-packages/btlewrap/base.py", line 62, in _cleanup
    self._backend.disconnect()
  File "/usr/local/lib/python3.7/dist-packages/btlewrap/bluepy.py", line 31, in _func_wrapper
    time.sleep(RETRY_DELAY)
KeyboardInterrupt

Don't worry, i understand the issue is problably due to my device. I'm not an expert but if you have some idea of things i can check, i'm listen :)

@ThomDietrich
Copy link
Owner

Because it was anyhow needed: I've just installed a fresh system for this.

image

@Chouille
Copy link
Contributor Author

Hello.
I followed your instructions and restart setup from beginning + compile/install bluez, but same result :

`
pi@raspberrypi:/opt/miflora-mqtt-daemon $ sudo python3 miflora-mqtt-daemon.py

Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
Source: https://github.com/ThomDietrich/miflora-mqtt-daemon

[2021-03-28 21:47:03] Connecting to MQTT broker ...
[2021-03-28 21:47:03] MQTT connection established

Adding sensor to device list and testing connection ...
Name: "Basilic"

`

Stupid question, my sensor is this one : https://www.amazon.fr/gp/product/B01LXOJSWA/
Does the script will work with it ? they says "Xiaomi Plant Monitor"...

@Chouille
Copy link
Contributor Author

Chouille commented Apr 7, 2021

Hello.
I received my Pi zero and tested the script : works like a charm.
So, don't know what failed on RPI3/4. I don't have enough knowledge to solve, but if i found the solution, be sure i will update.
I will change the title to be more explicit on the issue, maybe someone will solve it.
Thanks again for your help.

@Chouille Chouille changed the title No data transfer No data transfer with RPI 3/4 Apr 7, 2021
@ThomDietrich
Copy link
Owner

Thanks.

I'm honestly quite annoyed by Rasbian. It is supposed to be a baseline system for Raspi tinkerers and I honestly never encountered a worse linux default setup, at least not in the last 20 years.

The software must work with all Raspberry Pis but maybe a slightly different setup is needed. If you are not able to get it working you can always just use openHABian. It features openHAB (which you can disable if not needed) and a correctly configured bluetooth stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants