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

Two instances with mqtt #121

Open
Fragggy opened this issue May 28, 2020 · 10 comments
Open

Two instances with mqtt #121

Fragggy opened this issue May 28, 2020 · 10 comments

Comments

@Fragggy
Copy link

Fragggy commented May 28, 2020

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

@kwesolowski
Copy link

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

@Fragggy
Copy link
Author

Fragggy commented May 29, 2020

Second instance is on different Hardware.

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

@kwesolowski
Copy link

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

@Fragggy
Copy link
Author

Fragggy commented May 29, 2020

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

@kwesolowski
Copy link

kwesolowski commented May 29, 2020 via email

@Fragggy
Copy link
Author

Fragggy commented Oct 30, 2020

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

@OnnoH
Copy link

OnnoH commented Oct 30, 2020

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?

@Fragggy
Copy link
Author

Fragggy commented Oct 30, 2020

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
Copy link
Author

Fragggy commented Oct 30, 2020

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

@OnnoH
Copy link

OnnoH commented Oct 30, 2020

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?

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

3 participants