Schrolli91 / BOSWatch

Python Script to process input data from rtl_fm and multimon-NG - multiple Plugin support
https://bwcc.boswatch.de
GNU General Public License v2.0
132 stars 60 forks source link

subprocess bei erfolgreicher RIC #477

Closed samazaphikel closed 4 years ago

samazaphikel commented 4 years ago

Hi,

wo könnte ich einen subprocess einfügen, wenn eine RIC hereinkommt soll ein zusätzliches Bash script gestartet werden.

sowas wie z.B.:

import subprocess 
output = subprocess.call(['sh','test.sh'])

In meinem Fall soll das Display vom Raspberry an und ausgeschalten werden

sudo -E sh -c 'echo 0 > /sys/class/backlight/rpi_backlight/bl_power'
sleep 5m
sudo -E sh -c 'echo 1 > /sys/class/backlight/rpi_backlight/bl_power'
samazaphikel commented 4 years ago

Hallo,

ich nochmal.

Ich habe es nun über Plugins gelöst. Falls es sonst noch jemand benötigt. Ich nutze den Raspberry 4 mit dem Raspberry Pi 7" Touchscreen Display

Ich habe einen Ordner displaycontrol in plugins erstellt mit der Datei displaycontrol.py. In der config.ini habe ich unter [Plugins] die Zeile displaycontrol= 1 eingefügt In der displaycontrol.py habe ich dann folgendes Script:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import logging  # Global logger
import time
import os

#
#
# onLoad (init) function of plugin
# will be called one time by the pluginLoader on start
#
def onLoad():
    # nothing to do for this plugin
    return

#
#
# will be called by the alarmHandler
#
def run(typ, freq, data):
    try:
        # display on
        os.system("sudo -E sh -c 'echo 0 > /sys/class/backlight/rpi_backlight/bl_power'")
    except:
        logging.error("cannot turn the display on")

    try:
        # pause function
        time.sleep(900)  # pause in seconds
    except:
        logging.error("something wrong in sleep")

    try:    
        # display off
        os.system("sudo -E sh -c 'echo 1 > /sys/class/backlight/rpi_backlight/bl_power'")
    except:
        logging.error("cannot turn the display off")
Schrolli91 commented 4 years ago

Ich würde dann aber empfehlen die Plugin Ausführung auf Async zu stellen. So ist nämlich BOSWatch bis zur Abarbeitung dieses Plugins (Wartezeit) blockiert und es könnten Alarme verloren gehen.

samazaphikel commented 4 years ago

Ok, und wie stelle ich sowas auf async?

Schrolli91 commented 4 years ago

siehe Kommentar Block darüber ... https://github.com/Schrolli91/BOSWatch/blob/master/config/config.template.ini#L41

samazaphikel commented 4 years ago

Ah ok, Danke