Browse Source

Initial version - ring

master
Dirk Alders 2 years ago
parent
commit
f8284b51ef
12 changed files with 95 additions and 0 deletions
  1. 2
    0
      .gitignore
  2. 9
    0
      .gitmodules
  3. 26
    0
      example_config/config.py
  4. 49
    0
      exec_command.py
  5. 4
    0
      exec_command.sh
  6. 1
    0
      mqtt
  7. 1
    0
      report
  8. 1
    0
      requirements.txt
  9. 1
    0
      ring.wav
  10. BIN
      sounds/phone-incoming-call.wav
  11. BIN
      sounds/suspend-error.wav
  12. 1
    0
      task

+ 2
- 0
.gitignore View File

@@ -1,3 +1,5 @@
1
+config.py
2
+
1 3
 # ---> Linux
2 4
 *~
3 5
 

+ 9
- 0
.gitmodules View File

@@ -0,0 +1,9 @@
1
+[submodule "mqtt"]
2
+	path = mqtt
3
+	url = https://git.mount-mockery.de/pylib/mqtt.git
4
+[submodule "report"]
5
+	path = report
6
+	url = https://git.mount-mockery.de/pylib/report.git
7
+[submodule "task"]
8
+	path = task
9
+	url = https://git.mount-mockery.de/pylib/task.git

+ 26
- 0
example_config/config.py View File

@@ -0,0 +1,26 @@
1
+#!/usr/bin/env python
2
+# -*- coding: UTF-8 -*-
3
+import os
4
+import report
5
+
6
+__BASEPATH__ = os.path.abspath(os.path.dirname(__file__))
7
+
8
+MQTT_USER = "user"
9
+MQTT_PASS = "pass"
10
+MQTT_SERVER = "host"
11
+
12
+TOPIC = 'topic'
13
+PAYLOAD = b'payload'
14
+COMMAND = "aplay ring.wav -D plughw:UACDemoV10,0"
15
+
16
+#
17
+# Logging
18
+#
19
+APP_NAME = "exec_command"
20
+LOGTARGET = 'stdout'   # possible choices are: 'logfile' or 'stdout'
21
+LOGLVL = 'DEBUG'
22
+
23
+LOGHOST = 'cutelog'
24
+LOGPORT = 19996
25
+
26
+formatter = report.SHORT_FMT

+ 49
- 0
exec_command.py View File

@@ -0,0 +1,49 @@
1
+import config
2
+import logging
3
+import mqtt
4
+import os
5
+import report
6
+import task
7
+import time
8
+
9
+try:
10
+    from config import APP_NAME as ROOT_LOGGER_NAME
11
+except ImportError:
12
+    ROOT_LOGGER_NAME = 'root'
13
+logger = logging.getLogger(ROOT_LOGGER_NAME).getChild('main')
14
+
15
+
16
+class exec_command(mqtt.mqtt_client, task.threaded_queue):
17
+    def __init__(self):
18
+        self.__block_execution__ = False
19
+        task.threaded_queue.__init__(self)
20
+        mqtt.mqtt_client.__init__(self, config.APP_NAME, config.MQTT_SERVER, 1883, config.MQTT_USER, config.MQTT_PASS)
21
+        self.add_callback(config.TOPIC, self.mqtt_rx)
22
+
23
+    def exec_command(self, rt):
24
+        os.system(config.COMMAND)
25
+        self.__block_execution__ = False
26
+    
27
+
28
+    def mqtt_rx(self, client, userdate, message):
29
+        if not self.__block_execution__:
30
+            if message.payload == config.PAYLOAD:
31
+                logger.debug("Starting execution in background...")
32
+                self.__block_execution__ = True
33
+                self.enqueue(5, self.exec_command)
34
+        else:
35
+            logger.debug("Execution in progress. Ignoring request...")
36
+
37
+
38
+if __name__ == '__main__': 
39
+    report.appLoggingConfigure(config.__BASEPATH__, config.LOGTARGET, ((config.APP_NAME, config.LOGLVL), ), fmt=config.formatter, host=config.LOGHOST, port=config.LOGPORT)
40
+    #
41
+    ec = exec_command()
42
+    ec.run()
43
+    #
44
+    while True:
45
+        time.sleep(30)
46
+    try:
47
+        ec.join()
48
+    finally:
49
+        ec.stop()

+ 4
- 0
exec_command.sh View File

@@ -0,0 +1,4 @@
1
+#!/bin/sh
2
+#
3
+BASEPATH=`dirname $0`
4
+$BASEPATH/venv/bin/python $BASEPATH/exec_command.py

+ 1
- 0
mqtt

@@ -0,0 +1 @@
1
+Subproject commit cf97fa066cdff0e2f7eda0ff4d3c8c0f59c3f2ec

+ 1
- 0
report

@@ -0,0 +1 @@
1
+Subproject commit 21bac82e0c459ebf6d34783c9249526a657a6bbd

+ 1
- 0
requirements.txt View File

@@ -0,0 +1 @@
1
+paho-mqtt

+ 1
- 0
ring.wav View File

@@ -0,0 +1 @@
1
+sounds/phone-incoming-call.wav

BIN
sounds/phone-incoming-call.wav View File


BIN
sounds/suspend-error.wav View File


+ 1
- 0
task

@@ -0,0 +1 @@
1
+Subproject commit 7583bb5f3bd2420c901374ba95b678af6ce88433

Loading…
Cancel
Save