|
@@ -1,4 +1,5 @@
|
1
|
1
|
import config
|
|
2
|
+import json
|
2
|
3
|
import logging
|
3
|
4
|
import mqtt
|
4
|
5
|
import os
|
|
@@ -27,7 +28,20 @@ class exec_command(mqtt.mqtt_client, task.threaded_queue):
|
27
|
28
|
|
28
|
29
|
def mqtt_rx(self, client, userdate, message):
|
29
|
30
|
if not self.__block_execution__:
|
30
|
|
- if message.payload == config.PAYLOAD:
|
|
31
|
+ data = None
|
|
32
|
+ if config.PAYLOAD_KEY is None:
|
|
33
|
+ try:
|
|
34
|
+ data = message.payload.decode('utf-8')
|
|
35
|
+ except:
|
|
36
|
+ logger.exception("Error decoding mqtt message")
|
|
37
|
+ else:
|
|
38
|
+ try:
|
|
39
|
+ payload = json.loads(message.payload)
|
|
40
|
+ except:
|
|
41
|
+ logger.exception("Error decoding json mqtt message")
|
|
42
|
+ else:
|
|
43
|
+ data = payload.get(config.PAYLOAD_KEY)
|
|
44
|
+ if config.PAYLOAD_DATA is None or data == config.PAYLOAD_DATA:
|
31
|
45
|
logger.debug("Starting execution in background...")
|
32
|
46
|
self.__block_execution__ = True
|
33
|
47
|
self.enqueue(5, self.exec_command)
|