diff --git a/.gitignore b/.gitignore index 4dc4cec..47ba363 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +config.py + # ---> Linux *~ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..fa2204f --- /dev/null +++ b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "mqtt"] + path = mqtt + url = https://git.mount-mockery.de/pylib/mqtt.git +[submodule "report"] + path = report + url = https://git.mount-mockery.de/pylib/report.git +[submodule "task"] + path = task + url = https://git.mount-mockery.de/pylib/task.git diff --git a/example_config/config.py b/example_config/config.py new file mode 100644 index 0000000..0427260 --- /dev/null +++ b/example_config/config.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- +import os +import report + +__BASEPATH__ = os.path.abspath(os.path.dirname(__file__)) + +MQTT_USER = "user" +MQTT_PASS = "pass" +MQTT_SERVER = "host" + +TOPIC = 'topic' +PAYLOAD = b'payload' +COMMAND = "aplay ring.wav -D plughw:UACDemoV10,0" + +# +# Logging +# +APP_NAME = "exec_command" +LOGTARGET = 'stdout' # possible choices are: 'logfile' or 'stdout' +LOGLVL = 'DEBUG' + +LOGHOST = 'cutelog' +LOGPORT = 19996 + +formatter = report.SHORT_FMT diff --git a/exec_command.py b/exec_command.py new file mode 100644 index 0000000..a66b68f --- /dev/null +++ b/exec_command.py @@ -0,0 +1,49 @@ +import config +import logging +import mqtt +import os +import report +import task +import time + +try: + from config import APP_NAME as ROOT_LOGGER_NAME +except ImportError: + ROOT_LOGGER_NAME = 'root' +logger = logging.getLogger(ROOT_LOGGER_NAME).getChild('main') + + +class exec_command(mqtt.mqtt_client, task.threaded_queue): + def __init__(self): + self.__block_execution__ = False + task.threaded_queue.__init__(self) + mqtt.mqtt_client.__init__(self, config.APP_NAME, config.MQTT_SERVER, 1883, config.MQTT_USER, config.MQTT_PASS) + self.add_callback(config.TOPIC, self.mqtt_rx) + + def exec_command(self, rt): + os.system(config.COMMAND) + self.__block_execution__ = False + + + def mqtt_rx(self, client, userdate, message): + if not self.__block_execution__: + if message.payload == config.PAYLOAD: + logger.debug("Starting execution in background...") + self.__block_execution__ = True + self.enqueue(5, self.exec_command) + else: + logger.debug("Execution in progress. Ignoring request...") + + +if __name__ == '__main__': + report.appLoggingConfigure(config.__BASEPATH__, config.LOGTARGET, ((config.APP_NAME, config.LOGLVL), ), fmt=config.formatter, host=config.LOGHOST, port=config.LOGPORT) + # + ec = exec_command() + ec.run() + # + while True: + time.sleep(30) + try: + ec.join() + finally: + ec.stop() diff --git a/exec_command.sh b/exec_command.sh new file mode 100755 index 0000000..93d38c5 --- /dev/null +++ b/exec_command.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# +BASEPATH=`dirname $0` +$BASEPATH/venv/bin/python $BASEPATH/exec_command.py \ No newline at end of file diff --git a/mqtt b/mqtt new file mode 160000 index 0000000..cf97fa0 --- /dev/null +++ b/mqtt @@ -0,0 +1 @@ +Subproject commit cf97fa066cdff0e2f7eda0ff4d3c8c0f59c3f2ec diff --git a/report b/report new file mode 160000 index 0000000..21bac82 --- /dev/null +++ b/report @@ -0,0 +1 @@ +Subproject commit 21bac82e0c459ebf6d34783c9249526a657a6bbd diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8579e8b --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +paho-mqtt diff --git a/ring.wav b/ring.wav new file mode 120000 index 0000000..52a944f --- /dev/null +++ b/ring.wav @@ -0,0 +1 @@ +sounds/phone-incoming-call.wav \ No newline at end of file diff --git a/sounds/phone-incoming-call.wav b/sounds/phone-incoming-call.wav new file mode 100644 index 0000000..b59ce6c Binary files /dev/null and b/sounds/phone-incoming-call.wav differ diff --git a/sounds/suspend-error.wav b/sounds/suspend-error.wav new file mode 100644 index 0000000..5a02abe Binary files /dev/null and b/sounds/suspend-error.wav differ diff --git a/task b/task new file mode 160000 index 0000000..7583bb5 --- /dev/null +++ b/task @@ -0,0 +1 @@ +Subproject commit 7583bb5f3bd2420c901374ba95b678af6ce88433