question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Initial connection to Mi Flora sensor [...] failed (was working previously on a pi zero)

See original GitHub issue

Hi, I had miflora-mqtt-daemon correctly setup on a pi zero - everything was working perfectly well. Today, I decided to replace my pi zero with a raspberry pi 3b+ so I installed everything again on the new pi, including miflora-mqtt-daemon.

I got the same exact configuration than on the pizero but I can’t get my miflora sensor detected though - I have the feeling like if it still binded to the pizero and can’t be binded again with another setup ? Any ideas ? I’ve been completely stucked for hours…

Here is the error showing up when launching python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py (FYI config.ini is correctly setup, mac-adresses are correctly defined, again - same configuration than the working pizero)

Initial connection to Mi Flora sensor "miflora_plant" (xx:xx:xx:xx:xx:xx) failed.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
analoguecommented, Apr 17, 2021

New user to miflora here and had same issue trying to get miflora working in a docker container on a rpi. Turns out the --net host is necessary (at least in my case) for it to work. The empty error message is not too useful, so poking at the exception in a debug session revealed a bit more info:

[2021-04-17 12:11:08] Connecting to MQTT broker ...
[2021-04-17 12:11:08] MQTT connection established

Adding sensor to device list and testing connection ...
Name:          "DatePalms"
> /usr/src/app/miflora-mqtt-daemon.py(214)<module>()
-> print_line('Initial connection to Mi Flora sensor "{}" ({}) failed due to exception: {}'.format(name_pretty, mac, e), error=True, sd_notify=True)
(Pdb) e
BluetoothBackendException()
(Pdb) dir(e)
['__cause__', '__class__', '__context__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__suppress_context__', '__traceback__', '__weakref__', 'args', 'with_traceback']
(Pdb) e.__cause__
BTLEDisconnectError('Failed to connect to peripheral [redacted], addr type: public', {'rsp': ['stat'], 'state': ['disc'], 'mtu': [0], 'sec': ['low']})
(Pdb) dir(e.__cause__)
['__cause__', '__class__', '__context__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__suppress_context__', '__traceback__', '__weakref__', 'args', 'emsg', 'estat', 'message', 'with_traceback']
(Pdb) e.__cause__.__cause__
(Pdb) e.__cause__.args
('Failed to connect to peripheral [redacted], addr type: public', {'rsp': ['stat'], 'state': ['disc'], 'mtu': [0], 'sec': ['low']})
(Pdb) e.__cause__.emsg
(Pdb) e.__cause__.estat
(Pdb) e.__cause__.message
'Failed to connect to peripheral [redacted], addr type: public'
(Pdb)
'Failed to connect to peripheral [redacted], addr type: public'

Then I used gatttool both inside and outside the container and it failed in the container without --network=host.

Hope that helps someone 😃

0reactions
brononiuscommented, Apr 27, 2021

Same here. I’m new to the story, and installed it on a Raspberry 4. At first, everything worked fine. But suddenly, after about 2 hours, I noticed that the data wasn’t coming in anymore. After digging a bit deeper, I’m getting the same error:

root@winniedepoeh:~# sudo systemctl status miflora.service
* miflora.service - Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
   Loaded: loaded (/etc/systemd/system/miflora.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2021-04-27 21:23:35 CEST; 3min 10s ago
     Docs: https://github.com/ThomDietrich/miflora-mqtt-daemon
 Main PID: 735 (python3)
   Status: "Apr 27 21:25:21 - Status messages published."
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/miflora.service
           `-735 /usr/bin/python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py

apr 27 21:23:32 winniedepoeh systemd[1]: Starting Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon...
apr 27 21:23:35 winniedepoeh systemd[1]: Started Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon.
apr 27 21:23:36 winniedepoeh python3[735]: [2021-04-27 21:23:36] Initial connection to Mi Flora sensor "Bonsai" (C4:7C:8D:6C:7B:BA) failed due to exception:
apr 27 21:25:21 winniedepoeh python3[735]: [2021-04-27 21:25:21] Failed to retrieve data from Mi Flora sensor "Bonsai" (C4:7C:8D:6C:7B:BA), success rate: 0%

At the end, I think it has something to do with the distance. When my sensor is about 3 meters from the RP4 in a straight line, it works. When I move to about 4m, just in line with a door jamb (?), I’m getting the error above?

Read more comments on GitHub >

github_iconTop Results From Across the Web

miflora does not connect : r/homeassistant - Reddit
I got two new Mi Flora plant monitors, but I am having issues connecting them (running on hassio). I have another one I...
Read more >
Bountysource
Initial connection to Mi Flora sensor [...] failed (was working previously on a pi zero)
Read more >
Miflora broken after upgrading to 0.97 - Home Assistant OS
miflora was running for weeks without problems on 0.96.x Then I upgraded to 0.97.0 and it started crashing every 8-16 hours.
Read more >
Wireless soil moisture sensor - Page 2 - Raspberry Pi Forums
When i setup the 'miflora mqtt-daemon.py' to run at startup i will just edit the code to push output into my webserver for...
Read more >
Xiaomi Mi Flora [Temp/Light/Moisture] BLE Sensor - Page 13
Today I needed to reinstall my Orange Pi Zero, before I had ... Getting data from Mi Flora FW: 2.6.2 connect: Device or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found