Giter VIP home page Giter VIP logo

mqtt-launcher's Introduction

I'm a small-scale fiddler who enjoys doing and teaching. I wrote a thick book on FLOSS DNS servers and dreamed up OwnTracks over MQTT. Oh, and I invented NOCOWS=1 for Ansible.

I blog and I toot.

mqtt-launcher's People

Contributors

aergernis avatar dybm avatar inos-github avatar jpmens avatar juzam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mqtt-launcher's Issues

transfer number from topic to exec

Hi,
Thank you for this script,
it is possible to transfer a value from the topic to the exec?
for example:

topiclist = {

# topic                     payload value       program & arguments
"exec_switcher"          :   {
                            'value'        :   [ "/usr/bin/python2", '/home/switcher.py',"value"],
                        },

}

the topic will be for example exec_switcher and the payload: 11 and the exec will be /home/switcher.py 11
is there any option for this?

Seems to be missing mqtt messages

I'm using mqtt-launcher on Ubuntu 18.04.1 to run a shell script that grabs camera images then e-mails them to me. It works great for the most part but I've been noticing that mqtt-launcher is missing mqtt messages pretty consistently.

If I check the log file, I can see that mqtt-launcher has not detected a message but I can see in my smartthings-mqtt-bridge that the message has been received. I can see in the mosquito logs that mosquito is receiving it from the bridge. I also started an mqtt client on my laptop and subscribed to the message and it's receiving the message no problem as well.

Here's a sample of the log file. You can see at 14:39:08, the contact open was detected and the driveway.sh file was run. However, at 14:36:11, it only caught it as closed which I have no definition for in the config file. An open message was sent and received by other listening mqtt clients.

2019-09-16 14:29:08,993 smartthings/Driveway Motion/contact 0 open
2019-09-16 14:29:08,995 Running t=smartthings/Driveway Motion/contact: ['/bin/sh', '/opt/mqtt-launcher/driveway.sh']
2019-09-16 14:36:11,251 smartthings/Driveway Motion/contact 0 closed
2019-09-16 14:36:11,252 No matching param (closed) for smartthings/Driveway Motion/contact
2019-09-16 14:50:40,542 smartthings/Front Porch Motion Detector/motion 0 inactive

Any ideas what may be causing this?

Edit: I just noticed from the above log that it didn't catch the closed message at 14:29 either. Just the open.

What causes this loop?

Hello,

for some reason, I get a loop:

henfri@raspberrypi:~$ tail -f /var/log/mqtt-launcher.log
2020-03-17 20:15:18,930 DEBUG MODE
2020-03-17 20:15:49,947 Starting
2020-03-17 20:15:49,950 DEBUG MODE
2020-03-17 20:16:20,937 Starting
2020-03-17 20:16:20,940 DEBUG MODE
2020-03-17 20:16:21,003 Connected to MQTT broker, subscribing to topics...
2020-03-17 20:16:21,022 Device/action 1 unlock
2020-03-17 20:16:21,030 Running t=Device/action: ['/usr/local/bin/Device_launcher.sh', 'unlock']
2020-03-17 20:17:26,546 Device/action 1 lock
2020-03-17 20:17:26,550 Running t=Device/action: ['/usr/local/bin/Device_launcher.sh', 'lock']
2020-03-17 20:18:20,369 Device/action 1 lock
2020-03-17 20:18:20,373 Running t=Device/action: ['/usr/local/bin/Device_launcher.sh', 'lock']

This repeats again and again.
But this is not caused by a command coming via mqtt. Monitoring at the same time:

root@homeserver:~# mosquitto_sub -h localhost -t "#" -v -u henfri -P xxxx | grep Device
Device/action lock
Device/action lock
Device/action/report MOVING
Device/action/report MOVING

What could cause these repeating messages?

Greetings,
Hendrik

Script only executed once

Hi JP
first I would like to thank you for sharing this program!
It works great with the example configuration but not so much with mine.
Here is my configuration:

logfile = 'logfile'
mqtt_broker = '192.168.1.120'       # default: 'localhost'
mqtt_port = 1883                # default: 1883
mqtt_clientid = 'mqtt-launcher-1'
mqtt_username = ''
mqtt_password = ''

