Ankündigung

Einklappen
Keine Ankündigung bisher.

Bash script aus logic heraus aufrufen -> item getriggertes Ausschalten des HDMI Ports

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    Bash script aus logic heraus aufrufen -> item getriggertes Ausschalten des HDMI Ports

    Hallo,
    Ich hoffe es hat jemand eine Idee oder kann mir helfen. Ich möchte ein bash script display_ctrl_on.sh aus einer Logik heraus aufrufen. Aber ich bekomme es nict hin. Die logik soll den HDMI Port des Rpi item getriggert ein und ausschalten.

    Das script funktioniert wenn ich es in der Konsole aufrufe:
    display_ctrl_off.sh:
    Code:
    /opt/vc/bin/vcgencmd display_power 0
    Ich habe in der Logik versucht es wie folgt aufzurufen:

    Code:
    if trigger['value'] == False:
         os.system('./display_ctrl_off.sh')
    Dann kommt der folgende Fehler:

    Code:
    2016-10-16  17:52:39 ERROR    Main         Connection polling failed: [Errno 4] Unterbrechung während des Betriebssystemaufrufs
    Traceback (most recent call last):
      File "/usr/local/smarthome/bin/smarthome.py", line 331, in start
        self.connections.poll()
      File "/usr/local/smarthome/lib/connection.py", line 101, in poll
        for fileno, event in self._epoll.poll(timeout=1):

    Wenn ich das script so aufrufe dann passiert gar nichts (Kein Fehler, Kein Abschalten des HDMI Ports:

    Code:
    if trigger['value'] == False:
        subprocess.call('display_ctrl_off.sh',shell=True)
    Jemand eine Idee?

    Gruß

    #2
    Im Backend ist z.B. sowas drin:
    Code:
    def get_process_info(self, command):
       """
       returns output from executing a given command via the shell.
       """
       self.find_visu_plugin()
       ## get subprocess module
       import subprocess
       ## call date command ##
       p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
       # Talk with date command i.e. read data from stdout and stderr. Store this info in tuple ##
       # Interact with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached.
       # Wait for process to terminate. The optional input argument should be a string to be sent to the child process, or None, if no data should be sent to the child.
       (result, err) = p.communicate()
       ## Wait for date to terminate. Get return returncode ##
       p_status = p.wait()
       return str(result, encoding='utf-8', errors='strict')
    vielleicht hilft Dir das schon mal weiter...

    Kommentar


      #3
      Danke für die schnelle Antwort. Aber leider klappt das auch nicht. Kein Eintrag im Log, keine Aktion.

      So habe ich es in der Logik versucht:
      Code:
      import subprocess
      if trigger['value'] == False:
          #subprocess.call('display_ctrl_off.sh',shell=True)
          p=subprocess.Popen('./display_ctrl_off.sh', stdout=subprocess.PIPE, shell=True)
          #os.system('sudo ./display_ctrl_off.sh')
          #os.system("vcgencmd display_power 0")
      
      #    mode = "Off"
      #    subprocess.call(["/usr/local/smarthome/logics/display_ctrl.sh", mode])
      #    sh.Rpi_Daten.Test ('False')
      if trigger['value'] == True:
          #subprocess.call('display_ctrl_on.sh',shell=True)
          p=subprocess.Popen('./display_ctrl_on.sh', stdout=subprocess.PIPE, shell=True)
          #os.system('sudo ./display_ctrl_on.sh')
          #os.system("vcgencmd display_power 1")
      
      
         ## get subprocess module
      
         ## call date command ##
         #p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
         # Talk with date command i.e. read data from stdout and stderr. Store this info in tuple ##
         # Interact with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached.
         # Wait for process to terminate. The optional input argument should be a string to be sent to the child process, or None, if no data should be sent to the child.
      (result, err) = p.communicate()
         ## Wait for date to terminate. Get return returncode ##
      p_status = p.wait()
      
      sh.Rpi_Daten.Test1(str(result))
      sh.Rpi_Daten.Test2(str(err))
      Wobei im result b" steht und err leer ist. Leider habe ich keine Idee was result b" bedeutet.

      Ich bin für weitere Ideen dankbar...!?

      Kommentar


        #4
        Hi, also wenn ich das richtig verstehe möchtest Du eigentlich nur aus der Logik vcgencmd absetzen. Das hatte schon mal jemand hier vorgestellt, damals halt für die PI-Temperaturen. Klappt bei mir wunderbar und hilft Dir evtl. auch.

        Kommentar


          #5
          Danke für den Hinweis. Jetzt funktioniert es. Allerdings hatte ich erst einen Fehler in der Variable stehen welchen ich aber mittels hinzufügen meines Users in die Gruppe Video beseitigen konnte: sudo udermod -a -G video smarthome

          So klappts mit dem Ein- und Ausschalten des Monitors:

          Code:
          import os
          if trigger['value'] == False:
              result1 = os.popen('vcgencmd display_power 0').readline()
              sh.Rpi_Daten.Test1(str(result1)) #Achtung, bevor das funktioniert muss ein sudo udermod -a -G video smarthome ausgefuehrt werden
              #subprocess.call('display_ctrl_off.sh',shell=True)
              #p=subprocess.Popen('./display_ctrl_off.sh', stdout=subprocess.PIPE, shell=True)
              #os.system('sudo ./display_ctrl_off.sh')
              #os.system("vcgencmd display_power 0")
          
          #    mode = "Off"
          #    subprocess.call(["/usr/local/smarthome/logics/display_ctrl.sh", mode])
          #    sh.Rpi_Daten.Test ('False')
          if trigger['value'] == True:
              result2 = os.popen('vcgencmd display_power 1').readline()
              sh.Rpi_Daten.Test2(str(result2))
              #subprocess.call('display_ctrl_on.sh',shell=True)
              #p=subprocess.Popen('./display_ctrl_on.sh', stdout=subprocess.PIPE, shell=True)
              #os.system('sudo ./display_ctrl_on.sh')
              #os.system("vcgencmd display_power 1")
          
          
             ## get subprocess module
          
             ## call date command ##
             #p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
             # Talk with date command i.e. read data from stdout and stderr. Store this info in tuple ##
             # Interact with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached.
             # Wait for process to terminate. The optional input argument should be a string to be sent to the child process, or None, if no data should be sent to the child.
          #(result, err) = p.communicate()
             ## Wait for date to terminate. Get return returncode ##
          #p_status = p.wait()
          Allerdings bleibt die Hintergrundbeleuchtung des Monitors an, was nicht gewünscht ist. Werde versuchen das zu lösen und nochmal berichten.
          Gruß

          Kommentar


            #6
            Ich mach das so..

            Code:
                try:
                    command = subprocess.check_output(['ssh', '-p', '22', '-i', 'synology.private', 'root@10.0.0.100', 'reboot'],stderr=subprocess.STDOUT,timeout = 12)
                    command = command.decode('utf-8')
                    logger.debug("Rueckmeldung der NAS Reboot Logic: {0}".format(command))
                except subprocess.CalledProcessError as e:
                    error = e.output.decode('utf-8')
                    logger.debug("NAS Reboot Error: {0}".format(error))
                except subprocess.TimeoutExpired as et:
                    error = et.output.decode('utf-8')
                    logger.debug("NAS Reboot Timeout: {0}".format(error))

            Kommentar


              #7
              Heute ist mein Dell -Touchscreen eingetroffen... und siehe da, mit ausschalten des HDMI Ausgangs geht auch die Hintergrundbeleuchtung aus. Somit lag das wohl an meinem alten samsung pc Monitor das er nicht in den sparmodus geschaltet hat... funktioniert nun alles. Danke für die Unterstützung !

              Kommentar

              Lädt...
              X