Two instances with mqtt
Fragggy opened this issue · 10 comments
Hi everyone,
first thank you for this awesome piece of software.
I started with one daemon an a pi zero and newer missed an update at the mqtt broker.
Now with a second instance setup, I lose a lot of updates on the mqtt broker.
Interval is set to 300s and it sometime takes 20min till something arrives.
If I disable one instance it is back to normal.
Is there something special to set, when using more than one daemon on the same mqtt broker?
Thank you for any advice.
Regards
Dennis
Second instance is on the same hardware? I would worry more about sharing bluetooth than sharing a broker?
Second instance is on different Hardware.
Range was a problem, so I set up a second one.
Are both working fine with json backend when observed over SSH?
You mean the output when running them not as a daemon?
Or is there some kind of verbose logging I have to look for?
Hi, I had time to dig into this a little more. Sorry it took so long.
The Problem seems to be, that both clients use the same (empty) name, when they connect to the server:
If I turn one Instance off, the reconnecting stops.
The Server now thinks it is one Client and switches between both.
Is there a way to change the Name?
Regards
Dennis
It's easy to provide a name in mqtt_client = mqtt.Client()
, but that shouldn't be neccessary, because the broker (Mosquitto in my case) assigns a clientID automatically.
1604067158: mosquitto version 1.6.12 running
1604067164: New connection from 172.17.0.1 on port 1883.
1604067164: New client connected from 172.17.0.1 as Frederik (p2, c1, k60).
1604067176: Client Frederik disconnected.
1604067205: New connection from 172.17.0.1 on port 1883.
1604067205: New client connected from 172.17.0.1 as auto-3778535E-D001-177E-BF04-C0E98312E552 (p2, c1, k60).
1604067217: Client auto-3778535E-D001-177E-BF04-C0E98312E552 disconnected.
Which broker are you using?
I am using the mqtt Adapter in iobroker.
Do i have to set it in the Code or is there also a parameter in config.ini for this?
Ok i tested it.
Changed the Code to:
mqtt_client = mqtt.Client(client_id="FlowerPi2")
But the client crashed with the error below:
Adding sensor to device list and testing connection ...
Name: "Garden_right"
Internal name: "Garden_right"
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 C4:7C:8D:67:B9:4F, addr type: public
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py", line 216, in <module>
print('Device name: "{}"'.format(flora_poller.name()))
File "/usr/local/lib/python3.7/dist-packages/miflora/miflora_poller.py", line 74, in name
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
That seems like another problem to me and is Bluetooth related. Your Pi can't reach the MiFlora C4:7C:8D:67:B9:4F. Battery low or a sensor reset needed?