topiclist = {

    # topic                     payload value       program & arguments
    "dak/screen"          :   {
                                'off' :   [ '/home/pi/ir_scripts/rpi-hdmi.sh', 'off' ],
                                'on'  :   [ '/home/pi/ir_scripts/rpi-hdmi.sh', 'on'],
                               },
}

I start mqtt-launcher from the command line as user pi.
Then I send (from Node-Red) Topic: dak/screen Payload: on (QoS 2, Retain false) which works ok.
Then I send Topic: dak/screen Payload: off which usually works too (but not always) but then no other commands are accepted. No matter what I send, it is just ignored. Nothing shows up in the log.
But obviously the commands I send are stored somewhere because when I stop mqtt-launcher and start it again, all the previous commands are executed immediately.

2018-02-24 12:16:03,827 Starting
2018-02-24 12:16:03,829 DEBUG MODE
2018-02-24 12:16:03,848 Connected to MQTT broker, subscribing to topics...
2018-02-24 12:16:11,637 dak/screen 2 on
2018-02-24 12:16:11,645 Running t=dak/screen: ['/home/pi/ir_scripts/rpi-hdmi.sh', 'on']
--- This time only one command was executed
2018-02-24 12:18:33,811 Starting
2018-02-24 12:18:33,813 DEBUG MODE
2018-02-24 12:18:33,830 Connected to MQTT broker, subscribing to topics...
2018-02-24 12:18:33,925 dak/screen 2 off
2018-02-24 12:18:33,931 Running t=dak/screen: ['/home/pi/ir_scripts/rpi-hdmi.sh', 'off']
2018-02-24 12:18:34,063 display_power=0
2018-02-24 12:18:34,072 dak/screen 2 on
2018-02-24 12:18:34,075 Running t=dak/screen: ['/home/pi/ir_scripts/rpi-hdmi.sh', 'on']
---After restart all the previously sent commands are executed

Any idea what is going wrong here?

Hermann

Run as SystemD Service

Hello,

thanks for mqtt-launcher!
I would like to share some knowledge on how I run it as systemd-service:

/etc/systemd/system/Smartlock.service
[Unit]
Description=Smartlock
Require = network-online.target
After = network-online.target

[Service]
Type=simple
Environment=MQTTLAUNCHERCONFIG=/usr/local/bin/launcher.conf
WorkingDirectory=/usr/local/bin
ExecStart=/usr/bin/python /usr/local/bin/mqtt-launcher.py
Restart=always
StandardInput=tty-force
StandardOutput=tty
TTYPath=/dev/tty11

[Install]
WantedBy=multi-user.target

Now this did not work, and I suspected, it was due to the problem, that the config-file was not found. thus, I hardcoded the config file in the /usr/local/bin/mqtt-launcher.py;
Not sure, this was neccessary though.

Then, the final problem seemed to be, that something (network?) was not ready yet. At least the service worked when launching it a while after boot, but it did not work when running during boot.

Thus, I changed mqtt-launcher.py:

#CONFIG=os.getenv('MQTTLAUNCHERCONFIG', 'launcher.conf')
CONFIG="/usr/local/bin/launcher.conf"
time.sleep(30)

With this, it is working.

Hope, this helps someone, and maybe someone can comment.

Gretings,
Hendrik

Blocking commands result in queued actions.

Thank you for this - it's very good and useful!

I spotted a feature that when a command is running and there is a likelihood of a second mqtt message pattern being matched the first command blocks the next until complete. While this is OK for short running commands or scripts it can cause a problem with queued messages and unresponsive switches.

My situation is Smartthings, motion detected which triggers a camera capture (which then sleeps for 30 seconds) and then I tried to issue a virtual switch command but it was not-responsive. The log seemed to show the commands queue and then fire once the first command finishes - I am sure this is by design.

2021-04-24 18:49:33,382 smartthings/Driveway Motion/motion/state 0 active
2021-04-24 18:49:33,389 Running t=smartthings/Driveway Motion/motion/state: ['sudo', '/home/pi/ha/getimages']
2021-04-24 18:50:06,856 smartthings/Garage/switch/state 0 off
2021-04-24 18:50:06,860 Running t=smartthings/Garage/switch/state: ['/home/pi/ha/garage.py']

