From c113093ee3b9af7e0c5769df9e06ad5954184811 Mon Sep 17 00:00:00 2001 From: mrduckspace <34840030+mrduckspace@users.noreply.github.com> Date: Fri, 27 Mar 2020 09:27:47 +0100 Subject: [PATCH 1/6] Create gpiocontrol.py --- plugins/gpiocontrol/gpiocontrol.py | 87 ++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 plugins/gpiocontrol/gpiocontrol.py diff --git a/plugins/gpiocontrol/gpiocontrol.py b/plugins/gpiocontrol/gpiocontrol.py new file mode 100644 index 0000000..32a295d --- /dev/null +++ b/plugins/gpiocontrol/gpiocontrol.py @@ -0,0 +1,87 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- + +# Imports + +import RPi.GPIO as GPIO +import time +import threading + +import logging # Global logger +from includes import globalVars # Global variables + +# Helper function, uncomment to use +from includes.helper import timeHandler +from includes.helper import wildcardHandler +from includes.helper import configHandler + +## +# +# onLoad (init) function of plugin +# will be called one time by the pluginLoader on start +# +def onLoad(): + """ + While loading the plugins by pluginLoader.loadPlugins() + this onLoad() routine is called one time for initialize the plugin + """ + global GPIOPIN + global waitTime + + GPIOPIN = globalVars.config.getint("gpiocontrol","pin") + waitTime = globalVars.config.getint("gpiocontrol","triggertime") + + + GPIO.setmode(GPIO.BCM) + GPIO.setwarnings(False) + GPIO.setup(GPIOPIN, GPIO.OUT) + GPIO.output(GPIOPIN, GPIO.HIGH) + + return + +# +# +# Main function of plugin +# will be called by the alarmHandler +# +def run(typ,freq,data): + try: + if configHandler.checkConfig("gpiocontrol"): #read and debug the config + + logging.debug(globalVars.config.get("gpiocontrol", "pin")) + logging.debug(globalVars.config.get("gpiocontrol", "triggertime")) + logging.debug(globalVars.config.get("gpiocontrol", "activerics")) + + ########## User Plugin CODE ########## + if typ == "FMS": + th = threading.Thread(target = trigger) + th.start() + elif typ == "ZVEI": + th = threading.Thread(target = trigger) + th.start() + elif typ == "POC": + if globalVars.config.get("gpiocontrol", "activerics") == "": + th = threading.Thread(target = trigger) + th.start() + else + if data["ric"] in globalVars.config.get("gpiocontrol", "activerics"): + th = threading.Thread(target = trigger) + th.start() + else: + logging.info("Ric not in activerics") + else: + logging.warning("Invalid Typ: %s", typ) + ########## User Plugin CODE ########## + + except: + logging.error("unknown error") + logging.debug("unknown error", exc_info=True) + +def trigger(): + GPIO.output(GPIOPIN, GPIO.LOW) + logging.info("GPIOPIN %s on", GPIOPIN) + time.sleep(waitTime) + GPIO.output(GPIOPIN, GPIO.HIGH) + logging.info("GPIOPIN %s off", GPIOPIN) + + return From f6523929b21c4cbe6ea74487554131d247cfedf7 Mon Sep 17 00:00:00 2001 From: mrduckspace <34840030+mrduckspace@users.noreply.github.com> Date: Fri, 27 Mar 2020 09:31:20 +0100 Subject: [PATCH 2/6] Update gpiocontrol.py --- plugins/gpiocontrol/gpiocontrol.py | 77 ++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 25 deletions(-) diff --git a/plugins/gpiocontrol/gpiocontrol.py b/plugins/gpiocontrol/gpiocontrol.py index 32a295d..fa52bc6 100644 --- a/plugins/gpiocontrol/gpiocontrol.py +++ b/plugins/gpiocontrol/gpiocontrol.py @@ -1,6 +1,13 @@ #!/usr/bin/python # -*- coding: UTF-8 -*- +""" + +@author: KS + +@requires: none +""" + # Imports import RPi.GPIO as GPIO @@ -24,18 +31,28 @@ def onLoad(): """ While loading the plugins by pluginLoader.loadPlugins() this onLoad() routine is called one time for initialize the plugin + + @requires: nothing + + @return: nothing + @exception: Exception if init has an fatal error so that the plugin couldn't work + """ global GPIOPIN global waitTime - + GPIOPIN = globalVars.config.getint("gpiocontrol","pin") - waitTime = globalVars.config.getint("gpiocontrol","triggertime") - + waitTime = globalVars.config.getint("gpiocontrol","ontime") GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(GPIOPIN, GPIO.OUT) - GPIO.output(GPIOPIN, GPIO.HIGH) + + #GPIO schalten beim START + #GPIO.output(GPIOPIN, GPIO.LOW) + #time.sleep(1) + + GPIO.output(GPIOPIN, GPIO.HIGH) return @@ -45,32 +62,42 @@ def onLoad(): # will be called by the alarmHandler # def run(typ,freq,data): + """ + @type typ: string (FMS|ZVEI|POC) + @param typ: Typ of the dataset + @type data: map of data (structure see readme.md in plugin folder) + @param data: Contains the parameter for dispatch + @type freq: string + @keyword freq: frequency of the SDR Stick + + @requires: If necessary the configuration hast to be set in the config.ini. + + @return: nothing + @exception: nothing, make sure this function will never thrown an exception + """ try: - if configHandler.checkConfig("gpiocontrol"): #read and debug the config + if configHandler.checkConfig("gpiocontrol"): #read and debug the config (let empty if no config used) logging.debug(globalVars.config.get("gpiocontrol", "pin")) - logging.debug(globalVars.config.get("gpiocontrol", "triggertime")) - logging.debug(globalVars.config.get("gpiocontrol", "activerics")) - + logging.debug(globalVars.config.get("gpiocontrol", "ontime")) + ########## User Plugin CODE ########## if typ == "FMS": - th = threading.Thread(target = trigger) - th.start() + #th = threading.Thread(target = trigger) + #th.start() + logging.warning("%s not supported", typ) elif typ == "ZVEI": - th = threading.Thread(target = trigger) - th.start() + #th = threading.Thread(target = trigger) + #th.start() + logging.warning("%s not supported", typ) elif typ == "POC": - if globalVars.config.get("gpiocontrol", "activerics") == "": - th = threading.Thread(target = trigger) - th.start() - else - if data["ric"] in globalVars.config.get("gpiocontrol", "activerics"): - th = threading.Thread(target = trigger) - th.start() - else: - logging.info("Ric not in activerics") + if data["ric"] in globalVars.config.get("gpiocontrol", "activerics"): + th = threading.Thread(target = trigger) + th.start() + else: + logging.info("Ric not in activerics") else: - logging.warning("Invalid Typ: %s", typ) + logging.warning("Invalid Typ: %s", typ) ########## User Plugin CODE ########## except: @@ -79,9 +106,9 @@ def run(typ,freq,data): def trigger(): GPIO.output(GPIOPIN, GPIO.LOW) - logging.info("GPIOPIN %s on", GPIOPIN) + logging.info("GPIOPIN %s angeschaltet", GPIOPIN) time.sleep(waitTime) - GPIO.output(GPIOPIN, GPIO.HIGH) - logging.info("GPIOPIN %s off", GPIOPIN) + GPIO.output(GPIOPIN, GPIO.HIGH) + logging.info("GPIOPIN %s ausgeschaltet", GPIOPIN) return From bd3e15ba576351b985fbd36af79a5ce80940c522 Mon Sep 17 00:00:00 2001 From: mrduckspace <34840030+mrduckspace@users.noreply.github.com> Date: Fri, 27 Mar 2020 09:34:48 +0100 Subject: [PATCH 3/6] Update gpiocontrol.py --- plugins/gpiocontrol/gpiocontrol.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/gpiocontrol/gpiocontrol.py b/plugins/gpiocontrol/gpiocontrol.py index fa52bc6..c75f072 100644 --- a/plugins/gpiocontrol/gpiocontrol.py +++ b/plugins/gpiocontrol/gpiocontrol.py @@ -42,7 +42,7 @@ def onLoad(): global waitTime GPIOPIN = globalVars.config.getint("gpiocontrol","pin") - waitTime = globalVars.config.getint("gpiocontrol","ontime") + waitTime = globalVars.config.getint("gpiocontrol","triggertime") GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) @@ -79,7 +79,7 @@ def run(typ,freq,data): if configHandler.checkConfig("gpiocontrol"): #read and debug the config (let empty if no config used) logging.debug(globalVars.config.get("gpiocontrol", "pin")) - logging.debug(globalVars.config.get("gpiocontrol", "ontime")) + logging.debug(globalVars.config.get("gpiocontrol", "triggertime")) ########## User Plugin CODE ########## if typ == "FMS": From e7bd6ae2c5c177cda44d0f113a2d7f08b6ec8b23 Mon Sep 17 00:00:00 2001 From: mrduckspace <34840030+mrduckspace@users.noreply.github.com> Date: Fri, 27 Mar 2020 09:34:54 +0100 Subject: [PATCH 4/6] Update config.template.ini --- config/config.template.ini | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/config/config.template.ini b/config/config.template.ini index 9e05679..dd699ee 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -175,6 +175,7 @@ Pushover = 0 Telegram = 0 yowsup = 0 hue = 0 +gpiocontrol = 0 # for developing - template-module template = 0 @@ -463,6 +464,18 @@ timeoff = 1 # configure 0 to keep the switch on for infinite time or configure >=1 to keep it for the value in seconds to on, before switching to off. keepon = 60 +[gpiocontrol] +#Pin that will be triggered +#Only tested on Raspberry Pi 3 +pin = 21 + +#Time the Pin will be triggered (in Seconds) +triggertime = 180 + +#ONLY POC +#POC Rics that trigger PIN (empty: allow all, separator ",") +activerics = 1234567,1234568 + ##################### ##### Not ready yet # ##################### From 6222463a96b4ba6dd03f15e2a157bb3fbf8ccb8f Mon Sep 17 00:00:00 2001 From: mrduckspace <34840030+mrduckspace@users.noreply.github.com> Date: Fri, 27 Mar 2020 09:38:33 +0100 Subject: [PATCH 5/6] Update gpiocontrol.py --- plugins/gpiocontrol/gpiocontrol.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/plugins/gpiocontrol/gpiocontrol.py b/plugins/gpiocontrol/gpiocontrol.py index c75f072..7662fe8 100644 --- a/plugins/gpiocontrol/gpiocontrol.py +++ b/plugins/gpiocontrol/gpiocontrol.py @@ -83,19 +83,23 @@ def run(typ,freq,data): ########## User Plugin CODE ########## if typ == "FMS": - #th = threading.Thread(target = trigger) - #th.start() - logging.warning("%s not supported", typ) + th = threading.Thread(target = trigger) + th.start() + #logging.warning("%s not supported", typ) elif typ == "ZVEI": - #th = threading.Thread(target = trigger) - #th.start() - logging.warning("%s not supported", typ) + th = threading.Thread(target = trigger) + th.start() + #logging.warning("%s not supported", typ) elif typ == "POC": - if data["ric"] in globalVars.config.get("gpiocontrol", "activerics"): - th = threading.Thread(target = trigger) - th.start() - else: - logging.info("Ric not in activerics") + if globalVars.config.get("gpiocontrol", "activerics") == "": + th = threading.Thread(target = trigger) + th.start() + else + if data["ric"] in globalVars.config.get("gpiocontrol", "activerics"): + th = threading.Thread(target = trigger) + th.start() + else: + logging.info("Ric not in activerics") else: logging.warning("Invalid Typ: %s", typ) ########## User Plugin CODE ########## From d4b397073e868ac72916f348b52e81a455fe1b17 Mon Sep 17 00:00:00 2001 From: mrduckspace <34840030+mrduckspace@users.noreply.github.com> Date: Tue, 14 Apr 2020 10:37:19 +0200 Subject: [PATCH 6/6] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74f0218..b1cc352 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### __[v2.4.4]__ - unreleased ##### Added - Divera-Plugin: Plugin zum Ansteuern der Divera-Api. [#415](https://github.com/Schrolli91/BOSWatch/pull/415) +- GPIO-Control: Plugin zum Ansteuern der GPIO Pins. [#438](https://github.com/Schrolli91/BOSWatch/pull/438) ##### Changed - MySQL-Plugin: Index für die RIC Adresse hinzugefügt [#411](https://github.com/Schrolli91/BOSWatch/issues/411) - MySQL-Plugin: INSERT Befehl für MySQL 8.x angepasst, Spaltennamen escaped [#410](https://github.com/Schrolli91/BOSWatch/issues/410)