From 036c532fac4f71d9169981bd215dc5bc09bf5672 Mon Sep 17 00:00:00 2001 From: dominik Date: Thu, 18 Apr 2019 00:49:21 +0200 Subject: [PATCH] Companion AppSupport Android App WLANThermo Companion Support --- software/usr/sbin/wlt_2_comp.py | 38 ++++++++++ software/var/www/control/config.php | 108 ++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) diff --git a/software/usr/sbin/wlt_2_comp.py b/software/usr/sbin/wlt_2_comp.py index 0766cee..dd56f37 100755 --- a/software/usr/sbin/wlt_2_comp.py +++ b/software/usr/sbin/wlt_2_comp.py @@ -39,6 +39,7 @@ import json import statistics import platform +import requests gettext.install('wlt_2_comp', localedir='/usr/share/WLANThermo/locale/', unicode=True) @@ -531,6 +532,7 @@ def read_maverick(): Email_alert = new_config.getboolean('Email','email_alert') Push_alert = new_config.getboolean('Push', 'push_on') Telegram_alert = new_config.getboolean('Telegram', 'telegram_alert') + App_alert = new_config.getboolean('App', 'app_alert') temp_unit = new_config.get('locale', 'temp_unit') @@ -798,7 +800,42 @@ def read_maverick(): logger.error(u'Telegram HTTP error: ' + str(e.code) + u' - ' + e.read(500)) except urllib2.URLError, e: logger.error(u'Telegram URLError: ' + str(e.reason)) + + + if App_alert: + logger.debug(u'App_alert') + api_key='key=AAAA89_rQYw:APA91bEknuZrwPUNveElqW1CgFcICLOh9sIjtume6HPeExxtnJoQExiFIvqU84Xk-MsxI2Ig6w8VvaAsm43QHrowruP5EOvz0IO-HG9PB3mcoiumT2k6CcVryLiL4K450Jx1QKhumkd0' + app_id = ["","",""] + app_id[0] = new_config.get('App','app_inst_id') + app_id[1] = new_config.get('App','app_inst_id2') + app_id[2] = new_config.get('App','app_inst_id3') + app_device = ["","",""] + app_device[0] = new_config.get('App','app_device') + app_device[1] = new_config.get('App','app_device2') + app_device[2] = new_config.get('App','app_device3') + alarm_message = str(alarm_message.encode('utf-8')) + + url = 'https://fcm.googleapis.com/fcm/send' + myheaders = {'Content-Type': 'application/json', 'Authorization': api_key} + + i=0 + while i < 3: + if app_id[i] != "" and app_device[i]=="0" : + payload = {'data': {'Alarm':alarm_message}, "android":{"priority":"high"}, 'to':app_id[i]} + try: + logger.debug(u'App_alert try sending:' ) + logger.debug(u'App_id:' + app_id[i]) + data=json.dumps(payload) + results = requests.post(url, data, headers=myheaders) + print(results.text) + logger.debug(u'AppAlert result: ' + str(results.text)) + except requests.exceptions.RequestException as e: + print(e) + logger.debug(u'App_alert error') + i=i+1 + + if Push_alert: # Wenn konfiguriert, Alarm per Pushnachricht schicken Push_URL = new_config.get('Push', 'push_url') @@ -916,3 +953,4 @@ def read_maverick(): pi.bb_spi_close(7) logging.shutdown() os.unlink(pidfilename) + \ No newline at end of file diff --git a/software/var/www/control/config.php b/software/var/www/control/config.php index 9038a2f..b2615c5 100644 --- a/software/var/www/control/config.php +++ b/software/var/www/control/config.php @@ -19,6 +19,7 @@ $log_levels = array('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'); +$app_devices=array('Companion' => '0'); // ################################################################################## // Config-Files einlesen ------------------------------------------------------------ // ################################################################################## @@ -302,6 +303,58 @@ } } + // ###################################################################### //Dominik + // App Einstellungen ---------------------------------------------------- + // ###################################################################### + + // Pushbenachrichtigung Aktivieren/Deaktivieren + if(isset ($_POST['app_alert'])) {$_POST['app_alert'] = "True"; }else{ $_POST['app_alert'] = "False";} + if($ini['App']['app_alert'] !== $_POST['app_alert']){ + $ini['App']['app_alert'] = $_POST['app_alert']; + } + + // App app_inst_id + if (isset($_POST['app_inst_id'])) { + if($ini['App']['app_inst_id'] !== $_POST['app_inst_id']){ + $ini['App']['app_inst_id'] = $_POST['app_inst_id']; + } + } + // App app_device + if (isset($_POST['app_device_id1'])) { + if($ini['App']['app_device'] !== $_POST['app_device_id1']){ + $ini['App']['app_device'] = $_POST['app_device_id1']; + } + } + // App app_inst_id2 + if (isset($_POST['app_inst_id2'])) { + if($ini['App']['app_inst_id2'] !== $_POST['app_inst_id2']){ + $ini['App']['app_inst_id2'] = $_POST['app_inst_id2']; + } + } + // App app_device2 + if (isset($_POST['app_device_id2'])) { + if($ini['App']['app_device2'] !== $_POST['app_device_id2']){ + $ini['App']['app_device2'] = $_POST['app_device_id2']; + } + } + // App app_inst_id3 + if (isset($_POST['app_inst_id3'])) { + if($ini['App']['app_inst_id3'] !== $_POST['app_inst_id3']){ + $ini['App']['app_inst_id3'] = $_POST['app_inst_id3']; + } + } + // App app_device3 + if (isset($_POST['app_device_id3'])) { + if($ini['App']['app_device3'] !== $_POST['app_device_id3']){ + $ini['App']['app_device3'] = $_POST['app_device_id3']; + } + } + // App app_sound + if (isset($_POST['app_sound'])) { + if($ini['App']['app_sound'] !== $_POST['app_sound']){ + $ini['App']['app_sound'] = $_POST['app_sound']; + } + } // ###################################################################### // LCD Einstellungen ---------------------------------------------------- // ###################################################################### @@ -861,6 +914,61 @@
+
+
+
:
+
>
+
+
1:
+
2:
+
3:
+
+
+
+
+
+
+
+
+
+
1:
+
2:
+
3:
+
+ +
+
+ +
+
+ +
+
+