Ankündigung

Einklappen
Keine Ankündigung bisher.

Anfrage für LBS

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

    #46
    Oje, das hab ich schon befürchtet, ich glaub das übersteigt mein Wissen
    Gruß Ben

    Kommentar


      #47
      Zitat von mfd Beitrag anzeigen

      Btw.: Gibt es bereits eine funktionierende edomi-Anbindung/LBS für die Comfoair (350/550) von Zehnder?
      Da wäre ich auch dran interessiert.

      Kommentar


        #48
        jonofe
        Hallo André,

        Ich hab schon mal vor längerem Versucht deinen LBS für den LG TV für einen Monoprice 10761 umzubauen.
        Jetzt hat ich mal wieder bisschen Zeit mich damit zu beschäftigen, aber leider komm ich nicht so richtig weiter. Vieleicht wenn du Lust und Laune hast, könntest du mal drüber schauen. Wenn nicht halt nicht . Hab gedacht ich frag dich einfach mal, da du am vertrautesten mit dem LBS bist. Wenn du keine Zeit oder Lust hast kann ich das voll verstehen

        Versuch mal mein Problem zu beschreiben.
        Befehle senden funktioniert einwandfrei, aber mit der Statusabfrage haperts irgenwie.
        Power Status zeigts im LBS immer 0 an und alle weiteren Ausgänge mit -1.
        Und nach dem ich ich ein Kommando eingebe kommt beim ersten Ausgang "Error". Aber schalten funktioniert trotdem.

        Ich glaub der Unterschied zum LG ist einfach folgender, dass nach dem Senden eines Befehls kein ACK kommt. Stattdessen muss man den Status Aktiv abfragen.
        Also z.B. bei Power ON

        Monoprice einschalten
        Gesendeter Befehl: <11PR01
        Antwort: nix (also keine Antwort)

        Monoprice Status abfragen
        Gesendeter Befehl: ?11PR
        Antwort: >11PR01

        Bei falscher Eingabe: Command Error.


        Hier mal der abgeänderte LBS von mir. Vieleicht ist es ja nur ne Kleinigkeit.
        Code:
        ?###[DEF]###
        [name        = Monoprice 10761 RS-232C    (v0.1) ]
        
        [e#1        = IP ]
        [e#2        = Port ]
        [e#3        = ZoneID ]
        [e#4        = Command ]
        [e#5        = Log level ]
        
        [a#1        = Result ]
        [a#2        = Error ]
        [a#3        = Power ]
        [a#4        = Input ]
        [a#5        = Volume Mute ]
        [a#6        = Volume ]
        [a#7        = Treble ]
        [a#8        = Bass ]
        [a#9        = Balance ]
        
        [v#1        = 0 ]
        [v#2        = 0 ]
        [v#100        = 0.1 ]
        [v#101        = 19000501 ]
        [v#102        = Monoprice 10761 RS-232C ]
        [v#103        = 0 ]
        
        ###[/DEF]###
        
        
        ###[HELP]###
        This LBS controls an Monoprice 10761 connected via a Ethernet-to-RS-232C adapter (e.g. Moxa NPort 5110)  to your home network.
        
        Simple Configutaion:
        E1: IP address of your RS-232/Ethernet converter in TCP/IP Server mode (should work with ser2net as well)
        E2: Port, which you have configured you TCP/IP Server on
        E3: ZoneID, which Zone you want to control of your Monoprice 10761 (10-All Zone|11-Zone1|12-Zone2|13-Zone3|14-Zone4|15-Zone5|16-Zone6)
        E4: The Command, which you want to send to your Monoprice 10761
        E5: Enable Logging (0-none|1-emerg|2-alert|3-crit|4-err|5-warning|6-notice|7-info|8-debug)
        
        Available commands:
        
        COMMAND - raw command accoring to the RS-232C documentation of Monoprice ==> e.g. "11 PR 01" (11=ZoneID, PR=Power, 01=ON)
        POWER (00|01)
        POWER_ON
        POWER_OFF
        VOLUMEMUTE (00-Volume mute on|01-Volume mute off)
        MUTE (same as VOLUMEMUTE)
        VOLUMEMUTE_ON (=MUTE 00)
        MUTE_ON (same as VOLUMEMUTE_ON)
        VOLUMEMUTE_OFF (=MUTE 01)
        MUTE_OFF (same as VOLUMEMUTE_OFF)
        VOLUME (00-38)
        VOLUMECONTROL (same as VOLUME)
        TREBLE (00-14)
        BASS  (00-14)
        BALANCE  (00-20)
        INPUTSELECT (01-Source 1|02-Source 2|03-Source 3|04-Source 4|05-Source 5|06-Source 6)
        INPUT        (same as INPUTSELECT)
        
        The outputs are updated automatically every 1/4 second. You can expect 1-3 seconds delay when sending an command, until the outputs are updated.
        The outputs correspond to the commands above and should self explanatory. If the Monoprice is switched off, only the POWER output contains valid information.
        Monoprice will not respond to other requests.
        
        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        Prerequesite before using this LBS
        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        
        - Install php-process:
        
        yum install php-process
        
        Enjoy ...
        
        Changelog:
        ==========
        v0.1: Initial version
        
        ###[/HELP]###
        
        
        ###[LBS]###
        <?
        
        function LB_LBSID_logging($id, $msg, $priority=8)
        {
            $E=getLogicEingangDataAll($id);
            $logLevel = getLogicElementVar($id,103);
            if (is_int($priority) && $priority<=$logLevel && $priority>0)
            {
                $logLevelNames = array('none','emerg','alert','crit','err','warning','notice','info','debug');
                $version = getLogicElementVar($id,100);
                $lbsNo = getLogicElementVar($id,101);
                $logName = getLogicElementVar($id,102) . '  ---  LBS'.$lbsNo;
                strpos($_SERVER['SCRIPT_NAME'],$lbsNo) ? $scriptname='EXE'.$lbsNo : $scriptname = 'LBS'.$lbsNo;
                writeToCustomLog($logName,str_pad($logLevelNames[$logLevel],7), $scriptname.":\t".$msg."\t[v$version]");
            }
        }
        
        function LB_LBSID($id) {
            if ($E=getLogicEingangDataAll($id)) {
                setLogicElementVar($id,103,$E[5]['value']); //set loglevel to #VAR 103
                LB_LBSID_logging($id,'Logic started');
                if (getLogicElementVar($id,1)!=1) {
                    setLogicElementVar($id,1,1);
                    $uniqid = hexdec(uniqid());
                    setLogicElementVar($id,2,$uniqid);
                    callLogicFunctionExec(LBSID,$id);
                } else {
                    $uniqid = getLogicElementVar($id,2);
                    $msg_queue = msg_get_queue ( $uniqid );
                    if ($E[4]['refresh']==1) {
                        $cmd = $E[4]['value'];
                        msg_send($msg_queue,1,$cmd);
                        LB_LBSID_logging($id,'Sending command to EXEC daemon: '.$cmd);
                    }
                }
                LB_LBSID_logging($id,'Logic finished');
            }
        }
        ?>
        ###[/LBS]###
        
        
        ###[EXEC]###
        <?
        require(dirname(__FILE__)."/../../../../main/include/php/incl_lbsexec.php");
        set_time_limit(0);
        sql_connect();
        
        function logging($id,$msg, $priority=8)
        {
            $E=getLogicEingangDataAll($id);
            $logLevel = getLogicElementVar($id,103);
            if (is_int($priority) && $priority<=$logLevel && $priority>0)
            {
                $logLevelNames = array('none','emerg','alert','crit','err','warning','notice','info','debug');
                $version = getLogicElementVar($id,100);
                $lbsNo = getLogicElementVar($id,101);
                $logName = getLogicElementVar($id,102) . '  ---  LBS'.$lbsNo;
                strpos($_SERVER['SCRIPT_NAME'],$lbsNo) ? $scriptname='EXE'.$lbsNo : $scriptname = 'LBS'.$lbsNo;
                writeToCustomLog($logName,str_pad($logLevelNames[$logLevel],7), $scriptname.":\t".$msg."\t[v$version]");
            }
        }
        
        if ($E=getLogicEingangDataAll($id))
        {
            $ip = $E[1]['value'];
            $port = $E[2]['value'];
            $ZoneID = $E[3]['value'];
        
            setLogicElementVar($id,103,$E[5]['value']); //set loglevel to #VAR 103
        
            logging($id,'Daemon started');
        
            $uniqid=getLogicElementVar($id,2);
            $msg_queue = msg_get_queue ( $uniqid );
        
            $mono = new mono_moxa($ip,$port,$ZoneID);
            $mono->connect();
            $commandExecutionTime = 0;
        
            while (getSysInfo(1))
            {
                logging($id,'READ:'.MSG_IPC_NOWAIT);
                ;
                if (msg_receive($msg_queue,1,$msgtype, 4096, $msg, true, MSG_IPC_NOWAIT, $msg_error))
                {
                    logging($id,'Received Command to be executed: '.$msg);
                    $command = explode(' ',$msg);
                    $result = $mono->command($command);
                    $commandExecutionTime = microtime(true);
                    if (!$result)
                    {
                        setLogicLinkAusgang($id,1,'ERROR');
                        setLogicLinkAusgang($id,2,1);
                    } else {
                        setLogicLinkAusgang($id,1,$result);
                        setLogicLinkAusgang($id,2,0);
                    }
                }
        
                // read status regularly but not during the first second after a command was issued
                if ((microtime(true)-$commandExecutionTime)>=1)
                {
                  $commandExecutionTime = 0;  
                  $mono->status();
                }
                usleep(100000);
                logging($id,'END');
            }
            logging($id,'Daemon terminated');
        }
        
        $mono->disconnect();
        msg_remove_queue($msg_queue);
        
        sql_disconnect();
        
        
        class mono_moxa
        {
            private $moxa_ip;
            private $moxa_port;
            private $moxa_connection;
            private $ZoneID;
        
            function mono_moxa($moxa_ip, $moxa_port ,$ZoneID)
            {
                $this->moxa_ip = $moxa_ip;
                $this->moxa_port = $moxa_port;
                $this->ZoneID = $ZoneID;
        
            }
        
            function connect()
            {
                // Create socket
                if ($this->moxa_connection = socket_create(AF_INET, SOCK_STREAM, SOL_TCP))
                {
                    // Bind the source address
                    if (socket_bind($this->moxa_connection, global_serverIP))
                    {
                        // Connect to destination address
                        if (socket_connect($this->moxa_connection, $this->moxa_ip, $this->moxa_port))
                        {
                            if (socket_set_nonblock($this->moxa_connection)) return true;
                        }
                    }
                }
                return false;
            }
        
            function disconnect()
            {
                if (isset($this->moxa_connection)) socket_close($this->moxa_connection);
            }
        
            function command($cmd)
            {
                global $id;
                logging($id,'Command: '.serialize($cmd));
                $command = strtoupper($cmd[0]);
                array_shift($cmd);
                $value = strtoupper(implode(' ',$cmd));
                logging($id,'Value: '.$value);
                switch ($command)
                {
                    case "STATUS":
                        return $this->status();
                        break;
                    case "COMMAND":
                        return $this->sendCmd($value);
                        break;
                    case "POWER":
                        return $this->power($value);
                        break;
                    case "POWER_ON":
                        return $this->powerOn();
                        break;
                    case "POWER_OFF":
                        return $this->powerOff();
                        break;
                    case "INPUTSELECT":
                    case "INPUT":
                        return $this->inputSelect($value);
                        break;
                    case "VOLUMEMUTE":
                    case "MUTE":
                        return $this->mute($value);
                        break;
                    case "VOLUMEMUTE_ON":
                    case "MUTE_ON":
                        return $this->muteOn();
                        break;
                    case "VOLUMEMUTE_OFF":
                    case "MUTE_OFF":
                        return $this->muteOff();
                        break;
                    case "VOLUME":
                    case "VOLUMECONTROL":
                        return $this->volume($value);
                        break;
                    case "TREBLE":
                        return $this->treble($value);
                        break;
                    case "BASS":
                        return $this->bass($value);
                        break;
                    case "BALANCE":
                        return $this->balance($value);
                        break;
                    default:
                        return false;
                        break;
                }
        
            }
        
        
            function sendCmd($cmd)
            {
                $cmd .= chr(0x0D);
                if ($this->moxa_connection)
                {
                    $i = 0;
                    do {
                        $i++;
                        $res = socket_write($this->moxa_connection,$cmd);
                        if ($res===FALSE)
                        {
                            $this->disconnect();
                            $this->connect();
                            $res = socket_write($this->moxa_connection,$cmd);
                        }
        
                        $j = 0;
                        do {
                            $j++;
                            usleep(200000);
                            $response = $this->readResponse();
                            if ($response != FALSE)
                            {
                                if (count($response)<3) continue;
                                $status = substr($response[2],0,1);
                                if ($status == "C") return FALSE;
                                else if ($status == ">")
                                {
                                    $result = substr($response[2],2,2);
                                    return $result;
                                }
                                else continue;
                            }
                        } while ($j < 3);
                    } while ($i < 3);
                }
                return FALSE;
            }
        
            function readResponse()
            {
                global $id;
                if ($this->moxa_connection)
                {
                    $buf = socket_read($this->moxa_connection,8192);
                    if (strlen($buf) >= 10)
                    {
                        // logging($id,'Received Response: '.$buf);
                        $response = explode(' ',trim($buf));
                        return $response;
                    } else return FALSE;
                }
                return FALSE;
            }
        
            function power($status)
            {
                if ($status=="ON" || $status=="01") return $this->powerOn();
                else if ($status=="OFF" || $status=="00") return $this->powerOff();
            }
        
            function powerOn()
            {
                $cmd = "<".$this->ZoneID."PR01";     
                $result = $this->sendCmd($cmd);
                sleep(3);
                return $result;
            }
        
            function powerOff()
            {
                $cmd = "<".$this->ZoneID."PR00";
                return $this->sendCmd($cmd);
            }
        
            function inputSelect($input)
            {
                $cmd = "<".$this->ZoneID."CH".$input;
                return $this->sendCmd($cmd);
            }
        
            function mute($mute)
            {
                $cmd = "<".$this->ZoneID."MU".$mute;
                return $this->sendCmd($cmd);
            }
        
            function muteOn()
            {
                $cmd = "<".$this->ZoneID."MU00";
                return $this->sendCmd($cmd);
            }
        
            function muteOff()
            {
                $cmd = "<".$this->ZoneID."MU01";
                return $this->sendCmd($cmd);
            }
        
            function volume($vol) // 0-38
            {
                $cmd = "<".$this->ZoneID."VO".$vol;
                return $this->sendCmd($cmd);
            }
        
            function treble($treble) // 0-14
            {
                $cmd = "<".$this->ZoneID."TR".$treble;
                return $this->sendCmd($cmd);
            }
        
            function bass($bass) // 0-14
            {
                $cmd = "<".$this->ZoneID."BS".$bass;
                return $this->sendCmd($cmd);
            }
        
            function balance($balance) // 0-20
            {
                $cmd = "<".$this->ZoneID."BL".$balance;
                return $this->sendCmd($cmd);
            }
        
            function status()
            {
                global $id;
                static $lastPower = false,
                       $lastInputSelect = false,
                       $lastVolumeMute = false,
                       $lastVolumeControl = false,
                       $lastTreble = false,
                       $lastBass = false,
                       $lastBalance = false;
        
                $power = (int) $this->sendCmd("?".$this->ZoneID."PR");
                if ($power !== $lastPower)
                {
                    setLogicLinkAusgang($id,3,strval($power));
                    $lastPower = $power;
                    if ($power == 0)
                    {
                        // change all other ouputs to -1
                        setLogicLinkAusgang($id,4,-1);
                        setLogicLinkAusgang($id,5,-1);
                        setLogicLinkAusgang($id,6,-1);
                        setLogicLinkAusgang($id,7,-1);
                        setLogicLinkAusgang($id,8,-1);
                        setLogicLinkAusgang($id,9,-1);
                        $lastInputSelect = $lastVolumeMute = $lastVolumeControl =
                        $lastTreble = $lastBass = $lastBalance = false;
                    }
                }
        
                if ($power == 1)  // only retrieve further attributes when Monoprice is switched on
                {
                    $inputSelect = (int) $this->sendCmd("?".$this->ZoneID."CH");
                    if ($inputSelect !== $lastInputSelect)
                    {
                        setLogicLinkAusgang($id,4,$inputSelect);
                        $lastInputSelect = $inputSelect;
                    }
        
                    $volumeMute = (int) $this->sendCmd("?".$this->ZoneID."MU");
                    if ($volumeMute !== $lastVolumeMute)
                    {
                        setLogicLinkAusgang($id,5,$volumeMute);
                        $lastVolumeMute = $volumeMute;
                    }
        
                    $volumeControl = (int) $this->sendCmd("?".$this->ZoneID."VO");
                    if ($volumeControl !== $lastVolumeControl)
                    {
                        setLogicLinkAusgang($id,6,$volumeControl);
                        $lastVolumeControl = $volumeControl;
                    }
        
                    $treble = (int) $this->sendCmd("?".$this->ZoneID."TR");
                    if ($treble !== $lastTreble)
                    {
                         setLogicLinkAusgang($id,7,$treble);
                         $lastTreble = $treble;
                    }
        
                    $bass = (int) $this->sendCmd("?".$this->ZoneID."BS");
                    if ($bass !== $lastBass)
                    {
                         setLogicLinkAusgang($id,8,$bass);
                         $lastBass = $bass;
                    }
        
                    $balance = (int) $this->sendCmd("?".$this->ZoneID."BL");
                    if ($balance !== $lastBalance)
                    {
                         setLogicLinkAusgang($id,9,$balance);
                         $lastBalance = $balance;
                    }
                }
                return TRUE;
            }
        
        }
        
        ?>
        ###[/EXEC]###


        Gruß Ben
        Gruß Ben

        Kommentar


          #49
          Habe mal ein paar schnelle Änderung auf Basis deiner Erläuterung gemacht. Kannst ja mal testen.
          Im wesentlichen wartet die Senderoutine nun nicht mehr auf eine Antwort und sollte somit auch keinen Fehler mehr zurückgeben.
          Für Statusanfragen gibt es eine separate Sendefunktion, die danach auf eine Antwort wartet und diese dann zurückgibt.
          Jede empfangene Antwort sollte auf A10 und im Log ausgegeben werden, Außerdem fragt die function status() nun plain alle Statuswerte ab und gibt diese auf den Ausgängen aus. Hier wird, falls es überhaupt funktioniert, der gesamte Antwortstring ausgegeben. Dies müsstest du dann in der status() Funktion dann parsen und die eigentlichen Werte extrahieren, also z.B. das ">11PR01" in eine 1 umwandeln.

          Ich hoffe da du damit weiterkommst, ansonsten ist es kaum möglich ohne ein solches Gerät zu haben, sinnvoll helfen zu können.

          PHP-Code:
          ###[DEF]###
          [name        = Monoprice 10761 RS-232C    (v0.1) ]

          [e#1        = IP ]
          [e#2        = Port ]
          [e#3        = ZoneID ]
          [e#4        = Command ]
          [e#5        = Log level ]

          [a#1        = Result ]
          [a#2        = Error ]
          [a#3        = Power ]
          [a#4        = Input ]
          [a#5        = Volume Mute ]
          [a#6        = Volume ]
          [a#7        = Treble ]
          [a#8        = Bass ]
          [a#9        = Balance ]
          [a#10        = Response ]

          [v#1        = 0 ]
          [v#2        = 0 ]
          [v#100        = 0.1 ]
          [v#101        = 19000501 ]
          [v#102        = Monoprice 10761 RS-232C ]
          [v#103        = 0 ]

          ###[/DEF]###


          ###[HELP]###
          This LBS controls an Monoprice 10761 connected via a Ethernet-to-RS-232C adapter (e.g. Moxa NPort 5110)  to your home network.

          Simple Configutaion:
          E1: IP address of your RS-232/Ethernet converter in TCP/IP Server mode (should work with ser2net as well)
          E2: Port, which you have configured you TCP/IP Server on
          E3: ZoneID, which Zone you want to control of your Monoprice 10761 (10-All Zone|11-Zone1|12-Zone2|13-Zone3|14-Zone4|15-Zone5|16-Zone6)
          E4: The Command, which you want to send to your Monoprice 10761
          E5: Enable Logging (0-none|1-emerg|2-alert|3-crit|4-err|5-warning|6-notice|7-info|8-debug)

          Available commands:

          COMMAND - raw command accoring to the RS-232C documentation of Monoprice ==> e.g. "11 PR 01" (11=ZoneID, PR=Power, 01=ON)
          POWER (00|01)
          POWER_ON
          POWER_OFF
          VOLUMEMUTE (00-Volume mute on|01-Volume mute off)
          MUTE (same as VOLUMEMUTE)
          VOLUMEMUTE_ON (=MUTE 00)
          MUTE_ON (same as VOLUMEMUTE_ON)
          VOLUMEMUTE_OFF (=MUTE 01)
          MUTE_OFF (same as VOLUMEMUTE_OFF)
          VOLUME (00-38)
          VOLUMECONTROL (same as VOLUME)
          TREBLE (00-14)
          BASS  (00-14)
          BALANCE  (00-20)
          INPUTSELECT (01-Source 1|02-Source 2|03-Source 3|04-Source 4|05-Source 5|06-Source 6)
          INPUT        (same as INPUTSELECT)

          The outputs are updated automatically every 1/4 second. You can expect 1-3 seconds delay when sending an command, until the outputs are updated.
          The outputs correspond to the commands above and should self explanatory. If the Monoprice is switched off, only the POWER output contains valid information.
          Monoprice will not respond to other requests.

          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
          Prerequesite before using this LBS
          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

          - Install php-process:

          yum install php-process

          Enjoy ...

          Changelog:
          ==========
          v0.1: Initial version

          ###[/HELP]###


          ###[LBS]###
          <?

          function LB_LBSID_logging($id, $msg, $priority=8)
          {
              $E=getLogicEingangDataAll($id);
              $logLevel = getLogicElementVar($id,103);
              if (is_int($priority) && $priority<=$logLevel && $priority>0)
              {
                  $logLevelNames = array('none','emerg','alert','crit','err','warning','notice','info','debug');
                  $version = getLogicElementVar($id,100);
                  $lbsNo = getLogicElementVar($id,101);
                  $logName = getLogicElementVar($id,102) . '  ---  LBS'.$lbsNo;
                  strpos($_SERVER['SCRIPT_NAME'],$lbsNo) ? $scriptname='EXE'.$lbsNo : $scriptname = 'LBS'.$lbsNo;
                  writeToCustomLog($logName,str_pad($logLevelNames[$logLevel],7), $scriptname.":\t".$msg."\t[v$version]");
              }
          }

          function LB_LBSID($id) {
              if ($E=getLogicEingangDataAll($id)) {
                  setLogicElementVar($id,103,$E[5]['value']); //set loglevel to #VAR 103
                  LB_LBSID_logging($id,'Logic started');
                  if (getLogicElementVar($id,1)!=1) {
                      setLogicElementVar($id,1,1);
                      $uniqid = hexdec(uniqid());
                      setLogicElementVar($id,2,$uniqid);
                      callLogicFunctionExec(LBSID,$id);
                  } else {
                      $uniqid = getLogicElementVar($id,2);
                      $msg_queue = msg_get_queue ( $uniqid );
                      if ($E[4]['refresh']==1) {
                          $cmd = $E[4]['value'];
                          msg_send($msg_queue,1,$cmd);
                          LB_LBSID_logging($id,'Sending command to EXEC daemon: '.$cmd);
                      }
                  }
                  LB_LBSID_logging($id,'Logic finished');
              }
          }
          ?>
          ###[/LBS]###


          ###[EXEC]###
          <?
          require(dirname(__FILE__)."/../../../../main/include/php/incl_lbsexec.php");
          set_time_limit(0);
          sql_connect();

          function logging($id,$msg, $priority=8)
          {
              $E=getLogicEingangDataAll($id);
              $logLevel = getLogicElementVar($id,103);
              if (is_int($priority) && $priority<=$logLevel && $priority>0)
              {
                  $logLevelNames = array('none','emerg','alert','crit','err','warning','notice','info','debug');
                  $version = getLogicElementVar($id,100);
                  $lbsNo = getLogicElementVar($id,101);
                  $logName = getLogicElementVar($id,102) . '  ---  LBS'.$lbsNo;
                  strpos($_SERVER['SCRIPT_NAME'],$lbsNo) ? $scriptname='EXE'.$lbsNo : $scriptname = 'LBS'.$lbsNo;
                  writeToCustomLog($logName,str_pad($logLevelNames[$logLevel],7), $scriptname.":\t".$msg."\t[v$version]");
              }
          }

          if ($E=getLogicEingangDataAll($id))
          {
              $ip = $E[1]['value'];
              $port = $E[2]['value'];
              $ZoneID = $E[3]['value'];

              setLogicElementVar($id,103,$E[5]['value']); //set loglevel to #VAR 103

              logging($id,'Daemon started');

              $uniqid=getLogicElementVar($id,2);
              $msg_queue = msg_get_queue ( $uniqid );

              $mono = new mono_moxa($ip,$port,$ZoneID);
              $mono->connect();
              $commandExecutionTime = 0;

              while (getSysInfo(1))
              {
                  logging($id,'READ:'.MSG_IPC_NOWAIT);
                  ;
                  if (msg_receive($msg_queue,1,$msgtype, 4096, $msg, true, MSG_IPC_NOWAIT, $msg_error))
                  {
                      logging($id,'Received Command to be executed: '.$msg);
                      $command = explode(' ',$msg);
                      $result = $mono->command($command);
                      $commandExecutionTime = microtime(true);
                      if (!$result)
                      {
                          setLogicLinkAusgang($id,1,'ERROR');
                          setLogicLinkAusgang($id,2,1);
                      } else {
                          setLogicLinkAusgang($id,1,$result);
                          setLogicLinkAusgang($id,2,0);
                      }
                  }

                  // read status regularly but not during the first second after a command was issued
                  if ((microtime(true)-$commandExecutionTime)>=1)
                  {
                    $commandExecutionTime = 0;  
                    $mono->status();
                  }
                  usleep(100000);
                  logging($id,'END');
              }
              logging($id,'Daemon terminated');
          }

          $mono->disconnect();
          msg_remove_queue($msg_queue);

          sql_disconnect();


          class mono_moxa
          {
              private $moxa_ip;
              private $moxa_port;
              private $moxa_connection;
              private $ZoneID;

              function mono_moxa($moxa_ip, $moxa_port ,$ZoneID)
              {
                  $this->moxa_ip = $moxa_ip;
                  $this->moxa_port = $moxa_port;
                  $this->ZoneID = $ZoneID;

              }

              function connect()
              {
                  // Create socket
                  if ($this->moxa_connection = socket_create(AF_INET, SOCK_STREAM, SOL_TCP))
                  {
                      // Bind the source address
                      if (socket_bind($this->moxa_connection, global_serverIP))
                      {
                          // Connect to destination address
                          if (socket_connect($this->moxa_connection, $this->moxa_ip, $this->moxa_port))
                          {
                              if (socket_set_nonblock($this->moxa_connection)) return true;
                          }
                      }
                  }
                  return false;
              }

              function disconnect()
              {
                  if (isset($this->moxa_connection)) socket_close($this->moxa_connection);
              }

              function command($cmd)
              {
                  global $id;
                  logging($id,'Command: '.serialize($cmd));
                  $command = strtoupper($cmd[0]);
                  array_shift($cmd);
                  $value = strtoupper(implode(' ',$cmd));
                  logging($id,'Value: '.$value);
                  switch ($command)
                  {
                      case "STATUS":
                          return $this->status();
                          break;
                      case "COMMAND":
                          return $this->sendCmd($value);
                          break;
                      case "POWER":
                          return $this->power($value);
                          break;
                      case "POWER_ON":
                          return $this->powerOn();
                          break;
                      case "POWER_OFF":
                          return $this->powerOff();
                          break;
                      case "INPUTSELECT":
                      case "INPUT":
                          return $this->inputSelect($value);
                          break;
                      case "VOLUMEMUTE":
                      case "MUTE":
                          return $this->mute($value);
                          break;
                      case "VOLUMEMUTE_ON":
                      case "MUTE_ON":
                          return $this->muteOn();
                          break;
                      case "VOLUMEMUTE_OFF":
                      case "MUTE_OFF":
                          return $this->muteOff();
                          break;
                      case "VOLUME":
                      case "VOLUMECONTROL":
                          return $this->volume($value);
                          break;
                      case "TREBLE":
                          return $this->treble($value);
                          break;
                      case "BASS":
                          return $this->bass($value);
                          break;
                      case "BALANCE":
                          return $this->balance($value);
                          break;
                      default:
                          return false;
                          break;
                  }

              }


              function sendCmd($cmd)
              {
                  $cmd .= chr(0x0D);
                  if ($this->moxa_connection)
                  {
                          $res = socket_write($this->moxa_connection,$cmd);
                          if ($res===FALSE)
                          {
                              $this->disconnect();
                              $this->connect();
                              $res = socket_write($this->moxa_connection,$cmd);
                              return $res;
                          }

                  }
                  return FALSE;
              }

              function requestStatus($cmd)
              {
                  $cmd .= chr(0x0D);
                  if ($this->moxa_connection)
                  {
                      $res = socket_write($this->moxa_connection,$cmd);
                      if ($res===FALSE)
                      {
                          $this->disconnect();
                          $this->connect();
                          $res = socket_write($this->moxa_connection,$cmd);
                      }
                      if ($res)
                          return $this->readResponse();
                  }
                  return FALSE;
              }

              function readResponse()
              {
                  global $id;
                  if ($this->moxa_connection)
                  {
                      $buf = socket_read($this->moxa_connection,8192);
                      if (strlen($buf) >= 5)
                      {
                          logging($id,'Received Response: '.$buf);
                          $response = explode(' ',trim($buf));
                          logic_setOutput($id,10,$response);
                          return $response;
                      } else return FALSE;
                  }
                  return FALSE;
              }

              function power($status)
              {
                  if ($status=="ON" || $status=="01") return $this->powerOn();
                  else if ($status=="OFF" || $status=="00") return $this->powerOff();
              }

              function powerOn()
              {
                  $cmd = "<".$this->ZoneID."PR01";     
                  $result = $this->sendCmd($cmd);
                  sleep(3);
                  return $result;
              }

              function powerOff()
              {
                  $cmd = "<".$this->ZoneID."PR00";
                  return $this->sendCmd($cmd);
              }

              function inputSelect($input)
              {
                  $cmd = "<".$this->ZoneID."CH".$input;
                  return $this->sendCmd($cmd);
              }

              function mute($mute)
              {
                  $cmd = "<".$this->ZoneID."MU".$mute;
                  return $this->sendCmd($cmd);
              }

              function muteOn()
              {
                  $cmd = "<".$this->ZoneID."MU00";
                  return $this->sendCmd($cmd);
              }

              function muteOff()
              {
                  $cmd = "<".$this->ZoneID."MU01";
                  return $this->sendCmd($cmd);
              }

              function volume($vol) // 0-38
              {
                  $cmd = "<".$this->ZoneID."VO".$vol;
                  return $this->sendCmd($cmd);
              }

              function treble($treble) // 0-14
              {
                  $cmd = "<".$this->ZoneID."TR".$treble;
                  return $this->sendCmd($cmd);
              }

              function bass($bass) // 0-14
              {
                  $cmd = "<".$this->ZoneID."BS".$bass;
                  return $this->sendCmd($cmd);
              }

              function balance($balance) // 0-20
              {
                  $cmd = "<".$this->ZoneID."BL".$balance;
                  return $this->sendCmd($cmd);
              }

              function status()
              {
                  global $id;

                  $power = $this->requestStatus("?".$this->ZoneID."PR");
                  logic_setOutput($id,3,$power);

                  $inputSelect = $this->requestStatus("?".$this->ZoneID."CH");
                  logic_setOutput($id,4,$inputSelect);

                  $volumeMute = $this->requestStatus("?".$this->ZoneID."MU");
                  logic_setOutput($id,5,$volumeMute);

                  $volumeControl = $this->requestStatus("?".$this->ZoneID."VO");
                  logic_setOutput($id,6,$volumeControl);

                  $treble = $this->requestStatus("?".$this->ZoneID."TR");
                  logic_setOutput($id,7,$treble);

                  $bass = $this->requestStatus("?".$this->ZoneID."BS");
                  logic_setOutput($id,8,$bass);

                  $balance = $this->requestStatus("?".$this->ZoneID."BL");
                  logic_setOutput($id,9,$balance);

                  return TRUE;
              }

          }

          ?>
          ###[/EXEC]###

          Kommentar


            #50
            Vielen vielen Dank .

            Gruß Ben

            Kommentar


              #51
              Habs grad mal geschwind getestet.
              Also im Fehlerlog haut er mir jetzt andauernd folgende Meldung raus:
              Code:
              2017-10-04 19:10:01    170984    ?    3538    Datei: /var/edomi-backups/_public/www/shared/php/base.php | Fehlercode: 2 | Zeile: 284 | utf8_decode() expects parameter 1 to be string, array given    ERROR
              2017-10-04 19:10:01    173193    ?    3538    Datei: /var/edomi-backups/_public/www/shared/php/base.php | Fehlercode: 2 | Zeile: 284 | utf8_decode() expects parameter 1 to be string, array given    ERROR
              2017-10-04 19:10:01    690330    ?    3538    Datei: /var/edomi-backups/_public/www/shared/php/base.php | Fehlercode: 2 | Zeile: 284 | utf8_decode() expects parameter 1 to be string, array given    ERROR
              2017-10-04 19:10:01    692168    ?    3538    Datei: /var/edomi-backups/_public/www/shared/php/base.php | Fehlercode: 2 | Zeile: 284 | utf8_decode() expects parameter 1 to be string, array given    ERROR
              2017-10-04 19:10:01    698857    ?    3538    Datei: /var/edomi-backups/_public/www/shared/php/base.php | Fehlercode: 2 | Zeile: 284 | utf8_decode() expects parameter 1 to be string, array given    ERROR
              2017-10-04 19:10:01    700577    ?    3538    Datei: /var/edomi-backups/_public/www/shared/php/base.php | Fehlercode: 2 | Zeile: 284 | utf8_decode() expects parameter 1 to be string, array given    ERROR
              2017-10-04 19:10:01    707047    ?    3538    Datei: /var/edomi-backups/_public/www/shared/php/base.php | Fehlercode: 2 | Zeile: 284 | utf8_decode() expects parameter 1 to be string, array given    ERROR
              2017-10-04 19:10:01    708662    ?    3538    Datei: /var/edomi-backups/_public/www/shared/php/base.php | Fehlercode: 2 | Zeile: 284 | utf8_decode() expects parameter 1 to be string, array given    ERROR
              2017-10-04 19:10:01    816498    ?    3538    Datei: /var/edomi-backups/_public/www/shared/php/base.php | Fehlercode: 2 | Zeile: 284 | utf8_decode() expects parameter 1 to be string, array given    ERROR
              2017-10-04 19:10:01    818547    ?    3538    Datei: /var/edomi-backups/_public/www/shared/php/base.php | Fehlercode: 2 | Zeile: 284 | utf8_decode() expects parameter 1 to be string, array given    ERROR
              2017-10-04 19:10:01    823932    ?    3538    Datei: /var/edomi-backups/_public/www/shared/php/base.php | Fehlercode: 2 | Zeile: 284 | utf8_decode() expects parameter 1 to be string, array given    ERROR
              Und im Induvidual-Log folgendes:
              Code:
              2017-10-04 19:11:36    926131    3538    debug    EXE19000501:    END    [v0.1]
              2017-10-04 19:11:36    928177    3538    debug    EXE19000501:    READ:1    [v0.1]
              2017-10-04 19:11:37    041893    3538    debug    EXE19000501:    END    [v0.1]
              2017-10-04 19:11:37    043796    3538    debug    EXE19000501:    READ:1    [v0.1]
              2017-10-04 19:11:37    045609    3538    debug    EXE19000501:    Received Response: 1MU[CR][LF]#>11MU00[CR][CR][LF]#?11VO[CR][LF]#>11VO15[CR][CR][LF]#?11TR[CR][LF]#>11TR07[CR][CR][LF]#?11BS[CR][LF]#>11BS07[CR][CR][LF]#?11BL[CR][LF]#>11BL10[CR][CR][LF]#?11PR[CR][LF]#>11PR00[CR][CR][LF]#?11CH[CR][LF]#>11CH01[CR][CR][LF]#?11MU[CR][LF]#>11MU00[CR][CR][LF]#?11VO[CR][LF]#>11VO15[CR][CR][LF]#?11TR[CR][LF]#>11TR07[CR][CR][LF]#?11BS[CR][LF]#>11BS07[CR][CR][LF]#?11BL[CR][LF]#>11BL10[CR][CR][LF]#?11PR[CR][LF]#>11PR00[CR][CR][LF]#?11CH[CR][LF]#>11CH01[CR][CR][LF]#?11MU[CR][LF]#>11MU00[CR][CR][LF]#?11VO[CR][LF]#>11VO15[CR][CR][LF]#?11TR[CR][LF]#>11TR07[CR][CR][LF]#?11BS[CR][LF]#>11BS07[CR][CR][LF]#?11BL[CR][LF]#>11BL10[CR][CR][LF]#?11PR[CR][LF]#>11PR00[CR][CR][LF]#?11CH[CR][LF]#>11CH01[CR][CR][LF]#?11MU[CR][LF]#>11MU00[CR][CR][LF]#?11VO[CR][LF]#>11VO15[CR][CR][LF]#?11TR[CR][LF]#>11TR07[CR][CR][LF]#?11BS[CR][LF]#>11BS07[CR][CR][LF]#?11BL[CR][LF]#>11BL10[CR][CR][LF]#?11PR[CR][LF]#>11PR00[CR][CR][LF]#?11CH[CR][LF]#>11CH01[CR][CR][LF]#?11MU[CR][LF]#>11MU00[CR][CR][LF]#?11VO[CR][LF]#>11VO15[CR][CR][LF]#?11TR[CR][LF]#>11TR07[CR][CR][LF]#?11BS[CR][LF]#>11BS07[CR][CR][LF]#?11BL[CR][LF]#>11BL10[CR][CR][LF]#?11PR[CR][LF]#>11PR00[CR][CR][LF]#?11CH[CR][LF]#>11CH01[CR][CR][LF]#?11MU[CR][LF]#>11MU00[CR][CR][LF]#?11VO[CR][LF]#>11VO15[CR][CR][LF]#?11TR[CR][LF]#>11TR07[CR][CR][LF]#?11BS[CR][LF]#>11BS07[CR][CR][LF]#?11BL[CR][LF]#>11BL10[CR][CR][LF]#?11PR[CR][LF]#>11PR00[CR][CR][LF]#?11CH[CR][LF]#>11CH01[CR][CR][LF]#?11MU[CR][LF]#>11MU00[CR][CR][LF]#?11VO[CR][LF]#>11VO15[CR][CR][LF]#?11TR[CR][LF]#>11TR07[CR][CR][LF]#?11BS[CR][LF]#>11BS07[CR][CR][LF]#?11BL[CR][LF]#>11BL10[CR][CR][LF]#?11PR[CR][LF]#>11PR00[CR][CR][LF]#?11CH[CR][LF]#>11CH01[CR][CR][LF]#?11MU[CR][LF]#>11MU00[CR][CR][LF]#?11VO[CR][LF]#>11VO15[CR][CR][LF]#?11TR[CR][LF]#>11TR07[CR][CR][LF]#?11BS[CR][LF]#>11BS07[CR][CR][LF]#?11BL[CR][LF]#>11BL10[CR][CR][LF]#?11PR[CR][LF]#>11PR00[CR][CR][LF]#?11CH[CR][LF]#>11CH01[CR][CR][LF]#?11MU[CR][LF]#>11MU00[CR][CR][LF]#?11VO[CR][LF]#>11VO15[CR][CR][LF]#?11TR[CR][LF]#>11TR07[CR][CR][LF]#?11BS[CR][LF]#>11BS07[CR][CR][LF]#?11BL[CR][LF]#>11BL10[CR][CR][LF]#?11PR[CR][LF]#>11PR00[CR][CR][LF]#?11CH[CR][LF]#>11CH01[CR][CR][LF]#?11MU[CR][LF]#>11MU00[CR][CR][LF]#?11VO[CR][LF]#>11VO15[CR][CR][LF]#?11TR[CR][LF]#>11TR07[CR][CR][LF]#?11BS[CR][LF]#>11BS07[CR][CR][LF]#?11BL[CR][LF]#>    [v0.1]
              2017-10-04 19:11:37    162491    3538    debug    EXE19000501:    END    [v0.1]
              2017-10-04 19:11:37    164148    3538    debug    EXE19000501:    READ:1    [v0.1]
              2017-10-04 19:11:37    277741    3538    debug    EXE19000501:    END    [v0.1]
              2017-10-04 19:11:37    279833    3538    debug    EXE19000501:    READ:1    [v0.1]
              2017-10-04 19:11:37    394315    3538    debug    EXE19000501:    END    [v0.1]
              2017-10-04 19:11:37    396303    3538    debug    EXE19000501:    READ:1    [v0.1]
              2017-10-04 19:11:37    510643    3538    debug    EXE19000501:    END    [v0.1]
              2017-10-04 19:11:37    512259    3538    debug    EXE19000501:    READ:1    [v0.1]
              2017-10-04 19:11:37    625920    3538    debug    EXE19000501:    END    [v0.1]
              2017-10-04 19:11:37    627125    3538    debug    EXE19000501:    READ:1    [v0.1]
              2017-10-04 19:11:37    740505    3538    debug    EXE19000501:    END    [v0.1]
              2017-10-04 19:11:37    742295    3538    debug    EXE19000501:    READ:1    [v0.1]
              2017-10-04 19:11:37    744529    3538    debug    EXE19000501:    Received Response: 11BL10[CR][CR][LF]#?11PR[CR][LF]#>11PR00[CR][CR][LF]#?11CH[CR][LF]#>11CH01[CR][CR][LF]#?11MU[CR][LF]#>11MU00[CR][CR][LF]#?11VO[CR][LF]#>11VO15[CR][CR][LF]#?11TR[CR][LF]#>11TR07[CR][CR][LF]#?11BS[CR][LF]#>11BS07[CR][CR][LF]#?11BL[CR][LF]#>11BL10[CR][CR][LF]#?11PR[CR][LF]#>11PR00[CR][CR][LF]#?11CH[CR][LF]#>11CH01[CR][CR][LF]#?11MU[CR][LF]#>11MU00[CR][CR][LF]#?11VO[CR][LF]#>11VO15[CR][CR][LF]#?11TR[CR][LF]#>11TR07[CR][CR][LF]#?11BS[CR][LF]#>11BS07[CR][CR][LF]#?11BL[CR][LF]#>11BL10[CR][CR][LF]#?11PR[CR][LF]#>11PR00[CR][CR][LF]#?11CH[CR][LF]#>11CH01[CR][CR][LF]#?11MU[CR][LF]#>11MU00[CR][CR][LF]#?11VO[CR][LF]#>11VO15[CR][CR][LF]#?11TR[CR][LF]#>11TR07[CR][CR][LF]#?11BS[CR][LF]#>11BS07[CR][CR][LF]#?11BL[CR][LF]#>11BL10[CR][CR][LF]#?11PR[CR][LF]#>11PR00[CR][CR][LF]#?11CH[CR][LF]#>11CH01[CR][CR][LF]#?11MU[CR][LF]#>11MU00[CR][CR][LF]#?11VO[CR][LF]#>11VO15[CR][CR][LF]#?11TR[CR][LF]#>11TR07[CR][CR][LF]#?11BS[CR][LF]#>11BS07[CR][CR][LF]#?11BL[CR][LF]#>11BL10[CR][CR][LF]#?11PR[CR][LF]#>11PR00[CR][CR][LF]#?11CH[CR][LF]#>11CH01[CR][CR][LF]#?11MU[CR][LF]#>11MU00[CR][CR][LF]#?11VO[CR][LF]#>11VO15[CR][CR][LF]#?11TR[CR][LF]#>11TR07[CR][CR][LF]#?11BS[CR][LF]#>11BS07[CR][CR][LF]#?11BL[CR][LF]#>11BL10[CR][CR][LF]#?11PR[CR][LF]#>11PR00[CR][CR][LF]#?11CH[CR][LF]#>11    [v0.1]
              2017-10-04 19:11:37    751892    3538    debug    EXE19000501:    Received Response: CH01[CR][CR][LF]    [v0.1]
              2017-10-04 19:11:37    758210    3538    debug    EXE19000501:    Received Response: #?11MU[CR]    [v0.1]
              2017-10-04 19:11:37    765444    3538    debug    EXE19000501:    Received Response: [LF]#>11MU    [v0.1]
              2017-10-04 19:11:37    772927    3538    debug    EXE19000501:    Received Response: 00[CR][CR][LF]#    [v0.1]
              2017-10-04 19:11:37    779905    3538    debug    EXE19000501:    Received Response: ?11VO[CR][LF]#    [v0.1]
              2017-10-04 19:11:37    788579    3538    debug    EXE19000501:    Received Response: >11VO1    [v0.1]
              2017-10-04 19:11:37    897202    3538    debug    EXE19000501:    END    [v0.1]
              2017-10-04 19:11:37    898689    3538    debug    EXE19000501:    READ:1    [v0.1]
              2017-10-04 19:11:37    900340    3538    debug    EXE19000501:    Received Response: 5[CR][CR][LF]#?11TR[CR][LF]#>11TR07[CR][CR][LF]#?11BS[CR][LF]#>11BS07[CR][CR][LF]#?11BL[CR][LF]#>11BL10[CR][CR][LF]#?11PR[CR][LF]#>11PR00[CR][CR][LF]#?11CH[CR][LF]#>11CH0    [v0.1]
              2017-10-04 19:11:37    906529    3538    debug    EXE19000501:    Received Response: 1[CR][CR][LF]#?11MU[CR][LF]#>11MU00[CR]    [v0.1]
              2017-10-04 19:11:37    913116    3538    debug    EXE19000501:    Received Response: [CR][LF]#?1    [v0.1]
              2017-10-04 19:11:37    919097    3538    debug    EXE19000501:    Received Response: 1VO[CR][LF]#>    [v0.1]
              2017-10-04 19:11:37    925596    3538    debug    EXE19000501:    Received Response: 11VO15    [v0.1]
              2017-10-04 19:11:37    931833    3538    debug    EXE19000501:    Received Response: [CR][CR][LF]#?    [v0.1]
              2017-10-04 19:11:37    937546    3538    debug    EXE19000501:    Received Response: 11TR[CR][LF]    [v0.1]
              2017-10-04 19:11:38    044857    3538    debug    EXE19000501:    END    [v0.1]
              2017-10-04 19:11:38    046092    3538    debug    EXE19000501:    READ:1    [v0.1]
              2017-10-04 19:11:38    047197    3538    debug    EXE19000501:    Received Response: #>11TR07[CR][CR][LF]#?11BS[CR][LF]#>11BS07[CR][CR][LF]#?11BL[CR][LF]#>11BL10[CR][CR][LF]#?11PR[CR][LF]#>11PR00[CR][CR][LF]#?11CH[CR][LF]#>11CH01[CR][CR][LF]#?11MU[CR][LF]    [v0.1]
              2017-10-04 19:11:38    053601    3538    debug    EXE19000501:    Received Response: #>11MU00[CR][CR][LF]#?11V    [v0.1]
              2017-10-04 19:11:38    063657    3538    debug    EXE19000501:    Received Response: O[CR][LF]#>11    [v0.1]
              2017-10-04 19:11:38    070437    3538    debug    EXE19000501:    Received Response: VO15[CR][CR][LF]#?1    [v0.1]
              2017-10-04 19:11:38    077372    3538    debug    EXE19000501:    Received Response: 1TR[CR][LF]#    [v0.1]
              2017-10-04 19:11:38    084737    3538    debug    EXE19000501:    Received Response: >11TR0    [v0.1]
              2017-10-04 19:11:38    091357    3538    debug    EXE19000501:    Received Response: 7[CR][CR][LF]#?1    [v0.1]
              Also so wies aussieht kommen die Antworten auch zurück, aber im LBS unter Response wird nichts angezeigt.
              Und sobald ich ein Kommando ausführe kommt immer noch ein Error zurück.

              Ich dacht mir schon, dass es nicht leicht ist, wenn man das Gerät nicht zum testen hat, aber ich bin trotzdem für jedes kleine bisschen Hilfe dankbar, weil alleine würd ich gar nicht weiter kommen
              Gruß Ben

              Kommentar


                #52
                Laut Spezifikation sendet das Device auch nach jedem Befehl eine entsprechende Antwort.

                Versuch mal folgendes:

                Hier werden jetzt keine Statusausgänge gesetzt, sondern du musst ins Log schauen, bzw auf A10, ob was ankommt, was Sinn macht.
                Du musst ein Statusupdate allerdings mit dem Befehl "STATUS" an E4 triggern.

                Danach mal das Log posten.

                PHP-Code:
                ###[DEF]###
                [name        = Monoprice 10761 RS-232C    (v0.1) ]

                [e#1        = IP ]
                [e#2        = Port ]
                [e#3        = ZoneID ]
                [e#4        = Command ]
                [e#5        = Log level ]

                [a#1        = Result ]
                [a#2        = Error ]
                [a#3        = Power ]
                [a#4        = Input ]
                [a#5        = Volume Mute ]
                [a#6        = Volume ]
                [a#7        = Treble ]
                [a#8        = Bass ]
                [a#9        = Balance ]
                [a#10        = Response ]

                [v#1        = 0 ]
                [v#2        = 0 ]
                [v#100        = 0.1 ]
                [v#101        = 19000501 ]
                [v#102        = Monoprice 10761 RS-232C ]
                [v#103        = 0 ]

                ###[/DEF]###


                ###[HELP]###
                This LBS controls an Monoprice 10761 connected via a Ethernet-to-RS-232C adapter (e.g. Moxa NPort 5110)  to your home network.

                Simple Configutaion:
                E1: IP address of your RS-232/Ethernet converter in TCP/IP Server mode (should work with ser2net as well)
                E2: Port, which you have configured you TCP/IP Server on
                E3: ZoneID, which Zone you want to control of your Monoprice 10761 (10-All Zone|11-Zone1|12-Zone2|13-Zone3|14-Zone4|15-Zone5|16-Zone6)
                E4: The Command, which you want to send to your Monoprice 10761
                E5: Enable Logging (0-none|1-emerg|2-alert|3-crit|4-err|5-warning|6-notice|7-info|8-debug)

                Available commands:

                COMMAND - raw command accoring to the RS-232C documentation of Monoprice ==> e.g. "11 PR 01" (11=ZoneID, PR=Power, 01=ON)
                POWER (00|01)
                POWER_ON
                POWER_OFF
                VOLUMEMUTE (00-Volume mute on|01-Volume mute off)
                MUTE (same as VOLUMEMUTE)
                VOLUMEMUTE_ON (=MUTE 00)
                MUTE_ON (same as VOLUMEMUTE_ON)
                VOLUMEMUTE_OFF (=MUTE 01)
                MUTE_OFF (same as VOLUMEMUTE_OFF)
                VOLUME (00-38)
                VOLUMECONTROL (same as VOLUME)
                TREBLE (00-14)
                BASS  (00-14)
                BALANCE  (00-20)
                INPUTSELECT (01-Source 1|02-Source 2|03-Source 3|04-Source 4|05-Source 5|06-Source 6)
                INPUT        (same as INPUTSELECT)

                The outputs are updated automatically every 1/4 second. You can expect 1-3 seconds delay when sending an command, until the outputs are updated.
                The outputs correspond to the commands above and should self explanatory. If the Monoprice is switched off, only the POWER output contains valid information.
                Monoprice will not respond to other requests.

                !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                Prerequesite before using this LBS
                !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

                - Install php-process:

                yum install php-process

                Enjoy ...

                Changelog:
                ==========
                v0.1: Initial version

                ###[/HELP]###


                ###[LBS]###
                <?

                function LB_LBSID_logging($id, $msg, $priority = 8)
                {
                    $E = getLogicEingangDataAll($id);
                    $logLevel = getLogicElementVar($id, 103);
                    if (is_int($priority) && $priority <= $logLevel && $priority > 0) {
                        $logLevelNames = array(
                            'none',
                            'emerg',
                            'alert',
                            'crit',
                            'err',
                            'warning',
                            'notice',
                            'info',
                            'debug'
                        );
                        $version = getLogicElementVar($id, 100);
                        $lbsNo = getLogicElementVar($id, 101);
                        $logName = getLogicElementVar($id, 102) . '  ---  LBS' . $lbsNo;
                        strpos($_SERVER['SCRIPT_NAME'], $lbsNo) ? $scriptname = 'EXE' . $lbsNo : $scriptname = 'LBS' . $lbsNo;
                        writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . ":\t" . $msg . "\t[v$version]");
                    }
                }

                function LB_LBSID($id)
                {
                    if ($E = getLogicEingangDataAll($id)) {
                        setLogicElementVar($id, 103, $E[5]['value']); // set loglevel to #VAR 103
                        LB_LBSID_logging($id, 'Logic started');
                        if (getLogicElementVar($id, 1) != 1) {
                            setLogicElementVar($id, 1, 1);
                            $uniqid = hexdec(uniqid());
                            setLogicElementVar($id, 2, $uniqid);
                            callLogicFunctionExec(LBSID, $id);
                        } else {
                            $uniqid = getLogicElementVar($id, 2);
                            $msg_queue = msg_get_queue($uniqid);
                            if ($E[4]['refresh'] == 1) {
                                $cmd = $E[4]['value'];
                                msg_send($msg_queue, 1, $cmd);
                                LB_LBSID_logging($id, 'Sending command to EXEC daemon: ' . $cmd);
                            }
                        }
                        LB_LBSID_logging($id, 'Logic finished');
                    }
                }
                ?>
                ###[/LBS]###


                ###[EXEC]###
                <?
                require (dirname(__FILE__) . "/../../../../main/include/php/incl_lbsexec.php");
                set_time_limit(0);
                sql_connect();

                function logging($id, $msg, $priority = 8)
                {
                    $E = getLogicEingangDataAll($id);
                    $logLevel = getLogicElementVar($id, 103);
                    if (is_int($priority) && $priority <= $logLevel && $priority > 0) {
                        $logLevelNames = array(
                            'none',
                            'emerg',
                            'alert',
                            'crit',
                            'err',
                            'warning',
                            'notice',
                            'info',
                            'debug'
                        );
                        $version = getLogicElementVar($id, 100);
                        $lbsNo = getLogicElementVar($id, 101);
                        $logName = getLogicElementVar($id, 102) . '  ---  LBS' . $lbsNo;
                        strpos($_SERVER['SCRIPT_NAME'], $lbsNo) ? $scriptname = 'EXE' . $lbsNo : $scriptname = 'LBS' . $lbsNo;
                        writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . ":\t" . $msg . "\t[v$version]");
                    }
                }

                if ($E = getLogicEingangDataAll($id)) {
                    $ip = $E[1]['value'];
                    $port = $E[2]['value'];
                    $ZoneID = $E[3]['value'];

                    setLogicElementVar($id, 103, $E[5]['value']); // set loglevel to #VAR 103

                    logging($id, 'Daemon started');

                    $uniqid = getLogicElementVar($id, 2);
                    $msg_queue = msg_get_queue($uniqid);

                    $mono = new mono_moxa($ip, $port, $ZoneID);
                    $mono->connect();
                    $commandExecutionTime = 0;

                    while (getSysInfo(1)) {
                        if (msg_receive($msg_queue, 1, $msgtype, 4096, $msg, true, MSG_IPC_NOWAIT, $msg_error)) {
                            logging($id, 'Received Command to be executed: ' . $msg);
                            $command = explode(' ', $msg);
                            $result = $mono->command($command);
                            if (! $result) {
                                setLogicLinkAusgang($id, 1, 'ERROR');
                                setLogicLinkAusgang($id, 2, 1);
                            } else {
                                setLogicLinkAusgang($id, 1, 'OK');
                                setLogicLinkAusgang($id, 2, 0);
                            }
                        }

                       $mono->read();
                        usleep(250000);
                    }
                    logging($id, 'Daemon terminated');
                }

                $mono->disconnect();
                msg_remove_queue($msg_queue);

                sql_disconnect();

                class mono_moxa
                {

                    private $moxa_ip;

                    private $moxa_port;

                    private $moxa_connection;

                    private $ZoneID;

                    function mono_moxa($moxa_ip, $moxa_port, $ZoneID)
                    {
                        $this->moxa_ip = $moxa_ip;
                        $this->moxa_port = $moxa_port;
                        $this->ZoneID = $ZoneID;
                    }

                    function connect()
                    {
                        // Create socket
                        if ($this->moxa_connection = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) {
                            // Bind the source address
                            if (socket_bind($this->moxa_connection, global_serverIP)) {
                                // Connect to destination address
                                if (socket_connect($this->moxa_connection, $this->moxa_ip, $this->moxa_port)) {
                                    if (socket_set_nonblock($this->moxa_connection))
                                        return true;
                                }
                            }
                        }
                        return false;
                    }

                    function disconnect()
                    {
                        if (isset($this->moxa_connection))
                            socket_close($this->moxa_connection);
                    }

                    function command($cmd)
                    {
                        global $id;
                        logging($id, 'Command: ' . serialize($cmd));
                        $command = strtoupper($cmd[0]);
                        array_shift($cmd);
                        $value = strtoupper(implode(' ', $cmd));
                        logging($id, 'Value: ' . $value);
                        switch ($command) {
                            case "STATUS":
                                return $this->status();
                                break;
                            case "COMMAND":
                                return $this->sendCmd($value);
                                break;
                            case "POWER":
                                return $this->power($value);
                                break;
                            case "POWER_ON":
                                return $this->powerOn();
                                break;
                            case "POWER_OFF":
                                return $this->powerOff();
                                break;
                            case "INPUTSELECT":
                            case "INPUT":
                                return $this->inputSelect($value);
                                break;
                            case "VOLUMEMUTE":
                            case "MUTE":
                                return $this->mute($value);
                                break;
                            case "VOLUMEMUTE_ON":
                            case "MUTE_ON":
                                return $this->muteOn();
                                break;
                            case "VOLUMEMUTE_OFF":
                            case "MUTE_OFF":
                                return $this->muteOff();
                                break;
                            case "VOLUME":
                            case "VOLUMECONTROL":
                                return $this->volume($value);
                                break;
                            case "TREBLE":
                                return $this->treble($value);
                                break;
                            case "BASS":
                                return $this->bass($value);
                                break;
                            case "BALANCE":
                                return $this->balance($value);
                                break;
                            default:
                                return false;
                                break;
                        }
                    }

                    function sendCmd($cmd)
                    {
                        global $id;
                        $cmd .= chr(0x0D);
                        if ($this->moxa_connection) {
                            logging($id,"Sending: ".$cmd);
                            $res = socket_write($this->moxa_connection, $cmd);
                            if ($res === FALSE) {
                                $this->disconnect();
                                $this->connect();
                                $res = socket_write($this->moxa_connection, $cmd);
                                if ($res !== FALSE)
                                    return true;
                            }
                        }
                        return FALSE;
                    }


                    function read()
                    {
                        global $id;
                        if ($this->moxa_connection) {
                            $buf = socket_read($this->moxa_connection, 8192, PHP_NORMAL_READ);
                            if (strlen($buf) >= 6) {
                                logging($id, 'Received Response: ' . $buf);
                                $response = explode(' ', trim($buf));
                                $response = preg_match('/.*>([0-9]{2})([A-Z]{2})([0-9]{2})/',$buf,$matches);
                                if ($response) {
                                    $controlObjectCode = $matches[1];
                                    $controlActionCode = $matches[2];
                                    $controlValue = $matches[3];
                                    logging($id, "Object: $controlObjectCode / Action: $controlActionCode / Value: $controlValue");
                                }
                                logic_setOutput($id, 10, $controlObjectCode.'|'.$controlActionCode.'|'.$controlValue);
                                return $response;
                            } else
                                return FALSE;
                        }
                        return FALSE;
                    }

                    function power($status)
                    {
                        if ($status == "ON" || $status == "01")
                            return $this->powerOn();
                        else if ($status == "OFF" || $status == "00")
                            return $this->powerOff();
                    }

                    function powerOn()
                    {
                        $cmd = "<" . $this->ZoneID . "PR01";
                        $result = $this->sendCmd($cmd);
                        sleep(3);
                        return $result;
                    }

                    function powerOff()
                    {
                        $cmd = "<" . $this->ZoneID . "PR00";
                        return $this->sendCmd($cmd);
                    }

                    function inputSelect($input)
                    {
                        $cmd = "<" . $this->ZoneID . "CH" . $input;
                        return $this->sendCmd($cmd);
                    }

                    function mute($mute)
                    {
                        $cmd = "<" . $this->ZoneID . "MU" . $mute;
                        return $this->sendCmd($cmd);
                    }

                    function muteOn()
                    {
                        $cmd = "<" . $this->ZoneID . "MU00";
                        return $this->sendCmd($cmd);
                    }

                    function muteOff()
                    {
                        $cmd = "<" . $this->ZoneID . "MU01";
                        return $this->sendCmd($cmd);
                    }

                    function volume($vol) // 0-38
                    {
                        $cmd = "<" . $this->ZoneID . "VO" . $vol;
                        return $this->sendCmd($cmd);
                    }

                    function treble($treble) // 0-14
                    {
                        $cmd = "<" . $this->ZoneID . "TR" . $treble;
                        return $this->sendCmd($cmd);
                    }

                    function bass($bass) // 0-14
                    {
                        $cmd = "<" . $this->ZoneID . "BS" . $bass;
                        return $this->sendCmd($cmd);
                    }

                    function balance($balance) // 0-20
                    {
                        $cmd = "<" . $this->ZoneID . "BL" . $balance;
                        return $this->sendCmd($cmd);
                    }

                    function status()
                    {
                        global $id;
                        logging($id, 'Updating Status');
                        $this->sendCmd("?" . $this->ZoneID . "PR");
                        $this->sendCmd("?" . $this->ZoneID . "CH");
                        $this->sendCmd("?" . $this->ZoneID . "MU");
                        $this->sendCmd("?" . $this->ZoneID . "VO");
                        $this->sendCmd("?" . $this->ZoneID . "TR");
                        $this->sendCmd("?" . $this->ZoneID . "BS");
                        $this->sendCmd("?" . $this->ZoneID . "BL");

                    }
                }

                ?>
                ###[/EXEC]###

                Kommentar


                  #53
                  Okay, ich konnts jetzt mal nachstellen. Gestern wars doch bissel zu spät .
                  Also folgendes zuerst. Wenn ich den LBS aktiviere geht nach Edomi-Start die CPU ziemlich lange auf 100% und trudelt sich dann irgendwann zwischen 50-70% ein.
                  Ohne den LBS hab ich selten über 20%.

                  Dann das nächste Dubiose wenn Monoprice per Schaltaktor eingeschalten ist und ich schick ein Befehl, z.B. POWER_ON. passiert nichts. Hier Log:
                  Code:
                  2017-10-05 15:22:59    146887    16296    debug    LBS19000501:    Logic started    [v0.1]
                  2017-10-05 15:22:59    163404    16296    debug    LBS19000501:    Logic finished    [v0.1]
                  2017-10-05 15:22:59    263356    16398    debug    EXE19000501:    Daemon started    [v0.1]
                  2017-10-05 15:34:19    182106    16296    debug    LBS19000501:    Logic started    [v0.1]
                  2017-10-05 15:34:19    185240    16296    debug    LBS19000501:    Sending command to EXEC daemon: POWER_ON    [v0.1]
                  2017-10-05 15:34:19    186497    16296    debug    LBS19000501:    Logic finished    [v0.1]
                  2017-10-05 15:53:30    265256    1807    debug    LBS19000501:    Logic started    [v0.1]
                  2017-10-05 15:53:30    284853    1807    debug    LBS19000501:    Logic finished    [v0.1]
                  2017-10-05 15:53:30    384105    1883    debug    EXE19000501:    Daemon started    [v0.1]
                  2017-10-05 16:06:57    718189    2600    debug    LBS19000501:    Logic started    [v0.1]
                  2017-10-05 16:06:57    738557    2600    debug    LBS19000501:    Logic finished    [v0.1]
                  2017-10-05 16:06:57    830230    2701    debug    EXE19000501:    Daemon started    [v0.1]
                  2017-10-05 16:10:42    003181    2600    debug    LBS19000501:    Logic started    [v0.1]
                  Wenn ich jetzt aber den Monoprice per Schaltaktor ausschalte und dann einen Befehl schicke, z.B. POWER_ON und schalte in danach per Schataktor ein scheint es zu funktionioeren.Hier das Log dazu:
                  Code:
                  2017-10-05 16:24:23    795975    2600    debug    LBS19000501:    Logic started    [v0.1]
                  2017-10-05 16:24:23    799398    2600    debug    LBS19000501:    Sending command to EXEC daemon: POWER_ON    [v0.1]
                  2017-10-05 16:24:23    800662    2600    debug    LBS19000501:    Logic finished    [v0.1]
                  2017-10-05 16:24:34    822774    2701    debug    EXE19000501:    Received Command to be executed: STATUS    [v0.1]
                  2017-10-05 16:24:34    824671    2701    debug    EXE19000501:    Command: a:1:{i:0;s:6:"STATUS";}    [v0.1]
                  2017-10-05 16:24:34    825798    2701    debug    EXE19000501:    Value: [v0.1]
                  2017-10-05 16:24:34    826901    2701    debug    EXE19000501:    Updating Status    [v0.1]
                  2017-10-05 16:24:34    828056    2701    debug    EXE19000501:    Sending: ?11PR[CR]    [v0.1]
                  2017-10-05 16:24:34    829246    2701    debug    EXE19000501:    Sending: ?11CH[CR]    [v0.1]
                  2017-10-05 16:24:34    830389    2701    debug    EXE19000501:    Sending: ?11MU[CR]    [v0.1]
                  2017-10-05 16:24:34    832217    2701    debug    EXE19000501:    Sending: ?11VO[CR]    [v0.1]
                  2017-10-05 16:24:34    833585    2701    debug    EXE19000501:    Sending: ?11TR[CR]    [v0.1]
                  2017-10-05 16:24:34    834785    2701    debug    EXE19000501:    Sending: ?11BS[CR]    [v0.1]
                  2017-10-05 16:24:34    835881    2701    debug    EXE19000501:    Sending: ?11BL[CR]    [v0.1]
                  2017-10-05 16:24:35    094227    2701    debug    EXE19000501:    Received Command to be executed: POWER_ON    [v0.1]
                  2017-10-05 16:24:35    096628    2701    debug    EXE19000501:    Command: a:1:{i:0;s:8:"POWER_ON";}    [v0.1]
                  2017-10-05 16:24:35    098037    2701    debug    EXE19000501:    Value: [v0.1]
                  2017-10-05 16:24:35    099625    2701    debug    EXE19000501:    Sending: <11PR01[CR]    [v0.1]
                  2017-10-05 16:24:38    106292    2701    debug    EXE19000501:    Received Response: #?11PR[CR]    [v0.1]
                  2017-10-05 16:24:38    614331    2701    debug    EXE19000501:    Received Response: #>11PR00[CR]    [v0.1]
                  2017-10-05 16:24:38    615663    2701    debug    EXE19000501:    Object: 11 / Action: PR / Value: 00    [v0.1]
                  2017-10-05 16:24:39    371853    2701    debug    EXE19000501:    Received Response: #?11CH[CR]    [v0.1]
                  2017-10-05 16:24:39    878496    2701    debug    EXE19000501:    Received Response: #>11CH01[CR]    [v0.1]
                  2017-10-05 16:24:39    880664    2701    debug    EXE19000501:    Object: 11 / Action: CH / Value: 01    [v0.1]
                  2017-10-05 16:24:40    637608    2701    debug    EXE19000501:    Received Response: #?11MU[CR]    [v0.1]
                  2017-10-05 16:24:41    145590    2701    debug    EXE19000501:    Received Response: #>11MU00[CR]    [v0.1]
                  2017-10-05 16:24:41    146809    2701    debug    EXE19000501:    Object: 11 / Action: MU / Value: 00    [v0.1]
                  2017-10-05 16:24:41    903122    2701    debug    EXE19000501:    Received Response: #?11VO[CR]    [v0.1]
                  2017-10-05 16:24:42    410984    2701    debug    EXE19000501:    Received Response: #>11VO15[CR]    [v0.1]
                  2017-10-05 16:24:42    412300    2701    debug    EXE19000501:    Object: 11 / Action: VO / Value: 15    [v0.1]
                  2017-10-05 16:24:43    169799    2701    debug    EXE19000501:    Received Response: #?11TR[CR]    [v0.1]
                  2017-10-05 16:24:43    676893    2701    debug    EXE19000501:    Received Response: #>11TR07[CR]    [v0.1]
                  2017-10-05 16:24:43    679351    2701    debug    EXE19000501:    Object: 11 / Action: TR / Value: 07    [v0.1]
                  2017-10-05 16:24:44    437153    2701    debug    EXE19000501:    Received Response: #?11BS[CR]    [v0.1]
                  2017-10-05 16:24:44    944684    2701    debug    EXE19000501:    Received Response: #>11BS07[CR]    [v0.1]
                  2017-10-05 16:24:44    946223    2701    debug    EXE19000501:    Object: 11 / Action: BS / Value: 07    [v0.1]
                  2017-10-05 16:24:45    702327    2701    debug    EXE19000501:    Received Response: #?11BL[CR]    [v0.1]
                  2017-10-05 16:24:46    209794    2701    debug    EXE19000501:    Received Response: #>11BL10[CR]    [v0.1]
                  2017-10-05 16:24:46    211401    2701    debug    EXE19000501:    Object: 11 / Action: BL / Value: 10    [v0.1]
                  2017-10-05 16:24:46    967997    2701    debug    EXE19000501:    Received Response: #<11PR01[CR]    [v0.1]
                  jedoch hab ich dann auch Fehler im Fehlerlog, nämlich folgendes:
                  Code:
                  2017-10-05 16:24:38    106683    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlObjectCode    ERROR
                  2017-10-05 16:24:38    107156    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlActionCode    ERROR
                  2017-10-05 16:24:38    107566    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlValue    ERROR
                  2017-10-05 16:24:39    372265    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlObjectCode    ERROR
                  2017-10-05 16:24:39    372644    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlActionCode    ERROR
                  2017-10-05 16:24:39    373022    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlValue    ERROR
                  2017-10-05 16:24:40    638024    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlObjectCode    ERROR
                  2017-10-05 16:24:40    638406    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlActionCode    ERROR
                  2017-10-05 16:24:40    638761    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlValue    ERROR
                  2017-10-05 16:24:41    903558    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlObjectCode    ERROR
                  2017-10-05 16:24:41    903939    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlActionCode    ERROR
                  2017-10-05 16:24:41    904258    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlValue    ERROR
                  2017-10-05 16:24:43    170191    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlObjectCode    ERROR
                  2017-10-05 16:24:43    170594    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlActionCode    ERROR
                  2017-10-05 16:24:43    170918    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlValue    ERROR
                  2017-10-05 16:24:44    437530    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlObjectCode    ERROR
                  2017-10-05 16:24:44    437944    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlActionCode    ERROR
                  2017-10-05 16:24:44    438277    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlValue    ERROR
                  2017-10-05 16:24:45    702739    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlObjectCode    ERROR
                  2017-10-05 16:24:45    703166    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlActionCode    ERROR
                  2017-10-05 16:24:45    703496    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlValue    ERROR
                  2017-10-05 16:24:46    968390    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlObjectCode    ERROR
                  2017-10-05 16:24:46    968806    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlActionCode    ERROR
                  2017-10-05 16:24:46    969136    ?    2701    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 8 | Zeile: 204 | Undefined variable: controlValue    ERROR
                  Auf Ausgang A1 kommt immer noch Error, egal bei welchem Befehl.
                  Wenn ich den Befehl STATUS eingebe, scheint es auch zu funktionieren und den letzten empfangen Wert schreibt er auch auf Response A10. Also hier jetzt: 11|BL|10
                  Code:
                  2017-10-05 16:28:49    023788    2600    debug    LBS19000501:    Logic started    [v0.1]
                  2017-10-05 16:28:49    025434    2600    debug    LBS19000501:    Sending command to EXEC daemon: STATUS    [v0.1]
                  2017-10-05 16:28:49    026873    2600    debug    LBS19000501:    Logic finished    [v0.1]
                  2017-10-05 16:30:37    293694    2701    debug    EXE19000501:    Received Command to be executed: STATUS    [v0.1]
                  2017-10-05 16:30:37    295650    2701    debug    EXE19000501:    Command: a:1:{i:0;s:6:"STATUS";}    [v0.1]
                  2017-10-05 16:30:37    297264    2701    debug    EXE19000501:    Value: [v0.1]
                  2017-10-05 16:30:37    298854    2701    debug    EXE19000501:    Updating Status    [v0.1]
                  2017-10-05 16:30:37    300137    2701    debug    EXE19000501:    Sending: ?11PR[CR]    [v0.1]
                  2017-10-05 16:30:37    301759    2701    debug    EXE19000501:    Sending: ?11CH[CR]    [v0.1]
                  2017-10-05 16:30:37    303757    2701    debug    EXE19000501:    Sending: ?11MU[CR]    [v0.1]
                  2017-10-05 16:30:37    305881    2701    debug    EXE19000501:    Sending: ?11VO[CR]    [v0.1]
                  2017-10-05 16:30:37    307199    2701    debug    EXE19000501:    Sending: ?11TR[CR]    [v0.1]
                  2017-10-05 16:30:37    308829    2701    debug    EXE19000501:    Sending: ?11BS[CR]    [v0.1]
                  2017-10-05 16:30:37    310372    2701    debug    EXE19000501:    Sending: ?11BL[CR]    [v0.1]
                  2017-10-05 16:30:37    566907    2701    debug    EXE19000501:    Received Response: #?11PR[CR]    [v0.1]
                  2017-10-05 16:30:38    074453    2701    debug    EXE19000501:    Received Response: #>11PR00[CR]    [v0.1]
                  2017-10-05 16:30:38    075812    2701    debug    EXE19000501:    Object: 11 / Action: PR / Value: 00    [v0.1]
                  2017-10-05 16:30:38    832945    2701    debug    EXE19000501:    Received Response: #?11CH[CR]    [v0.1]
                  2017-10-05 16:30:39    340481    2701    debug    EXE19000501:    Received Response: #>11CH01[CR]    [v0.1]
                  2017-10-05 16:30:39    341892    2701    debug    EXE19000501:    Object: 11 / Action: CH / Value: 01    [v0.1]
                  2017-10-05 16:30:40    098632    2701    debug    EXE19000501:    Received Response: #?11MU[CR]    [v0.1]
                  2017-10-05 16:30:40    606553    2701    debug    EXE19000501:    Received Response: #>11MU00[CR]    [v0.1]
                  2017-10-05 16:30:40    608689    2701    debug    EXE19000501:    Object: 11 / Action: MU / Value: 00    [v0.1]
                  2017-10-05 16:30:41    366317    2701    debug    EXE19000501:    Received Response: #?11VO[CR]    [v0.1]
                  2017-10-05 16:30:41    874113    2701    debug    EXE19000501:    Received Response: #>11VO15[CR]    [v0.1]
                  2017-10-05 16:30:41    875556    2701    debug    EXE19000501:    Object: 11 / Action: VO / Value: 15    [v0.1]
                  2017-10-05 16:30:42    632061    2701    debug    EXE19000501:    Received Response: #?11TR[CR]    [v0.1]
                  2017-10-05 16:30:43    140360    2701    debug    EXE19000501:    Received Response: #>11TR07[CR]    [v0.1]
                  2017-10-05 16:30:43    141881    2701    debug    EXE19000501:    Object: 11 / Action: TR / Value: 07    [v0.1]
                  2017-10-05 16:30:43    899633    2701    debug    EXE19000501:    Received Response: #?11BS[CR]    [v0.1]
                  2017-10-05 16:30:44    407660    2701    debug    EXE19000501:    Received Response: #>11BS07[CR]    [v0.1]
                  2017-10-05 16:30:44    409172    2701    debug    EXE19000501:    Object: 11 / Action: BS / Value: 07    [v0.1]
                  2017-10-05 16:30:45    165496    2701    debug    EXE19000501:    Received Response: #?11BL[CR]    [v0.1]
                  2017-10-05 16:30:45    673162    2701    debug    EXE19000501:    Received Response: #>11BL10[CR]    [v0.1]
                  2017-10-05 16:30:45    674854    2701    debug    EXE19000501:    Object: 11 / Action: BL / Value: 10    [v0.1]
                  Gruß Ben

                  Kommentar


                    #54
                    Okay. Zwei kleine Anpassungen (s.u.)
                    Ziel: Fehler sollte weg sein. Jetzt sollte OK als Ergebnis erscheinen.

                    Das ganz am Anfang deiner E-Mail mit Einschalten etc.: Hier solltest Du für Tests den Receiver eingeschaltet haben, dann EDOMI Projekt aktivieren. Dann sollte es eigentlich funktionieren. Die hohe Load kann ich mir nicht erklären. Hier solltest du mal prüfen, ob du ggf. eine Schleife gebaut hast. Im LBS gibt es nur eine While Schleife und die hat am Ende ein usleep(250000). Damit sollte keine hohe Last entstehen.

                    PHP-Code:
                    ###[DEF]###
                    [name        = Monoprice 10761 RS-232C    (v0.1) ]

                    [e#1        = IP ]
                    [e#2        = Port ]
                    [e#3        = ZoneID ]
                    [e#4        = Command ]
                    [e#5        = Log level ]

                    [a#1        = Result ]
                    [a#2        = Error ]
                    [a#3        = Power ]
                    [a#4        = Input ]
                    [a#5        = Volume Mute ]
                    [a#6        = Volume ]
                    [a#7        = Treble ]
                    [a#8        = Bass ]
                    [a#9        = Balance ]
                    [a#10        = Response ]

                    [v#1        = 0 ]
                    [v#2        = 0 ]
                    [v#100        = 0.1 ]
                    [v#101        = 19000501 ]
                    [v#102        = Monoprice 10761 RS-232C ]
                    [v#103        = 0 ]

                    ###[/DEF]###


                    ###[HELP]###
                    This LBS controls an Monoprice 10761 connected via a Ethernet-to-RS-232C adapter (e.g. Moxa NPort 5110)  to your home network.

                    Simple Configutaion:
                    E1: IP address of your RS-232/Ethernet converter in TCP/IP Server mode (should work with ser2net as well)
                    E2: Port, which you have configured you TCP/IP Server on
                    E3: ZoneID, which Zone you want to control of your Monoprice 10761 (10-All Zone|11-Zone1|12-Zone2|13-Zone3|14-Zone4|15-Zone5|16-Zone6)
                    E4: The Command, which you want to send to your Monoprice 10761
                    E5: Enable Logging (0-none|1-emerg|2-alert|3-crit|4-err|5-warning|6-notice|7-info|8-debug)

                    Available commands:

                    COMMAND - raw command accoring to the RS-232C documentation of Monoprice ==> e.g. "11 PR 01" (11=ZoneID, PR=Power, 01=ON)
                    POWER (00|01)
                    POWER_ON
                    POWER_OFF
                    VOLUMEMUTE (00-Volume mute on|01-Volume mute off)
                    MUTE (same as VOLUMEMUTE)
                    VOLUMEMUTE_ON (=MUTE 00)
                    MUTE_ON (same as VOLUMEMUTE_ON)
                    VOLUMEMUTE_OFF (=MUTE 01)
                    MUTE_OFF (same as VOLUMEMUTE_OFF)
                    VOLUME (00-38)
                    VOLUMECONTROL (same as VOLUME)
                    TREBLE (00-14)
                    BASS  (00-14)
                    BALANCE  (00-20)
                    INPUTSELECT (01-Source 1|02-Source 2|03-Source 3|04-Source 4|05-Source 5|06-Source 6)
                    INPUT        (same as INPUTSELECT)

                    The outputs are updated automatically every 1/4 second. You can expect 1-3 seconds delay when sending an command, until the outputs are updated.
                    The outputs correspond to the commands above and should self explanatory. If the Monoprice is switched off, only the POWER output contains valid information.
                    Monoprice will not respond to other requests.

                    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                    Prerequesite before using this LBS
                    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

                    - Install php-process:

                    yum install php-process

                    Enjoy ...

                    Changelog:
                    ==========
                    v0.1: Initial version

                    ###[/HELP]###


                    ###[LBS]###
                    <?

                    function LB_LBSID_logging($id, $msg, $priority = 8)
                    {
                        $E = getLogicEingangDataAll($id);
                        $logLevel = getLogicElementVar($id, 103);
                        if (is_int($priority) && $priority <= $logLevel && $priority > 0) {
                            $logLevelNames = array(
                                'none',
                                'emerg',
                                'alert',
                                'crit',
                                'err',
                                'warning',
                                'notice',
                                'info',
                                'debug'
                            );
                            $version = getLogicElementVar($id, 100);
                            $lbsNo = getLogicElementVar($id, 101);
                            $logName = getLogicElementVar($id, 102) . '  ---  LBS' . $lbsNo;
                            strpos($_SERVER['SCRIPT_NAME'], $lbsNo) ? $scriptname = 'EXE' . $lbsNo : $scriptname = 'LBS' . $lbsNo;
                            writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . ":\t" . $msg . "\t[v$version]");
                        }
                    }

                    function LB_LBSID($id)
                    {
                        if ($E = getLogicEingangDataAll($id)) {
                            setLogicElementVar($id, 103, $E[5]['value']); // set loglevel to #VAR 103
                            LB_LBSID_logging($id, 'Logic started');
                            if (getLogicElementVar($id, 1) != 1) {
                                setLogicElementVar($id, 1, 1);
                                $uniqid = hexdec(uniqid());
                                setLogicElementVar($id, 2, $uniqid);
                                callLogicFunctionExec(LBSID, $id);
                            } else {
                                $uniqid = getLogicElementVar($id, 2);
                                $msg_queue = msg_get_queue($uniqid);
                                if ($E[4]['refresh'] == 1) {
                                    $cmd = $E[4]['value'];
                                    msg_send($msg_queue, 1, $cmd);
                                    LB_LBSID_logging($id, 'Sending command to EXEC daemon: ' . $cmd);
                                }
                            }
                            LB_LBSID_logging($id, 'Logic finished');
                        }
                    }
                    ?>
                    ###[/LBS]###


                    ###[EXEC]###
                    <?
                    require (dirname(__FILE__) . "/../../../../main/include/php/incl_lbsexec.php");
                    set_time_limit(0);
                    sql_connect();

                    function logging($id, $msg, $priority = 8)
                    {
                        $E = getLogicEingangDataAll($id);
                        $logLevel = getLogicElementVar($id, 103);
                        if (is_int($priority) && $priority <= $logLevel && $priority > 0) {
                            $logLevelNames = array(
                                'none',
                                'emerg',
                                'alert',
                                'crit',
                                'err',
                                'warning',
                                'notice',
                                'info',
                                'debug'
                            );
                            $version = getLogicElementVar($id, 100);
                            $lbsNo = getLogicElementVar($id, 101);
                            $logName = getLogicElementVar($id, 102) . '  ---  LBS' . $lbsNo;
                            strpos($_SERVER['SCRIPT_NAME'], $lbsNo) ? $scriptname = 'EXE' . $lbsNo : $scriptname = 'LBS' . $lbsNo;
                            writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . ":\t" . $msg . "\t[v$version]");
                        }
                    }

                    if ($E = getLogicEingangDataAll($id)) {
                        $ip = $E[1]['value'];
                        $port = $E[2]['value'];
                        $ZoneID = $E[3]['value'];

                        setLogicElementVar($id, 103, $E[5]['value']); // set loglevel to #VAR 103

                        logging($id, 'Daemon started');

                        $uniqid = getLogicElementVar($id, 2);
                        $msg_queue = msg_get_queue($uniqid);

                        $mono = new mono_moxa($ip, $port, $ZoneID);
                        $mono->connect();
                        $commandExecutionTime = 0;

                        while (getSysInfo(1)) {
                            if (msg_receive($msg_queue, 1, $msgtype, 4096, $msg, true, MSG_IPC_NOWAIT, $msg_error)) {
                                logging($id, 'Received Command to be executed: ' . $msg);
                                $command = explode(' ', $msg);
                                $result = $mono->command($command);
                                if (! $result) {
                                    setLogicLinkAusgang($id, 1, 'ERROR');
                                    setLogicLinkAusgang($id, 2, 1);
                                } else {
                                    setLogicLinkAusgang($id, 1, 'OK');
                                    setLogicLinkAusgang($id, 2, 0);
                                }
                            }

                           $mono->read();
                            usleep(250000);
                        }
                        logging($id, 'Daemon terminated');
                    }

                    $mono->disconnect();
                    msg_remove_queue($msg_queue);

                    sql_disconnect();

                    class mono_moxa
                    {

                        private $moxa_ip;

                        private $moxa_port;

                        private $moxa_connection;

                        private $ZoneID;

                        function mono_moxa($moxa_ip, $moxa_port, $ZoneID)
                        {
                            $this->moxa_ip = $moxa_ip;
                            $this->moxa_port = $moxa_port;
                            $this->ZoneID = $ZoneID;
                        }

                        function connect()
                        {
                            // Create socket
                            if ($this->moxa_connection = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) {
                                // Bind the source address
                                if (socket_bind($this->moxa_connection, global_serverIP)) {
                                    // Connect to destination address
                                    if (socket_connect($this->moxa_connection, $this->moxa_ip, $this->moxa_port)) {
                                        if (socket_set_nonblock($this->moxa_connection))
                                            return true;
                                    }
                                }
                            }
                            return false;
                        }

                        function disconnect()
                        {
                            if (isset($this->moxa_connection))
                                socket_close($this->moxa_connection);
                        }

                        function command($cmd)
                        {
                            global $id;
                            logging($id, 'Command: ' . serialize($cmd));
                            $command = strtoupper($cmd[0]);
                            array_shift($cmd);
                            $value = strtoupper(implode(' ', $cmd));
                            logging($id, 'Value: ' . $value);
                            switch ($command) {
                                case "STATUS":
                                    return $this->status();
                                    break;
                                case "COMMAND":
                                    return $this->sendCmd($value);
                                    break;
                                case "POWER":
                                    return $this->power($value);
                                    break;
                                case "POWER_ON":
                                    return $this->powerOn();
                                    break;
                                case "POWER_OFF":
                                    return $this->powerOff();
                                    break;
                                case "INPUTSELECT":
                                case "INPUT":
                                    return $this->inputSelect($value);
                                    break;
                                case "VOLUMEMUTE":
                                case "MUTE":
                                    return $this->mute($value);
                                    break;
                                case "VOLUMEMUTE_ON":
                                case "MUTE_ON":
                                    return $this->muteOn();
                                    break;
                                case "VOLUMEMUTE_OFF":
                                case "MUTE_OFF":
                                    return $this->muteOff();
                                    break;
                                case "VOLUME":
                                case "VOLUMECONTROL":
                                    return $this->volume($value);
                                    break;
                                case "TREBLE":
                                    return $this->treble($value);
                                    break;
                                case "BASS":
                                    return $this->bass($value);
                                    break;
                                case "BALANCE":
                                    return $this->balance($value);
                                    break;
                                default:
                                    return false;
                                    break;
                            }
                        }

                        function sendCmd($cmd)
                        {
                            global $id;
                            $cmd .= chr(0x0D);
                            if ($this->moxa_connection) {
                                logging($id,"Sending: ".$cmd);
                                $res = socket_write($this->moxa_connection, $cmd);
                                if ($res === FALSE) {
                                    $this->disconnect();
                                    $this->connect();
                                    $res = socket_write($this->moxa_connection, $cmd);
                                    if ($res !== FALSE)
                                        return true;
                                } else return TRUE;
                            }
                            return FALSE;
                        }


                        function read()
                        {
                            global $id;
                            if ($this->moxa_connection) {
                                $buf = socket_read($this->moxa_connection, 8192, PHP_NORMAL_READ);
                                if (strlen($buf) >= 6) {
                                    logging($id, 'Received Response: ' . $buf);
                                    $response = explode(' ', trim($buf));
                                    $response = preg_match('/.*>([0-9]{2})([A-Z]{2})([0-9]{2})/',$buf,$matches);
                                    if ($response) {
                                        $controlObjectCode = $matches[1];
                                        $controlActionCode = $matches[2];
                                        $controlValue = $matches[3];
                                        logging($id, "Object: $controlObjectCode / Action: $controlActionCode / Value: $controlValue");
                                        logic_setOutput($id, 10, $controlObjectCode.'|'.$controlActionCode.'|'.$controlValue);
                                    }
                                    return $response;
                                } else
                                    return FALSE;
                            }
                            return FALSE;
                        }

                        function power($status)
                        {
                            if ($status == "ON" || $status == "01")
                                return $this->powerOn();
                            else if ($status == "OFF" || $status == "00")
                                return $this->powerOff();
                        }

                        function powerOn()
                        {
                            $cmd = "<" . $this->ZoneID . "PR01";
                            $result = $this->sendCmd($cmd);
                            sleep(3);
                            return $result;
                        }

                        function powerOff()
                        {
                            $cmd = "<" . $this->ZoneID . "PR00";
                            return $this->sendCmd($cmd);
                        }

                        function inputSelect($input)
                        {
                            $cmd = "<" . $this->ZoneID . "CH" . $input;
                            return $this->sendCmd($cmd);
                        }

                        function mute($mute)
                        {
                            $cmd = "<" . $this->ZoneID . "MU" . $mute;
                            return $this->sendCmd($cmd);
                        }

                        function muteOn()
                        {
                            $cmd = "<" . $this->ZoneID . "MU00";
                            return $this->sendCmd($cmd);
                        }

                        function muteOff()
                        {
                            $cmd = "<" . $this->ZoneID . "MU01";
                            return $this->sendCmd($cmd);
                        }

                        function volume($vol) // 0-38
                        {
                            $cmd = "<" . $this->ZoneID . "VO" . $vol;
                            return $this->sendCmd($cmd);
                        }

                        function treble($treble) // 0-14
                        {
                            $cmd = "<" . $this->ZoneID . "TR" . $treble;
                            return $this->sendCmd($cmd);
                        }

                        function bass($bass) // 0-14
                        {
                            $cmd = "<" . $this->ZoneID . "BS" . $bass;
                            return $this->sendCmd($cmd);
                        }

                        function balance($balance) // 0-20
                        {
                            $cmd = "<" . $this->ZoneID . "BL" . $balance;
                            return $this->sendCmd($cmd);
                        }

                        function status()
                        {
                            global $id;
                            logging($id, 'Updating Status');
                            $this->sendCmd("?" . $this->ZoneID . "PR");
                            $this->sendCmd("?" . $this->ZoneID . "CH");
                            $this->sendCmd("?" . $this->ZoneID . "MU");
                            $this->sendCmd("?" . $this->ZoneID . "VO");
                            $this->sendCmd("?" . $this->ZoneID . "TR");
                            $this->sendCmd("?" . $this->ZoneID . "BS");
                            $this->sendCmd("?" . $this->ZoneID . "BL");

                        }
                    }

                    ?>
                    ###[/EXEC]###

                    Kommentar


                      #55
                      Hab jetzt mal alles mögliche durchprobiert.
                      Zu aller erst, Schleife kann ich keine gebaut haben, da ich an dem Baustein nur die Ausgänge mit Ausgangsboxen belegt hab. Hab noch keine KO's dran. Teste alles im Logikeditor im Livemodus.
                      Ich konnte aber nachstellen, dass das Problem tatsächlich in der while-Schleife liegt und zwar in dem Satz :$mono->read();
                      Wenn ich diesen testweiße rauslösche bin ich wieder bei unter 20% CPU Auslastung. Warum das so ist hab ich allerdings nicht rausgefunden.

                      Befehle hab ich durchprobiert. Kommt überall ein an A1 ein "OK" und A2 eine "0". Ausgenommen wenn ich STATUS eingebe, da kommt an A1" ERROR" und A2 "1".
                      Wenn ich den oben genannten Satz rauswerfe kommt bei A10 Response auch nichts mehr an.
                      Wenn ich den Satz drin lasse, geht es nur wenn ich den Monoprice oder den Moxa neustarte nach eingeben des Befehls "STATUS". Dann kommt bei Response der letzte empfange Wert an. Bzw. laufen alle Rückmeldungen durch und der letzte bleibt halt drin stehen.
                      Gruß Ben

                      Kommentar


                        #56
                        Ändere doch mal die zwei Zeilen in der read() Funktion wie folgt:

                        PHP-Code:
                        $result socket_recv($this->moxa_connection$buf8192MSG_DONTWAIT);
                        if (
                        $result >= 6) { 
                        Außerdem bitte immer das Log der Tests hochladen, ansonsten ist es schwierig die Ursache für deine Fehlerbeschreibung zu finden.

                        Kommentar


                          #57
                          Nur zum Sicherstellen dass ichs richtig gemacht hab. lch hab die Read Funktion folgendermaßen abgeändert:
                          PHP-Code:
                              function read()
                              {
                                  global 
                          $id;
                                  if (
                          $this->moxa_connection) {
                                      
                          $result socket_recv($this->moxa_connection$buf8192MSG_DONTWAIT);
                                      if (
                          $result >= 6) {
                                          
                          logging($id'Received Response: ' $buf);
                                          
                          $response explode(' 'trim($buf));
                                          
                          $response preg_match('/.*>([0-9]{2})([A-Z]{2})([0-9]{2})/',$buf,$matches);
                                          if (
                          $response) {
                                              
                          $controlObjectCode $matches[1];
                                              
                          $controlActionCode $matches[2];
                                              
                          $controlValue $matches[3];
                                              
                          logging($id"Object: $controlObjectCode / Action: $controlActionCode / Value: $controlValue");
                                              
                          logic_setOutput($id10$controlObjectCode.'|'.$controlActionCode.'|'.$controlValue);
                                          }
                                          return 
                          $response;
                                      } else
                                          return 
                          FALSE;
                                  }
                                  return 
                          FALSE;
                              } 
                          CPU-Auslastung ist jetzt wieder gut und Befehle ausführen funktioniert auch.
                          Wie gehabt alle Befehle außer STATUS bringen ein OK zurück.
                          Bei Eingabe von STATUS kommt bei Response folgendes raus: 11|CH|01

                          Hier das Log dazu:
                          Code:
                          2017-10-06 13:42:45    143192    22945    debug    LBS19000501:    Logic started    [v0.1]
                          2017-10-06 13:42:45    162982    22945    debug    LBS19000501:    Logic finished    [v0.1]
                          2017-10-06 13:42:45    258014    23040    debug    EXE19000501:    Daemon started    [v0.1]
                          2017-10-06 13:49:03    239032    22945    debug    LBS19000501:    Logic started    [v0.1]
                          2017-10-06 13:49:03    242717    22945    debug    LBS19000501:    Sending command to EXEC daemon: POWER_ON    [v0.1]
                          2017-10-06 13:49:03    244486    22945    debug    LBS19000501:    Logic finished    [v0.1]
                          2017-10-06 13:49:03    425604    23040    debug    EXE19000501:    Received Command to be executed: POWER_ON    [v0.1]
                          2017-10-06 13:49:03    427645    23040    debug    EXE19000501:    Command: a:1:{i:0;s:8:"POWER_ON";}    [v0.1]
                          2017-10-06 13:49:03    429311    23040    debug    EXE19000501:    Value: [v0.1]
                          2017-10-06 13:49:03    430630    23040    debug    EXE19000501:    Sending: <11PR01[CR]    [v0.1]
                          2017-10-06 13:49:06    437571    23040    debug    EXE19000501:    Received Response: <11PR01[CR][LF]#    [v0.1]
                          2017-10-06 13:49:19    698647    22945    debug    LBS19000501:    Logic started    [v0.1]
                          2017-10-06 13:49:19    701730    22945    debug    LBS19000501:    Sending command to EXEC daemon: STATUS    [v0.1]
                          2017-10-06 13:49:19    704399    22945    debug    LBS19000501:    Logic finished    [v0.1]
                          2017-10-06 13:49:19    765692    23040    debug    EXE19000501:    Received Command to be executed: STATUS    [v0.1]
                          2017-10-06 13:49:19    766813    23040    debug    EXE19000501:    Command: a:1:{i:0;s:6:"STATUS";}    [v0.1]
                          2017-10-06 13:49:19    768752    23040    debug    EXE19000501:    Value: [v0.1]
                          2017-10-06 13:49:19    770018    23040    debug    EXE19000501:    Updating Status    [v0.1]
                          2017-10-06 13:49:19    771341    23040    debug    EXE19000501:    Sending: ?11PR[CR]    [v0.1]
                          2017-10-06 13:49:19    773123    23040    debug    EXE19000501:    Sending: ?11CH[CR]    [v0.1]
                          2017-10-06 13:49:19    774650    23040    debug    EXE19000501:    Sending: ?11MU[CR]    [v0.1]
                          2017-10-06 13:49:19    776585    23040    debug    EXE19000501:    Sending: ?11VO[CR]    [v0.1]
                          2017-10-06 13:49:19    778827    23040    debug    EXE19000501:    Sending: ?11TR[CR]    [v0.1]
                          2017-10-06 13:49:19    780452    23040    debug    EXE19000501:    Sending: ?11BS[CR]    [v0.1]
                          2017-10-06 13:49:19    782146    23040    debug    EXE19000501:    Sending: ?11BL[CR]    [v0.1]
                          2017-10-06 13:49:19    787224    23040    debug    EXE19000501:    Received Response: ?11PR[CR][LF]#>    [v0.1]
                          2017-10-06 13:49:20    041459    23040    debug    EXE19000501:    Received Response: 11PR01[CR][CR][LF]#?11CH[CR][LF]#>11CH01[CR][CR][LF]#?11MU[CR][LF]#>11MU00[CR][CR][LF]#?11VO[CR][LF]#>11VO15[CR][CR][LF]#?11TR[CR][LF]#>11TR07[CR][CR][LF]#?11BS[CR][LF]#>11BS07[CR][CR][LF]#?11BL[CR][LF]#>11BL10[CR][CR][LF]#    [v0.1]
                          2017-10-06 13:49:20    043124    23040    debug    EXE19000501:    Object: 11 / Action: CH / Value: 01    [v0.1]
                          Also bei Response laufen nicht mehr alle Werte durch, sondern es wird nur der 2te ausgegeben? Außerdem schreibt er im Log wieder alles nach der ersten Abfrage hintereinander in eine Reihe. Keine Ahnung ob das gut oder schlecht ist.

                          Der Fehlerlog läuft mir jetzt leider auch wieder mit folgendem voll (über 7000 Einträge nach paar Minuten):
                          Code:
                          2017-10-06 13:42:45    264004    ?    23040    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 2 | Zeile: 193 | socket_recv(): unable to read from socket [11]: Resource temporarily unavailable    ERROR
                          2017-10-06 13:42:45    515639    ?    23040    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 2 | Zeile: 193 | socket_recv(): unable to read from socket [11]: Resource temporarily unavailable    ERROR
                          2017-10-06 13:42:45    766822    ?    23040    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 2 | Zeile: 193 | socket_recv(): unable to read from socket [11]: Resource temporarily unavailable    ERROR
                          2017-10-06 13:42:46    017810    ?    23040    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 2 | Zeile: 193 | socket_recv(): unable to read from socket [11]: Resource temporarily unavailable    ERROR
                          2017-10-06 13:42:46    268810    ?    23040    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 2 | Zeile: 193 | socket_recv(): unable to read from socket [11]: Resource temporarily unavailable    ERROR
                          2017-10-06 13:42:46    519860    ?    23040    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 2 | Zeile: 193 | socket_recv(): unable to read from socket [11]: Resource temporarily unavailable    ERROR
                          2017-10-06 13:42:46    770889    ?    23040    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 2 | Zeile: 193 | socket_recv(): unable to read from socket [11]: Resource temporarily unavailable    ERROR
                          2017-10-06 13:42:47    021933    ?    23040    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 2 | Zeile: 193 | socket_recv(): unable to read from socket [11]: Resource temporarily unavailable    ERROR
                          2017-10-06 13:42:47    272973    ?    23040    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 2 | Zeile: 193 | socket_recv(): unable to read from socket [11]: Resource temporarily unavailable    ERROR
                          2017-10-06 13:42:47    523973    ?    23040    Datei: /usr/local/edomi/www/data/liveproject/lbs/EXE19000501.php | Fehlercode: 2 | Zeile: 193 | socket_recv(): unable to read from socket [11]: Resource temporarily unavailable    ERROR
                          Das du das Log brauchst ist mir schon klar aber leider stand da vorher nicht wirklich was drin. Vieleicht hing es mit der CPU-Auslastung zusammen, keine Ahnung. Aber das ausführen von Befehlen ging nur so wie oben in #53 beschrieben mit An/Ausschalten von Moxa oder Monoprice.

                          Danke übrigens für deinen Aufwand den du hier betreibst.
                          Gruß Ben

                          Kommentar


                            #58
                            Mir gehn allerdings so langsam die Ideen aus.

                            Kommentar


                              #59
                              Kann man wohl nichts machen.
                              Trotzdem Danke für deine Mühe
                              Gruß Ben

                              Kommentar


                                #60
                                stonie2oo4 : sobald ich mich näher mit edomi beschäftige, evtl. über Jahreswechsel werde ich mir die Thematik auch mal noch anschauen.
                                Geniale Menschen sind selten ordentlich, ordentliche selten genial. (Albert Einstein)

                                Kommentar

                                Lädt...
                                X