So the fix is for me to put the first command into the background but may be worth noting this in the example config so others don't trip over it.

Thanks a lot!
Ian

Execute sudo command

Hi,
thank you for your code it's truly what i was looking for. My only question is if it is possible to execute a program that require sudo privileges through an mqtt payload. I've tried quite a lot but with any success.
Thank you

Mark

expand command

Hi,

From the command line I'm doing this:

~$ mosquitto_pub -h localhost -t test/$(hostname)/clients_connected -m $(mosquitto_sub -h localhost -C 1 -t \$SYS/broker/clients/connected)
~$ mosquitto_sub -t test/# -h localhost -v
test/revo/clients_connected 1

Is there a way to get it working in the config file?

I tried this:

"launcher/mosquitto":{
  'local':[
     'mosquitto_pub',
     '-h',
     'localhost',
     '-t',
     'status/$(hostname)/clients_connected',
     '-m',
     '$(mosquitto_sub -h localhost -C 1 -t \$SYS/broker/clients/connected)'
  ],

but the commands don't get expanded:

~$ mosquitto_sub -h localhost -t status/# -v
status/$(hostname)/clients_connected $(mosquitto_sub -h localhost -C 1 -t \$SYS/broker/clients/connected)

argument

hi,
i want to run a python file with mqtt launcher ,how the argument will be ,i am new at python

Breaks on paho-mqtt version 1.3

Hi

I've used your program for a long time and couldn't understand why it didn't work on a new machine. Turns out it works fine on ubuntu with paho-mqtt 1.2 from pip, but fails with paho-mqtt 1.3.

Error:

:~/mqtt-launcher-master$ ./mqtt-launcher.py 
Traceback (most recent call last):
  File "./mqtt-launcher.py", line 155, in <module>
    mqttc.loop_forever()
  File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1470, in loop_forever
    rc = self.loop(timeout, max_packets)
  File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 995, in loop
    rc = self.loop_read(max_packets)
  File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1273, in loop_read
    rc = self._packet_read()
  File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 1838, in _packet_read
    rc = self._packet_handle()
  File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 2291, in _packet_handle
    return self._handle_connack()
  File "/usr/local/lib/python2.7/dist-packages/paho/mqtt/client.py", line 2349, in _handle_connack
    self.on_connect(self, self._userdata, flags_dict, result)
TypeError: on_connect() takes exactly 3 arguments (4 given)

Fails when run in Background

Probably my fault, I hope you can help.
When I run MQTT-launcher via the terminal it works well and it reports the output of the shell script I run with it.
But when I try to run it in background (with disown - I know its, bad..) it always fails with *****> Command 'MYCOMAND' returned non-zero exit status 1
I looked into this python problem and tried to solve it myself (subprocess, path), but none of my attempts worked..

Or is there a better way to run it in background?
Unrelated question: Does mqttwarn have this very helpful report function, where it responds with the output of the command? Because that would make me switch to mqttwarn for my purpose.

I hope you can help me.

Script work under Windows with Python

Good day!
Thank you very much for your work.

I have never studied programming, this is just my hobby.
Now I am learning a smart home with MQTT and want to control my home computer.

I have successfully run your script in Windows 10 with python, but I can't figure out which command syntax to use to execute .exe or .bat files when getting certain values ​​in topics.

Can you tell me how to solve this issue?

bash script will not execute

Bash script is executable and can be executed ./ipdoorhassio.sh will execute from cmd,


topiclist = {

    # topic                     payload value       program & arguments
    "signal"          :   {
                                'ipdoorhassio'        :   [ './ipdoorhassio.sh' ],
                                'iplobbyhassio'       :   [ '/home/iplobbyhassio.sh'    ],
                                'test'                :   [ 'echo', 'hello'],`
```2020-04-17 02:29:32,035 DEBUG MODE
2020-04-17 02:29:34,198 Connected to MQTT broker, subscribing to topics...
2020-04-17 02:29:39,205 signal 0 ipdoorhassio
2020-04-17 02:29:39,208 Running t=signal: ['./ipdoorhassio.sh']
2020-04-17 02:29:40,025 signal 0 ipdoorhassio
2020-04-17 02:29:40,025 Running t=signal: ['./ipdoorhassio.sh']
2020-04-17 02:29:40,528 signal 0 ipdoorhassio
2020-04-17 02:29:40,529 Running t=signal: ['./ipdoorhassio.sh']
2020-04-17 02:29:40,976 signal 0 ipdoorhassio
2020-04-17 02:29:40,977 Running t=signal: ['./ipdoorhassio.sh']
2020-04-17 02:29:41,334 signal 0 ipdoorhassio
2020-04-17 02:29:41,335 Running t=signal: ['./ipdoorhassio.sh']




Keepalive, timeout and client disconnection

Hi there !
Thanks for your package ! It is awesome and of great help

I'm having an issue where in the case of a long process, I run into client disconnection
I receive this error
Client mqtt-launcher-1 has exceeded timeout, disconnecting

I believe it has to do with the PINGREQ, PINGRESP that are not sent while the process is run.
I have set the keepalive value of mqttc.connect to 65535, but I'm not sure it is viable...

Do you have any idea on how to send back a PINGREQ from the mqtt-launcher while a process is running ?

I also thought of running multiple python instances of the launcher, again a workaround and not very scalable

Thanks in advance and again thank you for your work

Edit : Simply put, how to reconnect if my process takes longer than the keepalive interval ?

Don't know why the command is not executed

Hello,
I want to use your code in my smarthome with OpenHAB 2.5 + MQTT (mosquitto). Setting up and trying it out was pretty easy, I just had to adjust the path for the .conf file.

Everything seems to be fine in the .log file:

However, the script is not executed and I cannot find any reason why.

OpenHAB and Mosquitto run on a Debian 10, your code and my scripts run on a RasberryPI with rasbian (debian 9)
and should also work on an Arduino in the future.

my .conf

logfile         = '/var/log/mosquitto/mqtt-launcher.log'
mqtt_broker     = 'home-server'       
mqtt_port       = 1883              
mqtt_clientid   = 'mqtt-launcher-1'
mqtt_username   = 'xxxx'
mqtt_password   = 'xxxxxxx'
mqtt_tls        = None              # default: No TLS

topiclist = {
# topic                         payload value           program & arguments
"433Mhz/Licht/Aqua"  :  { 'ON' : [ '/usr/bin/send-OH2', '11000 00100 1', ],
                                             'OFF': [ '/usr/bin/send-OH2', '11000 00100 0' ],
                        }
}

the .log file

2020-11-29 10:41:06,557 Starting
2020-11-29 10:41:06,560 DEBUG MODE
2020-11-29 10:41:06,592 Connected to MQTT broker, subscribing to topics...
2020-11-29 10:41:06,838 433Mhz/Licht/Aqua 1 ON
2020-11-29 10:41:06,845 Running t=433Mhz/Licht/Aqua: ['/usr/bin/send-OH2', '11000 00100 1']
2020-11-29 10:46:12,828 Starting
2020-11-29 10:46:12,839 DEBUG MODE
2020-11-29 10:46:12,878 Connected to MQTT broker, subscribing to topics...
2020-11-29 10:46:13,078 433Mhz/Licht/Aqua 1 ON
2020-11-29 10:46:13,088 Running t=433Mhz/Licht/Aqua: ['/usr/bin/send-OH2', '11000 00100 1']

Thanks for your help

greeting
JP

Possible to run programs in the background?

I'm trying to leverage this to turn a raspi into a noise machine controlled by mqtt in node red.

When I send the topic for my play script, it keeps the mqtt busy so it can't see the topic to run the stop command.

Do you know of a way that It could start the process in the background so it can listen for more events?

2020-06-26 06:47:26,217 Starting
2020-06-26 06:47:26,221 DEBUG MODE
2020-06-26 06:47:26,584 Connected to MQTT broker, subscribing to topics...
2020-06-26 06:47:54,167 prog/play 0 None
2020-06-26 06:47:54,171 Running t=prog/play: ['nohup', '/root/soundmachine/play.sh', '&']

How do you get this to run a script?

e.g /root/Scripts/myscript.sh flower, I tried

['/bin/bash', '/root/Scripts/myscript.sh', 'flower']

and

['/root/Scripts/myscript.sh', 'flower']

But it doesn't call the script

Use @!@ as a substring instead of a parameter

Is there a way to use the value of a message as a sub-string of a command parameter?
As far as I can see, @!@ is always a parameter by it's own however I need to append a string to this value... The tool might be much more flexible with this option.

My use case:
the value of a message is a IP address and I have to append a port like ´10.0.0.1:222'

My suggestion:
instead of

87           cmd = []
88           for p in topiclist[topic][None]:
89                if p == '@!@':
90                    p = param
91                    cmd.append(p)
87            cmd = [p.replace('@!@', param) for p in topiclist[topic][None]]

json support

I have a branch with json support https://github.com/clach04/mqtt-launcher/tree/json_config rather than Python code for config.

  1. Any interest in this as a feature? If so, as an additional format or as a replacement for Python - I don't yet have code to support both but it could be done
  2. For Python config support, any thoughts about supporting functions as well as spawning sub-processes? (I do not have code for this :-D)

Commands not being actioned

This is most likely me no understanding the config correctly but.....

I have a simple config like this (credentials excluded):

`
topiclist = {

# topic                     payload value       program & arguments
"intercom/commands"          :   {
                            'shutdown'        :   [ '/usr/bin/sudo shutdown' ],
                            'reboot'         :   [ '/usr/bin/sudo shutdown -r now' ],
                            'update'          :   [ '/usr/bin/sudo apt update && /usr/bin/sudo apt upgrade -y' ],
                        },
"prog/pwd"          :   {
                            None            :   [ 'pwd' ],
                        },
}

`

I can see in the logfile that the script is picking up the MQTT message and identifying the relevant command from the config:

2020-04-20 20:37:41,893 Starting 2020-04-20 20:37:41,894 DEBUG MODE 2020-04-20 20:37:42,551 Connected to MQTT broker, subscribing to topics... 2020-04-20 20:37:46,290 server/actions/intercom/ 0 reboot 2020-04-20 20:37:46,291 Running t=server/actions/intercom/: ['/usr/bin/sudo', 'shutdown -r now']

However, my system isn't being rebooted or anything else that I can see. This command works normally if I run it myself via the cli.

Any idea as to what I'm doing wrong here?

Open URL in Default Browser

I'm using Kubuntu 19.10 and running mqtt-launcher.py as a systemd service on boot. I'm trying to get a URL to open in my default browser Chrome using xdg-open but I get the error "returned non-zero exit status 3". Here is my launcher.conf:

https://pastebin.com/raw/Wngw89fT

I have verified that xdg-open opens the URL fine as the user but errors as root with 'no method available for opening'. I have also tried running the systemd service as the user but get the same error.

I have also tried running mqtt-launcher.py in the user crontab to run on reboot but it does not launch.

Any ideas? Thanks.

Not a real issue - more a problem - maybe depends on Subprocess - Killall does not work in MQTT Command.

Hello,

iam starting a script "cam.sh" with the MQTT launcher. This works fine and the script is running. Topic /camera/on
Now i want to kill that script using "killall -9 cam.sh" with Topic /camera/off.

But /report always shows "returned non-zero exit status 1" and the script is not killed.

I tryed the full Path to killall, too. An tried it with a second bash script containing the killall command. But nothing works.
Does Python Subprocess not allow to kill a process from another subprocess ?

Why i cant use killall -9 with the mqtt-launcher ?

No matching param (OFF) for sound/1/set/report

Hi

I've set up mqtt-launcher to play a sound, but it seems it keeps crashing and I'm having trouble understanding this error.

launcher.conf:

"sound/1/set/report" : {
'state' : [ 'echo', '"OFF"' ],
},
"sound/1/set" : {
'OFF' : [ '/home/pi/mqtt-launcher/buzzset.sh', '1', '0' ],
'ON' : [ '/home/pi/mqtt-launcher/buzzset.sh', '1', '1' ],
},

In home-assistant (may be relevant):

  • platform: mqtt
    name: "Buzzer bop"
    state_topic: "sound/1/set/report"
    command_topic: "sound/1/set"
    payload_on: "ON"
    payload_off: "OFF"
    optimistic: false
    qos: 0
    retain: false

mqtt shows:

clients/mqtt-launcher Adios!
sound/1/set/report OFF
clients/mqtt-launcher Adios!
clients/mqtt-launcher Adios!

mqtt-launchers log says:

2017-08-30 14:31:54,122 Connected to MQTT broker, subscribing to topics...
2017-08-30 14:31:54,136 sound/1/set 0 OFF
2017-08-30 14:31:54,139 Running t=sound/1/set: ['/home/pi/mqtt-launcher/buzzset.sh', '1', '0']
2017-08-30 14:31:54,244 sound/1/set/report 2 OFF
2017-08-30 14:31:54,247 No matching param (OFF) for sound/1/set/report
2017-08-30 14:32:05,138 OOOOPS! launcher disconnects
2017-08-30 14:32:16,168 Connected to MQTT broker, subscribing to topics...
2017-08-30 14:32:16,182 sound/1/set 0 OFF
2017-08-30 14:32:16,187 Running t=sound/1/set: ['/home/pi/mqtt-launcher/buzzset.sh', '1', '0']
2017-08-30 14:32:16,293 sound/1/set/report 2 OFF
2017-08-30 14:32:16,296 No matching param (OFF) for sound/1/set/report
2017-08-30 14:32:27,182 OOOOPS! launcher disconnects
2017-08-30 14:32:38,213 Connected to MQTT broker, subscribing to topics...
...

[Errno 2] No such file or directory

Hi guys

First of all, this is an awesome piece of script - Thank you!!
I am trying to use it to shutdown or wol my servers, but without success.
I think I have defined the parameters well, but the script is raising a "[Errno 2] No such file or directory"
Could you help?

From my .conf:
topiclist = {

# topic                     payload value       program & arguments
"smartthings/Computer openmediavault/switch"  :   
    'wake openmediavault'      :   [ '/usr/bin/wakeonlan', '-p', '7', 'XX:XX:XX:XX:XX:XX' ],
    'shutdown openmediavault'      :   [ '/usr/bin/ssh', 'root@openmediavault', 'shutdown', 'now' ],
 },

}

From the log:
Running t=smartthings/Computer openmediavault/switch: ['/usr/bin/ssh', 'root@openmediavault', 'shutdown', 'now']
2016-08-08 13:01:15,346 Running command: ['/usr/bin/ssh', 'root@openmediavault', 'shutdown', 'now']
2016-08-08 13:01:15,447 Result: *****> Command '['/usr/bin/ssh', 'root@openmediavault', 'shutdown', 'now']' returned non-zero exit status 255

Launcher disconnects

I'm running an ubuntu VM dedicated mqtt server.

Version:

mosquitto version 1.4.14 (build date Tue, 11 Jul 2017 00:29:26 +0100)
mosquitto is an MQTT v3.1.1/v3.1 broker.

Both my clients disconnects all the time.

2017-08-30 14:48:59,627 Connected to MQTT broker, subscribing to topics...
2017-08-30 14:48:59,645 OOOOPS! launcher disconnects
2017-08-30 14:49:10,656 Connected to MQTT broker, subscribing to topics...
2017-08-30 14:49:10,662 OOOOPS! launcher disconnects
2017-08-30 14:49:21,670 Connected to MQTT broker, subscribing to topics...
2017-08-30 14:49:21,688 OOOOPS! launcher disconnects
2017-08-30 14:49:32,700 Connected to MQTT broker, subscribing to topics...
2017-08-30 14:49:32,707 OOOOPS! launcher disconnects
2017-08-30 14:49:43,717 Connected to MQTT broker, subscribing to topics...
2017-08-30 14:49:43,735 OOOOPS! launcher disconnects
2017-08-30 14:49:54,747 Connected to MQTT broker, subscribing to topics...
2017-08-30 14:49:54,749 OOOOPS! launcher disconnects
2017-08-30 14:50:04,756 OOOOPS! launcher disconnects
2017-08-30 14:50:15,767 Connected to MQTT broker, subscribing to topics...
2017-08-30 14:50:15,785 OOOOPS! launcher disconnects
2017-08-30 14:50:26,798 Connected to MQTT broker, subscribing to topics...
2017-08-30 14:50:26,803 OOOOPS! launcher disconnects
2017-08-30 14:50:37,815 Connected to MQTT broker, subscribing to topics...
2017-08-30 14:50:37,834 OOOOPS! launcher disconnects
2017-08-30 14:50:48,840 Connected to MQTT broker, subscribing to topics...
2017-08-30 14:50:48,851 OOOOPS! launcher disconnects

Any idea why?

double subcription on startup

starting the program, the client subscribes twice to the topics. This leads to a repeated execution of commands for retained messages.

subscription is done in on_connect(...) and again in line 154

Usage of payload within arguments

Hi,
is it possible to subscribe for a topic which can have individual payloads like an URL and then use this URL within the execution arguments?

Would be great.
THX

Running ssh does not work

I want to shut down my QNAP NAS remotely via SSH using your python script (thanks! it already works great for waking that NAS up via wakeonlan)

This is my config:

logfile         = '/home/user/mqtt-launcher/logfile'
mqtt_broker     = 'broker'       # default: 'localhost'. If using TLS, this must be set to the domain name signed by$
mqtt_port       = 1883              # default: 1883
mqtt_clientid   = 'mqtt-launcher-1-nas-poweroff'
mqtt_username   = ''
mqtt_password   = ''
mqtt_tls        = None              # default: No TLS

topiclist = {

    # topic                     payload value       program & arguments
	"nas/off"	:	{
					'0'	:	[ 'ssh -i /home/user/.ssh/ssh_privatekey user@nas-hostname /share/homes/admin/shutdown.sh', '' ],
				}
}

When I run 'ssh -i /home/user/.ssh/ssh_privatekey admin@nas /share/homes/admin/shutdown.sh directly from the command line, it works. But with mqtt-launcher, I had no success yet.

Here is an excerpt from the logs (you can see I tried passing the script as an argument in the second attempt). But in both cases, nothing happens.

2018-12-15 17:32:31,193 nas/off 1 0
2018-12-15 17:32:31,194 Running t=nas/off: ['ssh -i /home/user/.ssh/ssh_privatekey admin@nas /share/homes/admin/shutdown.sh', '']
2018-12-15 17:33:15,374 Starting
2018-12-15 17:33:15,375 DEBUG MODE
2018-12-15 17:33:15,662 Connected to MQTT broker, subscribing to topics...
2018-12-15 17:33:15,820 nas/off 1 0
2018-12-15 17:33:15,822 Running t=nas/off: ['ssh -i /home/user/.ssh/ssh_privatekey admin@nas', '/share/homes/admin/shutdown.sh']

No matching param...

Hi guys
please tell me what I am doing wrong here...
I have several Raspi's running mqtt-launcher and they all run fine - except one.
This is launcher.conf:

logfile         = 'logfile'
mqtt_broker     = '192.168.1.120'
mqtt_port       = 1883
mqtt_clientid   = 'dashxxx384756934'
mqtt_username   = ''
mqtt_password   = ''

topiclist = {

    # topic                     payload value       program & arguments
    "dashboard/screen"  :   {
                                'off'        :   [ '/home/pi/mqtt-launcher/rpi_hdmi_off.sh' ],
                                'on'         :   [ '/home/pi/mqtt-launcher/rpi_hdmi_on.sh'  ],
                            },
}

When I send e.g topic: dashboard/screen message: off I see in the logfile:

2021-01-05 21:44:28,856 Starting
2021-01-05 21:44:28,857 DEBUG MODE
2021-01-05 21:44:28,868 Connected to MQTT broker, subscribing to topics...
2021-01-05 21:44:35,675 dashboard/screen 0 off
2021-01-05 21:44:35,681 No matching param (off) for dashboard/screen
2021-01-05 21:52:16,936 dashboard/screen 0 off
2021-01-05 21:52:16,937 No matching param (off) for dashboard/screen

I used mosquitto_pub, MQTT Eplorer and Home Assistant to send the message, always the same.
I copied a working launcher.conf from one of the other Raspi's, no change... I downloaded the current mqtt-launcher.py - you guessed it - same. These Raspi's are all running on Rasbian Stretch.

What am I doing wrong here?

Program arguments from payload

Hi @jpmens thanks for this great experiment!

I was thinking to implement a simple mqtt media player on linux which could be use to play TTS messages from Home Assistant.
It's very simple, HA renders the TTS stream as an MP3 available on its own server via http protocol, so something like
mplayer -volume 80 http://home.assistant.address:8123/api/tts_proxy/6a0efdf280bf8c79a.mp3
shot from the command line would play the sound.

The goal is to be able to get the URL from the payload because that changes every time, at every message spoken.
So with mqtt-launcher we would need a variable containing the payload to be accessed in the program & arguments part of the config. For example sending the URL above to the topic mybox/mediaplay could be decoded with a special key like @payload@:

# topic         payload value           program & arguments
"mybox/mediaplay"  :   {
                    '@payload@'        :   [ 'mplayer', '-volume', '80', '@payload@'],
                },

Or anything similar...
What do you think?

Difficulty running python script with mqtt-launcher

Hello!

In launcher.conf I've written:

    "test/message"      :   {
                               'keith2'            :   [ "/home/pi/Documents",
                                                      'python',
                                                      'keith1.py'],
                            }

I've also tried [ "/home/pi/Documents", '/usr/bin/python', 'keith1.py']

And when I publish "keith2" on the topic test/message I see in the log
Running t=test/message: ['/home/pi/Documents', 'python', 'keith1.py']
Yet the python script doesn't run? It runs properly if executed manually in the command line.

Is there a silly error I could be making?

I've posted keith1.py below; the general context is using pyvisa to send commands through Rs232 from a Raspberry Pi to a Keithley 2401 sourcemeter, and running the .py script remotely over MQTT from another machine on the same topic thread

import visa 
import time 
rm = visa.ResourceManager('@py') 
address = "ASRL/dev/ttyUSB0::INSTR"
inst = rm.open_resource(address) 
inst.write("*RST") print(inst.query("*IDN?")) 
inst.write("FORM:DATA ASCII") 
inst.write(“:SYSt:BEEP 100, 3“)
inst.close()

Thank you!

Raspbian GNU/Linux 10
Python 2.7

Execute bash scripts

I have an implementation of mqtt in a Raspberry and a number of sensors that publish to topics. Each sensor writes to individual topic. I would like to call some bash scripts in case of a sensor is enabled. For example if topic /home/burglar/master_bedroom_window is enabled, then execute script /home/atuxnull/scripts/a.sh
if topic /home/burglar/gront_door is enabled, then execute script /home/atuxnull/scripts/b.sh and the list goes on.
Pretty basic question here but how do i install the mqtt-launchet and how do i make it each one of the scenario's call particular scripts?

"Command returned non-zero exit status 2"

I'm not sure if the issue is with mqtt-launcher or with https://github.com/haim0n/python-mirobo.
My conf-file:

logfile         = 'logfile'
mqtt_broker     = 'localhost'       # default: 'localhost'. If using TLS, this must be set to the domain name signed by your TLS certificate.
mqtt_port       = 1883              # default: 1883
mqtt_clientid   = 'mqtt-launcher-1'
mqtt_username   = 'user'
mqtt_password   = 'password'
mqtt_tls        = None              # default: No TLS

topiclist = {

    # topic                     payload value       program & arguments
    "vacuum/control"          :   {
                                'start'        :   [ '/usr/local/bin/mirobo', '--ip 192.168.1.10', '--token 000000', 'start' ],
                                'home'          :   [ '/usr/local/bin/miiocli', 'vacuum', '--ip 192.168.1.10', '--token 000000', 'home' ],
                            },
}

vacuum/control/reports prints:

*****> Command '['/usr/local/bin/mirobo', '--ip 192.168.1.10', '--token 000000', 'start']' returned non-zero exit status 2

As you can see, I've tried both "mirobo" and "miiocli", same results.
If I copy the command and run it manually, it works.

Any idea?
Can I somehow see the output of the command, not jsut the exit status? That might help me in the right direction...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.