Ankündigung

Einklappen
Keine Ankündigung bisher.

Anfrage für LBS

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

    #61
    Das freut mich zu hören
    Gruß Ben

    Kommentar


      #62
      hallo.. gibt es schon eine Möglichkeit den Monoprice anzusteuern?

      Kommentar


        #63
        Nein, noch nix neues.
        Gruß Ben

        Kommentar


          #64
          Aber das Senden von befehlen funktioniert mit dem LBS doch oder?

          Kannst du mir sagen, ob beim Monoprice eine Telnet-Verbindung gehalten werden muss? Oder funktionieren einfache IP-Telegramme? (UDP/TCP?)

          Danke Thomas

          Kommentar


            #65
            Ja Senden geht.
            Da er an einem RS232->Ethernet Adapter hängt, der im TCP-Server Mode läuft, vermute ich mal stark das es einfache IP-Telegramme sind.
            Wollte mir das ganze die Tage eigentlich mal wieder anschauen, bin aber leider noch nicht dazu gekommen.
            Gruß Ben

            Kommentar


              #66
              löschen

              Kommentar


                #67
                Zitat von stonie2oo4 Beitrag anzeigen
                Ja Senden geht.
                Da er an einem RS232->Ethernet Adapter hängt, der im TCP-Server Mode läuft, vermute ich mal stark das es einfache IP-Telegramme sind.
                Danke!

                Zitat von stonie2oo4 Beitrag anzeigen
                Wollte mir das ganze die Tage eigentlich mal wieder anschauen, bin aber leider noch nicht dazu gekommen.
                Top

                Kommentar


                  #68
                  So, bin mal wieder dazu gekommen ein bisschen zu experimentieren.
                  LBS läuft jetzt und Problem mit der CPU-Aulastung hab ich auch gelöst. Hab jetzt den ganzen LBS umgeschrieben. Als Vorlage dienten mir dieses mal der Onkyo jonofe und Pioneer lennartc LBS. Danke den Entwicklern dafür .

                  Rückmeldungen funktionieren auch (fast).

                  Jetzt hab ich eigentlich nur noch 1 Problem. Bei den Originalen LBS gibt es einen Eingang bei dem man den Polling-Intervall definieren kann.
                  Also sollte doch nach meinem Verständnis nach der definierten Zeit immer der Status aller Ausgänge abgefragt werden?
                  Momentan ist es aber so dass der Status nur beim ersten Start einmalig abgefragt wird und dann nicht mehr.

                  Da mein Wissen was Programmieren an geht leider stark begrenzt ist, könnte vielleicht bitte jemand der sich auskennt mal kurz drüber schauen ob er den Fehler findet. Bei mir ist es immer so ein rumprobieren, testen und schauen ob ich Glück hatte und es geht .

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

                  [e#1        = Start/Stop #init=1]
                  [e#2        = IP ]
                  [e#3        = Port #init=4001 ]
                  [e#4        = ZoneID ]
                  [e#5        = Command ]
                  [e#6        = Polling intervall #init=250]
                  [e#7        = Log Level #init=0]

                  [a#1        = Result ]
                  [a#2        = Power ]
                  [a#3        = Volume ]
                  [a#4        = Source ]
                  [a#5        = Volume Mute ]
                  [a#6        = Treble ]
                  [a#7        = Bass ]
                  [a#8        = Balance ]


                  [v#1        = 0 ]
                  [v#2        = 0 ]

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

                  ###[/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.
                  A command can be sent to input E4. In general all command are supported. Refer to the Monoprice documentation, 
                  which commands are valid for your Monoprice 10761. (https://downloads.monoprice.com/files/manuals/10761_Manual_141028.pdf)
                  The daemon part of the LBS regularly reads the changes indicated by the Monoprice. This includes even changes, which are
                  made by your normal IR remote. Therefore the outputs
                  should be always consistent to the real status. With the polling intervall you can specify how fast the LBS
                  recognizes changes, what happened to the device.    

                  Simple Configutaion:
                  E1: Start(1)/Stop(0)
                  E2: IP address of your RS-232/Ethernet converter in TCP/IP Server mode (should work with ser2net as well)
                  E3: Port, which you have configured you TCP/IP Server on
                  E4: 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)
                  E5: The Command, which you want to send to your Monoprice 10761
                  E6: Polling intervall - Specifies how often the LBS will poll for changes.
                  E7: Enable Logging (0-none|1-emerg|2-alert|3-crit|4-err|5-warning|6-notice|7-info|8-debug)

                  A1: Result of the Command (OK|ERROR)
                  A2: Power - Current power status (ON|STANDBY)
                  A3: Volume - Current Volume value (0-38)
                  A4: Source - Currently selected input source
                  A5: Mute - Indicates whether mute is on or off (ON|OFF)
                  A6: Treble - Current Treble value (0-14)
                  A7: Bass - Current Bass value (0-14)
                  A8: Balance - Current Balance value (0-20)

                  V1: Ensures the daemon is only started once
                  V2: Containes the message queue id, which is used to transfern commands from LBS to EXEC part
                  V100: Version of LBS
                  V101: LBS Number
                  V102: Name of Custom Log
                  V103: used to store Loglevel
                  V104: One log file per LBS instance
                  V105: log ID in each log entry

                  Prerequistes needed:
                  ==================== 
                  You need to install php-process module before you can use this LBS, because it uses a message queue.
                  To install php-process you have to login as root to your edomi server and execute

                      yum install php-process

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


                  ###[/HELP]###


                  ###[LBS]###
                  <?

                  function LB_LBSID_logging($id, $msg, $var = NULL, $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";
                          $logName = preg_replace('/ /', '_', $logName);
                          if (logic_getVar($id, 104))
                              $logName .= "-$id";
                              if (logic_getVar($id, 105) == 1)
                                  $msg .= " ($id)";
                                  strpos($_SERVER['SCRIPT_NAME'], $lbsNo) ? $scriptname = 'EXE' . $lbsNo : $scriptname = 'LBS' . $lbsNo;
                                  writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t" . $msg);
                                  if (isset($var)) {
                                      writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t================ ARRAY/OBJECT START ================");
                                      writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t" . json_encode($var));
                                      writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t================ ARRAY/OBJECT  END  ================");
                                  }
                      }
                  }

                  function LB_LBSID($id) {
                      if ($E=getLogicEingangDataAll($id)) {
                          setLogicElementVar($id,103,$E[7]['value']); //set loglevel to #VAR 103

                          LB_LBSID_logging($id,'LBS started');

                          if ($E[1]['value']!=0 && $E[1]['refresh']==1) {

                              if (getLogicElementVar($id,1)!=1) {    //dieses Konstrukt stellt sicher, dass das EXEC-Script nur einmal gestartet wird
                                  setLogicElementVar($id,1,1);
                                  $msg_queue_id = hexdec(uniqid());
                                  setLogicElementVar($id,2,$msg_queue_id);
                                  callLogicFunctionExec(LBSID,$id);
                              }
                          } else if ($E[1]['value']==0 && $E[1]['refresh']==1) {
                              if (getLogicElementVar($id,1)!=0) {    //dieses Konstrukt stellt sicher, dass das EXEC-Script gestoppt wird, wenn es läuft
                                  setLogicElementVar($id,1,0);
                                  $msg_queue_id = getLogicElementVar($id,2);
                                  $msg_queue = msg_get_queue ( $msg_queue_id );
                                  LB_LBSID_logging ($id,"Create Message Queue with ID: ".dechex($msg_queue_id));
                                  msg_send($msg_queue,1,"STOP",true);
                              }
                          } else if ($E[5]['refresh']==1) 
                          {
                              if (getLogicElementVar($id,1)==1) {
                                  $cmd = $E[5]['value'];
                                  LB_LBSID_logging($id,'Command sent to daemon: '.$cmd);
                                  $msg_queue_id = getLogicElementVar($id,2);
                                  $msg_queue = msg_get_queue ( $msg_queue_id );
                                  msg_send($msg_queue,1,$cmd,true);
                              }
                          }
                          LB_LBSID_logging($id,'LBS finished');
                      }
                  }
                  ?>
                  ###[/LBS]###


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


                  function logging($id, $msg, $var = NULL, $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";
                          $logName = preg_replace('/ /', '_', $logName);
                          if (logic_getVar($id, 104))
                              $logName .= "-$id";
                              if (logic_getVar($id, 105) == 1)
                                  $msg .= " ($id)";
                                  strpos($_SERVER['SCRIPT_NAME'], $lbsNo) ? $scriptname = 'EXE' . $lbsNo : $scriptname = 'LBS' . $lbsNo;
                                  writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t" . $msg);
                                  if (isset($var)) {
                                      writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t================ ARRAY/OBJECT START ================");
                                      writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t" . json_encode($var));
                                      writeToCustomLog($logName, str_pad($logLevelNames[$logLevel], 7), $scriptname . " [v$version]:\t================ ARRAY/OBJECT  END  ================");
                                  }
                      }
                  }


                  $E=getLogicEingangDataAll($id);
                  if ($E) {
                      logging($id,'Monoprice 10761 Daemon started');
                      $intervall = $E[6]['value'];
                      if (!is_numeric($intervall) || $intervall<100) $intervall=100;
                      $ip = $E[2]['value'];
                      $port = $E[3]['value'];
                      $ZoneID = $E[4]['value'];

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

                      $monoprice = new monoprice($ip, $port, $ZoneID);    
                      $status = $monoprice->get_status();

                      while (getSysInfo(1)) { // Hauptschleife (wird beim Beenden oder Neustart von EDOMI verlassen)
                          unset($command);
                          $result = msg_receive($msg_queue, 1, $msgtype, 4096, $command, true, MSG_IPC_NOWAIT, $msg_error);
                          if ($command) {
                              logging($id, 'Command to be executed: ', $command);
                              $monoprice->sendCmd($command);
                          }
                          $monoprice->read();
                          if (substr($command, 4, 4) == 'PR01')
                              sleep(1);
                  //        else 
                  //            if (substr($command, 4, 2) == 'CH')
                  //                sleep(2);
                              else 
                                  if (isset($command))
                                      sleep(1);
                                  else
                                      usleep($intervall * 1000); // CPU-Last verteilen (die Länge der Pause sollte je nach Bedarf angepasst werden - je länger, desto ressourcenschonender)
                      }
                      logging($id, 'Monoprice 10761 Daemon stopped');
                  }

                  msg_remove_queue($msg_queue);
                  sql_disconnect();

                  class monoprice
                  {
                      private $monoprice_ip;
                      private $monoprice_port;
                      private $monoprice_connection;        
                      private $ZoneID;            
                      private $power;
                      private $volume;    
                      private $source;
                      private $mute;
                      private $treble;    
                      private $bass;    
                      private $balance;       

                      function __construct($ip, $port, $ZoneID)
                      {
                          $this->monoprice_ip = $ip;
                          $this->monoprice_port = $port;   
                          $this->ZoneID = $ZoneID;    
                          $this->connect();
                      }

                      function __destruct()
                      {
                          socket_close($this->monoprice_connection);
                      }

                      function connect()
                      {
                          $i=0;
                          // Create socket connection to Monoprice 10761
                          do {
                              $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
                              if ($sock)
                              {
                                  // Bind the source address
                                  $bind = socket_bind($sock, global_serverIP);
                                  if ($bind)
                                  {
                                      $connect = socket_connect($sock, $this->monoprice_ip, $this->monoprice_port);
                                      if (!$connect) sleep(1);
                                  }
                              }
                              $i++;
                          } while (!$connect && $i<3);
                          if ($connect)
                          {
                              $this->monoprice_connection = $sock;
                              socket_set_nonblock($this->monoprice_connection);
                              socket_set_option($this->monoprice_connection,SOL_SOCKET,SO_KEEPALIVE,1);
                              return TRUE;
                          }
                          $this->monoprice_connection=FALSE;
                          return FALSE;
                      }

                      function sendCmd($cmd)
                      {
                          global $id, $debug;
                          if ($this->monoprice_connection) {
                              logging($id, 'SENDING: ' . $cmd);
                              if (socket_write($this->monoprice_connection, "\x0A".$cmd."\x0D"))
                                  setLogicLinkAusgang($id, 1, 'OK');
                              else
                                  setLogicLinkAusgang($id, 1, 'ERROR');
                          }
                      }

                      function read()
                      {   
                          global $id;
                          if ($this->monoprice_connection)
                          {
                              $e = socket_get_option($this->monoprice_connection,SOL_SOCKET,SO_ERROR);
                              if ($e != 0) $this->connect();
                              $buf = socket_read($this->monoprice_connection,2048);
                              if ($buf!='')
                              {
                                  $responses = explode("\x0A",$buf);
                                  foreach ($responses as $response)
                                  {
                                      logging($id, 'RECEIVED: ' . $response);
                                      $cmd = substr($response,4,2);
                                      switch ($cmd)
                                      {
                                          case 'PR':
                                              $power = substr($response,6,2);
                                              switch ($power) {
                                                  case '00':
                                                      $power = 'OFF';
                                                      break;                                
                                                  case '01':
                                                      $power = 'ON';
                                                      break; 
                                                  default:
                                                      $power = $power;
                                                      break;   
                                              }
                                              setLogicLinkAusgang($id,2,$power);
                                              break;                             
                                          case 'VO':
                                              $volume = substr($response,6,2);
                                              if (is_numeric($volume)) setLogicLinkAusgang($id,3,(int)$volume);
                                              break;
                                          case 'CH':
                                              $source = substr($response,6,2);
                                              switch ($source) {
                                                  case '01':
                                                      $source = 'Source01';
                                                      break;
                                                  case '02':
                                                      $source = 'Source02';
                                                      break;
                                                  case '03':
                                                      $source = 'Source03';
                                                      break;
                                                  case '04':
                                                      $source = 'Source04';
                                                      break;
                                                  case '05':
                                                      $source = 'Source05';
                                                      break;
                                                  case '06':
                                                      $source = 'Source06';
                                                      break;
                                                  default:
                                                      $source = $source;
                                                      break;
                                              }
                                              setLogicLinkAusgang($id,4,$source);
                                              break;
                                          case 'MU':
                                              $mute = substr($response,6,2);
                                              switch ($mute) {
                                                  case '00':
                                                      $mute = 'OFF';
                                                      break;                                
                                                  case '01':
                                                      $mute = 'ON';
                                                      break; 
                                                  default:
                                                      $mute = $mute;
                                                      break;   
                                              }
                                              setLogicLinkAusgang($id,5,$mute);
                                              break;                                     
                                          case 'TR':
                                              $treble = substr($response,6,2);
                                              if (is_numeric($treble)) setLogicLinkAusgang($id,6,(int)$treble);
                                              break;
                                          case 'BS':
                                              $bass = substr($response,6,2);
                                              if (is_numeric($bass)) setLogicLinkAusgang($id,7,(int)$bass);
                                              break;
                                          case 'BL':
                                              $balance = substr($response,6,2);
                                              if (is_numeric($balance)) setLogicLinkAusgang($id,8,(int)$balance);
                                              break;                                                       
                                      }
                                  }
                              }
                          } else $this->connect();
                      }

                      // requests all relevant data for the LBS outputs 
                      function get_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]###

                  ​​​​​​​
                  Hier das Log vom Starten und 1mal An und Aus schalten
                  Code:
                  Zeitstempel    ms    PID    LogLevel    Meldung
                  2018-02-27 22:55:21    177392    11820    debug    LBS19000501 [v0.1]:    LBS started (3491)
                  2018-02-27 22:55:21    179902    11820    debug    LBS19000501 [v0.1]:    LBS finished (3491)
                  2018-02-27 22:55:21    203895    11826    debug    EXE19000501 [v0.1]:    Monoprice 10761 Daemon started (3491)
                  2018-02-27 22:55:21    206522    11826    debug    EXE19000501 [v0.1]:    SENDING: ?13PR (3491)
                  2018-02-27 22:55:21    207247    11826    debug    EXE19000501 [v0.1]:    SENDING: ?13CH (3491)
                  2018-02-27 22:55:21    207590    11826    debug    EXE19000501 [v0.1]:    SENDING: ?13MU (3491)
                  2018-02-27 22:55:21    207946    11826    debug    EXE19000501 [v0.1]:    SENDING: ?13VO (3491)
                  2018-02-27 22:55:21    208245    11826    debug    EXE19000501 [v0.1]:    SENDING: ?13TR (3491)
                  2018-02-27 22:55:21    208540    11826    debug    EXE19000501 [v0.1]:    SENDING: ?13BS (3491)
                  2018-02-27 22:55:21    208822    11826    debug    EXE19000501 [v0.1]:    SENDING: ?13BL (3491)
                  2018-02-27 22:55:22    212790    11826    debug    EXE19000501 [v0.1]:    RECEIVED: ?13PR[CR] (3491)
                  2018-02-27 22:55:22    215578    11826    debug    EXE19000501 [v0.1]:    RECEIVED: #>13PR00[CR][CR] (3491)
                  2018-02-27 22:55:22    219661    11826    debug    EXE19000501 [v0.1]:    RECEIVED: #?13CH[CR] (3491)
                  2018-02-27 22:55:22    222645    11826    debug    EXE19000501 [v0.1]:    RECEIVED: #>13CH01[CR][CR] (3491)
                  2018-02-27 22:55:22    225658    11826    debug    EXE19000501 [v0.1]:    RECEIVED: #?13MU[CR] (3491)
                  2018-02-27 22:55:22    228292    11826    debug    EXE19000501 [v0.1]:    RECEIVED: #>13MU00[CR][CR] (3491)
                  2018-02-27 22:55:22    230772    11826    debug    EXE19000501 [v0.1]:    RECEIVED: #?13VO[CR] (3491)
                  2018-02-27 22:55:22    231724    11826    debug    EXE19000501 [v0.1]:    RECEIVED: #>13VO15[CR][CR] (3491)
                  2018-02-27 22:55:22    233439    11826    debug    EXE19000501 [v0.1]:    RECEIVED: #?13TR[CR] (3491)
                  2018-02-27 22:55:22    234684    11826    debug    EXE19000501 [v0.1]:    RECEIVED: #>13TR07[CR][CR] (3491)
                  2018-02-27 22:55:22    236471    11826    debug    EXE19000501 [v0.1]:    RECEIVED: #?13BS[CR] (3491)
                  2018-02-27 22:55:22    237411    11826    debug    EXE19000501 [v0.1]:    RECEIVED: #>13BS07[CR][CR] (3491)
                  2018-02-27 22:55:22    239063    11826    debug    EXE19000501 [v0.1]:    RECEIVED: #?13BL[CR] (3491)
                  2018-02-27 22:55:22    240009    11826    debug    EXE19000501 [v0.1]:    RECEIVED: #>13BL10[CR][CR] (3491)
                  2018-02-27 22:55:22    241774    11826    debug    EXE19000501 [v0.1]:    RECEIVED: # (3491)
                  2018-02-27 22:57:14    500538    11820    debug    LBS19000501 [v0.1]:    LBS started (3491)
                  2018-02-27 22:57:14    500880    11820    debug    LBS19000501 [v0.1]:    Command sent to daemon: <13PR01 (3491)
                  2018-02-27 22:57:14    501101    11820    debug    LBS19000501 [v0.1]:    LBS finished (3491)
                  2018-02-27 22:57:15    323570    11826    debug    EXE19000501 [v0.1]:    Command to be executed: (3491)
                  2018-02-27 22:57:15    323786    11826    debug    EXE19000501 [v0.1]:    ================ ARRAY/OBJECT START ================
                  2018-02-27 22:57:15    323906    11826    debug    EXE19000501 [v0.1]:    "<13PR01"
                  2018-02-27 22:57:15    323990    11826    debug    EXE19000501 [v0.1]:    ================ ARRAY/OBJECT END ================
                  2018-02-27 22:57:15    324841    11826    debug    EXE19000501 [v0.1]:    SENDING: <13PR01 (3491)
                  2018-02-27 22:57:16    327615    11826    debug    EXE19000501 [v0.1]:    RECEIVED: <13PR01[CR] (3491)
                  2018-02-27 22:57:16    328557    11826    debug    EXE19000501 [v0.1]:    RECEIVED: # (3491)
                  2018-02-27 22:57:27    862363    11820    debug    LBS19000501 [v0.1]:    LBS started (3491)
                  2018-02-27 22:57:27    863648    11820    debug    LBS19000501 [v0.1]:    Command sent to daemon: <13PR00 (3491)
                  2018-02-27 22:57:27    864789    11820    debug    LBS19000501 [v0.1]:    LBS finished (3491)
                  2018-02-27 22:57:28    337450    11826    debug    EXE19000501 [v0.1]:    Command to be executed: (3491)
                  2018-02-27 22:57:28    337647    11826    debug    EXE19000501 [v0.1]:    ================ ARRAY/OBJECT START ================
                  2018-02-27 22:57:28    337801    11826    debug    EXE19000501 [v0.1]:    "<13PR00"
                  2018-02-27 22:57:28    337888    11826    debug    EXE19000501 [v0.1]:    ================ ARRAY/OBJECT END ================
                  2018-02-27 22:57:28    338757    11826    debug    EXE19000501 [v0.1]:    SENDING: <13PR00 (3491)
                  2018-02-27 22:57:29    341142    11826    debug    EXE19000501 [v0.1]:    RECEIVED: <13PR00[CR] (3491)
                  2018-02-27 22:57:29    342403    11826    debug    EXE19000501 [v0.1]:    RECEIVED: # (3491
                  monoprice.JPG
                  Gruß Ben

                  Kommentar


                    #69
                    Hey,
                    ich bin zwar auch nicht so der PHP-Programmierer und hatte meinen Baustein ja auch größtenteils von jonofe kopiert, aber der Baustein fragt eigentlich nur zu anfangs einmal den tatsächlichen Status aller Ausgänge ab. Anschließend schaut er alle $pollingInvervall ms, ob neue Befehle zum senden in der MessageQueue sind und verarbeitet anschließend auch sämtliche Rückgaben, die in der Zeit vom Receiver kamen.

                    Entscheidend ist hier die while-Schleife, sowie der letzte Befehl davor:
                    PHP-Code:
                    $status $monoprice->get_status();
                    while (
                    getSysInfo(1)) {
                        unset(
                    $command);
                        
                    $result msg_receive($msg_queue1$msgtype4096$commandtrueMSG_IPC_NOWAIT$msg_error);
                        if (
                    $command) {
                            
                    logging($id'Command to be executed: '$command);
                            
                    $monoprice->sendCmd($command);
                        }
                        
                    $monoprice->read();
                        if (
                    substr($command44) == 'PR01')
                            
                    sleep(1);
                        else 
                            if (isset(
                    $command))
                                
                    sleep(1);
                            else
                                
                    usleep($intervall 1000);


                    get_status() fragt initial einmal sämtliche Ausgänge ab.

                    In der Schleife wird dann zunächst der alte Befehl gelöscht (unset($command);) und anschließend ein Befehl aus der MessageQueue geholt. Ist dort ein Befehl vorhanden, wird dieser gesendet (if ($command) {...}). Danach wird der Input vom telnet-stream gelesen und verarbeitet ($monoprice->read()). Wenn die MessageQueue nicht leer war, so wird nur 1-2ms gewartet (je nachdem, ob zuletzt ein CH command kam, oder nicht) und die Schleife startet von vorne, um zu schauen, ob weitere Befehle in der Queue stehen. Falls alle abgearbeitet wurden und $command leer ist, so wird die in $intervall gesetzte Zeit gewartet.

                    Bei meinem Pioneer war es so, dass wenn man eine Telnet-Verbindung zu ihm aufgemacht hatte, er einem Änderungen aktiv mitgeteilt hat - also eine Nachricht an den Baustein gesendet hat, sodass diese dann in read() verarbeitet werden konnte und somit sich die Ausgänge des Bausteins auch geupdatet haben.
                    Sollte der Monoprice das nicht so machen, so müsstest du die get_status() Abfrage ebenfalls mit in die Schleife holen. Dies führt allerdings dazu, dass du deinen Receiver dann nach jedem Intervall mit diesen Anfragen "bombardierst".

                    Viele Grüße,
                    Lennart

                    Kommentar


                      #70
                      Zitat von lennartc Beitrag anzeigen
                      aber der Baustein fragt eigentlich nur zu anfangs einmal den tatsächlichen Status aller Ausgänge ab. Anschließend schaut er alle $pollingInvervall ms, ob neue Befehle zum senden in der MessageQueue sind und verarbeitet anschließend auch sämtliche Rückgaben, die in der Zeit vom Receiver kamen.
                      Okay das macht ja auch Sinn so. Dann hab ich das mit dem Polling-Intervall einfach falsch verstanden.
                      Dann ist das Problem ein anderes
                      Beim ersten Start funktioniert die Abfrage ja und wenn ich einen Befehl absetzte nicht. Das liegt an folgendem, ich weiß bloß nicht wie mans löst.
                      Wenn man den Status abfragt kommt das zurück:
                      RECEIVED: #>13PR00[CR][CR] (3491)

                      Wenn man einen Befehl setzt das hier:
                      RECEIVED: <13PR01[CR] (3491)

                      Man beachte oben die Raute.


                      Ich such ja im LBS hiermit das PR, also die Stelle wo es steht:
                      PHP-Code:
                                      $responses explode("\x0A",$buf);
                                      foreach (
                      $responses as $response)
                                      {
                                          
                      logging($id'RECEIVED: ' $response);
                                          
                      $cmd substr($response,4,2);
                                          switch (
                      $cmd
                      Und wenn die Raute davor kommt verschiebt sich halt die Stelle um 1.
                      Beim Schreiben hat ich aber grad ne Idee, ich kann ja die Stelle des „PR“ auch von rechts nach links suchen, muss ich heut Abend mal testen. Weiß nur nicht ob ich da dass gleiche Problem hab, weil einmal kommt ja das [CR] doppelt vor. Mhh…
                      Gruß Ben

                      Kommentar


                        #71
                        Oder mit Regex...
                        sowas in der Richtung halt:
                        Code:
                        if (preg_match('/PR(..)/im', $response, $regs)) {
                            $cmd = $regs[0];
                        } else {
                            $cmd = "";
                        }
                        Zuletzt geändert von vento66; 01.03.2018, 22:45.

                        Kommentar


                          #72
                          Habe sehr gute Nachrichten.
                          Der LBS läuft und scheint so zu funktionieren wie ich mir das vorstelle (Ausgenommen eine Gleinigkeit).
                          Hier nochmal einen herzlichen Dank an alle die mir bis hierhin geholfen haben.

                          Sobald ich für den Download-Bereich freigeschalten bin, werde ich ihn natürlich zu Verfügung stellen.


                          Also die Ausgänge werden jetzt beim Starten des LBS abgefragt und werden auch bei Änderungen aktualisiert.
                          Falsche Eingaben beim Command-Eingang werden nicht abgefangen.
                          Beispiel an Power an:
                          <11PR01
                          setzt den Ausgang auf 01 (An)

                          aber:
                          11PR01
                          setzt den Ausgang auch auf 01 (An), aber der Befehl wird vom Monoprice nicht ausgeführt.
                          Kommt einfach daher das ich jetzt die Zeichen von rechts nach links suche, siehe #70, Problem mit der vorangehenden Raute. Aber ich glaube damit kann man leben, da man die Befehle ja eh nicht jedesmal von Hand eingibt, sondern in der Visu oder im LBS hinterlegt. Da merkt man recht schnell falls man mal den Befehl falsch hinterlegt hat

                          vento66 Danke Micha für deinen Tip, aber meine Kentnisse sind leider so schlecht das ich damit nicht viel anfangen konnte. Also was es macht ist mir ungefähr klar, aber nicht wie ich es richtig eingebaut bekommen hätte
                          Gruß Ben

                          Kommentar


                            #73
                            Anstatt der Zeile
                            Code:
                            $cmd = substr($response,4,2);
                            P.S Freigeschaltet bist Du schon...
                            Zuletzt geändert von vento66; 01.03.2018, 22:46.

                            Kommentar


                              #74
                              Ah okay danke, werd ich mal aus reiner Neugierde testen.
                              P.S Freigeschaltet bist Du schon...
                              Hab ich auch grad gesehen, aber jetzt lieg ich schon im Sessel.
                              Muss dann wohl bis morgen Abend warten. Nachdem es so lange gedauert hat, kommts auf den einen Tag auch nicht mehr an
                              Gruß Ben

                              Kommentar


                                #75
                                Hi stonie2oo4
                                Glückwunsch zu deinem ersten lbs! !!

                                Wie sieht es mit der Reaktionsgeschwindigkeit bei deinem monoprice lbs aus ?
                                Also z. B Power on off??
                                .
                                Jean-Luc Picard: "Things are only impossible until they are not."

                                Kommentar

                                Lädt...
                                X