Open ViperRNMC opened 6 years ago
Please provide the non-cut version of the error messages. Besides that the error seems clear, your mqtt broker is not reachable...
this is the output of the Damon status, where can I find the log?
You just have to maximize your console window =)
strange enough when I start the service again it connects fine
* miflora.service - Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
Loaded: loaded (/etc/systemd/system/miflora.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2018-01-17 17:19:12 UTC; 54min ago
Docs: https://github.com/ThomDietrich/miflora-mqtt-daemon
Process: 243 ExecStart=/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py (code=exited, status=1/FAILURE)
Main PID: 243 (code=exited, status=1/FAILURE)
Status: "Jan 17 17:19:11 - MQTT connection error. Please check your settings in the configuration file "config.ini"."
jan 17 17:19:03 pi-zero-w systemd[1]: Starting Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon...
jan 17 17:19:11 pi-zero-w miflora-mqtt-daemon.py[243]: [2018-01-17 17:19:11] MQTT connection error. Please check your settings in the configuration file "config.in
jan 17 17:19:12 pi-zero-w systemd[1]: miflora.service: Main process exited, code=exited, status=1/FAILURE
jan 17 17:19:12 pi-zero-w systemd[1]: Failed to start Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon.
jan 17 17:19:12 pi-zero-w systemd[1]: miflora.service: Unit entered failed state.
jan 17 17:19:12 pi-zero-w systemd[1]: miflora.service: Failed with result 'exit-code'.
~
~
Hmm that means that your broker is temporarily not available I guess. Maybe you need to add reconnection attempts (a simple loop with a short waiting period) to the code here. I can't do that at the moment but when you find a configuration that works, please let us know!
@ThomDietrich can you please add
Restart=always
to the [Service] part of the systemd service file? this helped in my case.
When is this needed? I never had issues with the execution.
I am not against the addition. Please create a PR. Thanks!
On my system the services crashed every 2-3 hours because of connection issues. i created a PR
The PR is merged but this issue should definitely be solved inside the daemon by checking the connection prior to sending data.
Hi:
I have a related Issue. If the MQTT server is down for an update for some time, before it restarts I didn't get new messages until I reboot the RPI or restart the daemon service, so I think that the daemon looses the connection and It gets stucked.
¿Is there any way to change the reconnection loop to make it infinite?
Thanks for your work
I'm not sure but I think you have to add this:
def on_disconnect(client, userdata, rc):
if rc != 0:
print("Unexpected disconnection. Reconnecting...")
mqtt_client.reconnect()
else :
print "Disconnected successfully"
and this:
mqtt_client.on_disconnect = on_disconnect
But I'm not sure that this is happening. I think that the problem comes froms this:
def on_connect(client, userdata, flags, rc):
if rc == 0:
print_line('MQTT connection established', console=True, sd_notify=True)
print()
else:
print_line('Connection error with result code {} - {}'.format(str(rc), mqtt.connack_string(rc)), error=True)
#kill main thread
os._exit(1)
Going to an os._exit because of a connection error is maybe stoping the daemon after several reconnection attempts... not sure.
Hi, i install the daemon on a pi 0w with raspbian. Works great for a while, but couple of weeks I got almost every 1 a 2 days an error and my daemon stops working.