Ankündigung

Einklappen
Keine Ankündigung bisher.

Anfrage für LBS

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

    #16
    Okay, hab mir den LBS nochmal genauer angeschaut, könnte ich villeicht hinbekommen .
    Hab jetzt alles mal soweit angepasst, bringt aber immer Syntax-Fehler beim importieren.
    Find ich iwie heraus im welchen Satz der Fehler liegt?

    Meine Vermutung ist ja folgendes, zumindest is das die einzige Zeile die ich geändert hab.
    $cmd = "CH ".$this->setID." ".$input;
    geändert in
    $cmd = "".$this->setID." CH ".$input;
    Ist das so richtig? Oder müssen die Gänsefüßchen wo anderst hin?

    Grund: Ich will die setID missbrauchen für die einzelnen Zonen. Bloß muss laut Datenblatt des Monoprice diese eben vor dem Control Objekt stehen.
    Also grad andersherum wie beim LG TV.
    Also z.B.: 11 CH 01

    11 = Zone (variabel)
    CH = Input
    01 = Quelle 1
    Gruß Ben

    Kommentar


      #17
      $cmd = "".$this->setID." CH ".$Input;
      Für was brauchst du denn die Anführungszeichen und den Punkt am Anfang noch, wenn dort nichts steht?

      Ohne den Baustein zu kennen würde ich vermuten es müsste so richtig sein:
      $cmd = $this->setID." CH ".$Input;
      Zuletzt geändert von magiczambo; 20.07.2016, 10:35.
      Geniale Menschen sind selten ordentlich, ordentliche selten genial. (Albert Einstein)

      Kommentar


        #18
        eigentlich ist das Statement syntaktisch korrekt. Allerdings kannst du das erste "". auch weglassen.
        Ich vermute eher ein Problem bei der Kodierung oder so. bust du sicher, dass du das File UTF8 kodiert abgespeichert hast?
        Hast du den Namen des LBS und die Nummer geändert? Evtl. hast du ansonsten zwei Bausteine mit demselben Namen. ggf mag EDOMI das nicht.

        Kommentar


          #19
          Zitat von jonofe Beitrag anzeigen
          Allerdings kannst du das erste "". auch weglassen.
          Habs jetzt weg gelassen, aber hattest Recht, daran liegt es nicht.

          Zitat von jonofe Beitrag anzeigen
          bust du sicher, dass du das File UTF8 kodiert abgespeichert hast?
          Ja bin ich, benutz Ultraedit. hab ja deinen Baustein abgeändert. Wenn ich deinen erneut speichere funktionierts auch.

          Zitat von jonofe Beitrag anzeigen
          Hast du den Namen des LBS und die Nummer geändert?
          Ja hab ich, zum Test in 19000501_lbs.php
          Dann muss ich wohl mal weiter Suchen, wo ich den Fehler eingebaut hab, mhh....
          Gruß Ben

          Kommentar


            #20
            Probier mal in der Console ein "php -l /pfad/zum/lbs.php"

            Kommentar


              #21
              dann kommt:
              Errors parsing /usr/local/edomi/www/admin/lbs/19000501_lbs.php

              Gruß Ben

              Kommentar


                #22
                q.e.e.
                Und sonst nix? Da steht nicht welche errors?

                Kommentar


                  #23
                  Nein leider nicht. Hab auch nochmal drüber geschaut, mir fällt nix auf.
                  Iwie ist das so die Nadel im Heuhaufen
                  Gruß Ben

                  Kommentar


                    #24
                    Hier ist das gute Stück. Vielleicht fällt euch ja was auf



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

                    [e#1        = IP ]
                    [e#2        = Port ]
                    [e#3        = setID ]
                    [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: setID, 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=setID, 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'];
                        $setID = $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 );
                        
                        $lg = new lg_moxa($ip,$port,$setID);
                        $lg->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 = $lg->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;  
                              $lg->status();
                            }
                            usleep(100000);
                            logging($id,'END');
                        }
                        logging($id,'Daemon terminated');
                    }

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

                    sql_disconnect();


                    class lg_moxa
                    {
                        private $moxa_ip;
                        private $moxa_port;
                        private $moxa_connection;
                        private $setID;

                        function lg_moxa($moxa_ip, $moxa_port ,$setID)
                        {
                            $this->moxa_ip = $moxa_ip;
                            $this->moxa_port = $moxa_port;
                            $this->setID = $setID;

                        }

                        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,2);
                                            if ($status == "NG") return FALSE;
                                            else if ($status == "OK")
                                            {
                                                $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->setID." PR 01";
                            $result = $this->sendCmd($cmd);
                            sleep(3);
                            return $result;
                        }

                        function powerOff()
                        {
                            $cmd = $this->setID." PR 00";
                            return $this->sendCmd($cmd);
                        }

                        function inputSelect($input)
                        {
                            $cmd = $this->setID." CH ".$input;
                            return $this->sendCmd($cmd);
                        }
                        
                        function mute($mute)
                        {
                            $cmd = $this->setID." MU ".$mute;
                            return $this->sendCmd($cmd);
                        }

                        function muteOn()
                        {
                            $cmd = $this->setID." MU 00";
                            return $this->sendCmd($cmd);
                        }

                        function muteOff()
                        {
                            $cmd = $this->setID." MU 01";
                            return $this->sendCmd($cmd);
                        }

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

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

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

                        function balance($balance) // 0-20
                        {
                            $cmd = $this->setID." 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->setID." PR ff");
                            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->setID." CH ff");
                                if ($inputSelect !== $lastInputSelect)
                                {
                                    setLogicLinkAusgang($id,4,$inputSelect);
                                    $lastInputSelect = $inputSelect;
                                }
                                
                                $volumeMute = (int) $this->sendCmd($this->setID." MU ff");
                                if ($volumeMute !== $lastVolumeMute)
                                {
                                    setLogicLinkAusgang($id,5,$volumeMute);
                                    $lastVolumeMute = $volumeMute;
                                }
                                    
                                $volumeControl = (int) $this->sendCmd($this->setID." VO ff");
                                if ($volumeControl !== $lastVolumeControl)
                                {
                                    setLogicLinkAusgang($id,6,$volumeControl);
                                    $lastVolumeControl = $volumeControl;
                                }

                                $treble = (int) $this->sendCmd($this->setID." TR ff");
                                if ($treble !== $lastTreble)
                                {
                                     setLogicLinkAusgang($id,7,$treble);
                                     $lastTreble = $treble;
                                }
                                
                                $bass = (int) $this->sendCmd($this->setID." BS ff");
                                if ($bass !== $lastBass)
                                {
                                     setLogicLinkAusgang($id,8,$bass);
                                     $lastBass = $bass;
                                }
                                
                                $balance = (int) $this->sendCmd($this->setID." BL ff");
                                if ($balance !== $lastBalance)
                                {
                                     setLogicLinkAusgang($id,9,$balance);
                                     $lastBalance = $balance;
                                }
                            }
                            return TRUE;
                        }
                        
                    }

                    ?>
                    ###[/EXEC]###
                    Gruß Ben

                    Kommentar


                      #25
                      Hmja, ich habe scheinbar wohl mal mein php umkonfiguriert...
                      Aender in der /etc/php.ini mal "display_errors" von "off" auf "on" und probier nochmal.

                      Kommentar


                        #26
                        aha, schon besser
                        Danke dir

                        Parse error: syntax error, unexpected T_INT_CAST in /usr/local/edomi/www/admin/lbs/19000501_lbs.php on line 434

                        Gruß Ben

                        Kommentar


                          #27
                          Ist zum Entwickeln irgendwie praktischer so

                          Kommentar


                            #28
                            Ja ist praktischer
                            Ähm, hehe was bedeutet denn der Fehler jetzt?
                            Gruß Ben

                            Kommentar


                              #29
                              Die Zeile 434 ist die hier:

                              PHP-Code:
                              $power = (int) $this->sendCmd($this->setID." PR ff"); 
                              Zumindest wenn ich mir den Code rauskopiere. Hier schlägt ein sog. Typecast auf. Also die Umwandlung in ein Integer.
                              Zuletzt geändert von magiczambo; 20.07.2016, 12:17.
                              Geniale Menschen sind selten ordentlich, ordentliche selten genial. (Albert Einstein)

                              Kommentar


                                #30
                                Da steht "hier kommt ein (int) Typecast mit dem ich nicht gerechnet hatte". PHP hat das einfach nicht erwartet, weil die Zeile davor nicht "abgeschlossen" ist, 434 ist (zumindest) syntaktisch ok.

                                Kommentar

                                Lädt...
                                X