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

Problem after reboot #115

Open
martellucci opened this issue Apr 11, 2020 · 6 comments
Open

Problem after reboot #115

martellucci opened this issue Apr 11, 2020 · 6 comments

Comments

@martellucci
Copy link

martellucci commented Apr 11, 2020

Hi, I’m using miflora-mqtt-daemon on RPI 3B+ and I’m very happy with it ;)

Only I’ve got a problem after reboot of the RPI when the daemon doesn’t start. The error is:

pi@Pi:~ $ 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: failed (Result: exit-code) since Sat 2020-04-11 21:11:30 BST; 13s ago
     Docs: https://github.com/ThomDietrich/miflora-mqtt-daemon
  Process: 614 ExecStart=/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py (code=exited, status=1/FAILURE)
 Main PID: 614 (code=exited, status=1/FAILURE)
   Status: "Apr 11 21:11:30 - MQTT connection error. Please check your settings in the configuration file "config.ini"."

Apr 11 21:11:30 Pi systemd[1]: Failed to start Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon.
Apr 11 21:11:30 Pi systemd[1]: miflora.service: Service RestartSec=100ms expired, scheduling restart.
Apr 11 21:11:30 Pi systemd[1]: miflora.service: Scheduled restart job, restart counter is at 5.
Apr 11 21:11:30 Pi systemd[1]: Stopped Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon.
Apr 11 21:11:30 Pi systemd[1]: miflora.service: Start request repeated too quickly.
Apr 11 21:11:30 Pi systemd[1]: miflora.service: Failed with result 'exit-code'.
Apr 11 21:11:30 Pi systemd[1]: Failed to start Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon.

I restart the daemon manually and it works well.

Can you help me?

Ciao

Stefano

@ThomDietrich
Copy link
Owner

Hey!
Probably an issue with the availability of resources. Is the MQTT broker installed on the same system? Check if you have the latest service file version, which has a dependency on the network target.

https://github.com/ThomDietrich/miflora-mqtt-daemon#continuous-daemonservice

@martellucci
Copy link
Author

The MQTT broker is on different server with different IP, but same LAN. The file is the last version.

Ciao

@user34756361233
Copy link

user34756361233 commented Oct 16, 2020

I see exactly the same after a (or any) reboot on my Rpi 3B:

han@mediamachine:~ $ 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: failed (Result: exit-code) since Fri 2020-10-16 19:52:32 UTC; 1h 21min ago
     Docs: https://github.com/ThomDietrich/miflora-mqtt-daemon
  Process: 712 ExecStart=/usr/bin/python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py (code=exited, status=1/FAILURE)
 Main PID: 712 (code=exited, status=1/FAILURE)
   Status: "Oct 16 19:52:32 - MQTT connection error. Please check your settings in the configuration file "config.ini"."

Oct 16 19:52:32 mediamachine systemd[1]: miflora.service: Unit entered failed state.
Oct 16 19:52:32 mediamachine systemd[1]: miflora.service: Failed with result 'exit-code'.
Oct 16 19:52:32 mediamachine systemd[1]: miflora.service: Service hold-off time over, scheduling restart.
Oct 16 19:52:32 mediamachine systemd[1]: Stopped Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon.
Oct 16 19:52:32 mediamachine systemd[1]: miflora.service: Start request repeated too quickly.
Oct 16 19:52:32 mediamachine systemd[1]: Failed to start Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon.
Oct 16 19:52:32 mediamachine systemd[1]: miflora.service: Unit entered failed state.
Oct 16 19:52:32 mediamachine systemd[1]: miflora.service: Failed with result 'exit-code'.

When the service is started again, everything is normal again.

han@mediamachine:~ $ sudo systemctl start miflora.service
han@mediamachine:~ $ 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 Fri 2020-10-16 21:15:47 UTC; 34s ago
     Docs: https://github.com/ThomDietrich/miflora-mqtt-daemon
 Main PID: 2843 (python3)
   Status: "Oct 16 21:16:10 - Status messages published."
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/miflora.service
           └─2843 /usr/bin/python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py

Oct 16 21:15:46 mediamachine systemd[1]: Starting Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon...
Oct 16 21:15:47 mediamachine systemd[1]: Started Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon.
han@mediamachine:~ $

MQTT is running on another system.

tia Han

@user34756361233
Copy link

I added a wait in the service definition:

[Unit]
Description=Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
Documentation=https://github.com/ThomDietrich/miflora-mqtt-daemon
After=network.target bluetooth.service mosquitto.service

[Service]
Type=notify
User=daemon
Group=daemon
WorkingDirectory=/opt/miflora-mqtt-daemon/
ExecStartPre=/bin/sleep 30.  **<-------------------**
ExecStart=/usr/bin/python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py
StandardOutput=null
#StandardOutput=syslog
#SyslogIdentifier=miflora
StandardError=journal
Environment=PYTHONUNBUFFERED=true
Restart=always

[Install]
WantedBy=multi-user.target

It looks like this delay helps. I guess the MQTT problem is caused by a service that has not fully started when miflora tries to use it.

tia Han

@OnnoH
Copy link

OnnoH commented Oct 17, 2020

IMHO the daemon should wait for the MQTT server to become available and gracefully shutdown if it doesn't reach it within a certain timeframe.

https://blog.miguelgrinberg.com/post/how-to-make-python-wait

Happy to help if I can squeeze it in my busy schedule ;-)

@benginx
Copy link

benginx commented Mar 9, 2021

Hey, unfortunately I have the same problem. Suddenly it stopped working and I can't figure out why. The MQTT Broker (mosquito) is running on a different server inside my LAN and anther service is able to use ist. And even this great tool was able some days before.

The log says only to check the config.ini but this is purely minimalistic.

Is there any way to see what actually failed?

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 Tue 2021-03-09 11:44:29 CET; 2s ago
     Docs: https://github.com/ThomDietrich/miflora-mqtt-daemon
  Process: 7697 ExecStart=/usr/bin/python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py (code=exited, status=1/FAILURE)
 Main PID: 7697 (code=exited, status=1/FAILURE)
   Status: "Mar 09 11:44:29 - MQTT connection error. Please check your settings in the configuration file "config.ini"."

Can you help me?
Thanks

Ben

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

5 participants