eschava / broadlink-mqtt

MQTT client to control BroadLink devices
MIT License
222 stars 60 forks source link

Run on startup #29

Closed QuagmireMan closed 6 years ago

QuagmireMan commented 6 years ago

I am trying to have the mqtt.py run on startup. I added python /home/openhabian/broadlink-mqtt/mqtt.py & to rc.local, but it did not seem to trigger the script.

I also get errors when trying to execute mqtt.py from node red.
Traceback (most recent call last): File "mqtt.py", line 3, in <module> import paho.mqtt.client as paho # pip install paho-mqttImportError: No module named paho.mqtt.client

I assume that has to do with the way paho was installed and it can't find the module... but I haven't figured that out either. I am assuming they might be related.

Is it something simple I am missing?

eschava commented 6 years ago

Maybe startup script runs mqtt.py under the root user while paho-mqtt library is installed for regular user? Please try to execute sude pip install paho-mqtt

QuagmireMan commented 6 years ago

Installed it with sudo, and I am still having the same issue.

If I run with python3 i get File "/home/openhabian/broadlink-mqtt/mqtt.py", line 67 except Exception, e: ^SyntaxError: invalid syntax

QuagmireMan commented 6 years ago

Well, it looks like i needed to install broadlink with sudo and it fixed the problem. sudo pip install paho-mqtt broadlink

Thank you for the help!

pabloreadi commented 6 years ago

hello, I'm windows user and I run on startup mqtt.py and it's ok. I need to know if mqtt.py can run like a service?

eschava commented 6 years ago

Sorry, I have no experience with Windows services. Somebody on the StackOverflow suggested using http://nssm.cc/ for managing user services Could you please try it and tell if it helps

pabloreadi commented 5 years ago

I tried it and it's works fine!! I use Windows 10, then I downloaded the last version,

You have mqtt.py like a service, and you can see it in your Services.

VincentSC commented 4 years ago

For documentation

sudo pip install paho-mqtt broadlink

sudo nano /lib/systemd/system/broadlink-mqtt.service


[Unit]
Description=Broadlink MQTT Service
After=multi-user.target
Conflicts=getty@tty1.service

[Service] Type=simple ExecStart=/usr/bin/python3 /home/pi/broadlink-mqtt/mqtt.py StandardInput=tty-force

[Install] WantedBy=multi-user.target


> sudo systemctl daemon-reload
> sudo systemctl start broadlink-mqtt.service
> sudo systemctl status broadlink-mqtt.service