miflora-mqtt-daemon icon indicating copy to clipboard operation
miflora-mqtt-daemon copied to clipboard

Two instances with mqtt

Open Fragggy opened this issue 4 years ago β€’ 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

Fragggy avatar May 28 '20 17:05 Fragggy

Second instance is on the same hardware? I would worry more about sharing bluetooth than sharing a broker?

kwesolowski avatar May 29 '20 06:05 kwesolowski

Second instance is on different Hardware.

Range was a problem, so I set up a second one.

Fragggy avatar May 29 '20 07:05 Fragggy

Are both working fine with json backend when observed over SSH?

kwesolowski avatar May 29 '20 08:05 kwesolowski

You mean the output when running them not as a daemon? Or is there some kind of verbose logging I have to look for?

Fragggy avatar May 29 '20 15:05 Fragggy

In config you can select local std out printing and run not as a service, so you can see if measurements are coming.

Also when running not as a deamon stdout is already very verbose. Do you see measurements happening but just mqtt misses them?

On Fri, 29 May 2020, 17:14 Fragggy, [email protected] wrote:

You mean the output when running them not as a daemon? Or is there some kind of verbose logging I have to look for?

β€” You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ThomDietrich/miflora-mqtt-daemon/issues/121#issuecomment-636028630, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNPW344SHK2YZTOWUKDOMTRT7GMBANCNFSM4NNJOGSA .

kwesolowski avatar May 29 '20 17:05 kwesolowski

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: image 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

Fragggy avatar Oct 30 '20 13:10 Fragggy

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?

OnnoH avatar Oct 30 '20 14:10 OnnoH

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?

Fragggy avatar Oct 30 '20 14:10 Fragggy

Ok i tested it.

Changed the Code to: mqtt_client = mqtt.Client(client_id="FlowerPi2")

Now I hava a Name in the Log: image

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

Fragggy avatar Oct 30 '20 14:10 Fragggy

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?

OnnoH avatar Oct 30 '20 14:10 OnnoH