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

Run on startup #29

Closed
QuagmireMan opened this issue Jun 25, 2018 · 7 comments
Closed

Run on startup #29

QuagmireMan opened this issue Jun 25, 2018 · 7 comments

Comments

@QuagmireMan
Copy link

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

eschava commented Jun 25, 2018

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

QuagmireMan commented Jun 25, 2018

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

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

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

eschava commented Sep 3, 2018

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

pabloreadi commented Sep 19, 2018

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

  • I must ran cmd like an administrator
  • nssm install servicename
  • then in edit windows:
    path: C:\Python27\python.exe
    Startup directory: directory where is mqtt.py
    Arguments: mqtt.py
    then save
  • then again in cmd
    nssm set mqttpy appnoconsole 1

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

@VincentSC
Copy link

VincentSC commented May 18, 2020

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
[email protected]

[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

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

4 participants