Oje, das hab ich schon befürchtet, ich glaub das übersteigt mein Wissen

?###[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]###
###[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]###
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
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]
###[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]###
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]
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]
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
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]
###[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]###
$result = socket_recv($this->moxa_connection, $buf, 8192, MSG_DONTWAIT);
if ($result >= 6) {
function read()
{
global $id;
if ($this->moxa_connection) {
$result = socket_recv($this->moxa_connection, $buf, 8192, MSG_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($id, 10, $controlObjectCode.'|'.$controlActionCode.'|'.$controlValue);
}
return $response;
} else
return FALSE;
}
return FALSE;
}
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]
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
Wir verarbeiten personenbezogene Daten über die Nutzer unserer Website mithilfe von Cookies und anderen Technologien, um unsere Dienste bereitzustellen. Weitere Informationen findest Du in unserer Datenschutzerklärung.
Indem Du unten auf "ICH stimme zu" klickst, stimmst Du unserer Datenschutzerklärung und unseren persönlichen Datenverarbeitungs- und Cookie-Praktiken zu, wie darin beschrieben. Du erkennst außerdem an, dass dieses Forum möglicherweise außerhalb Deines Landes gehostet wird und bist damit einverstanden, dass Deine Daten in dem Land, in dem dieses Forum gehostet wird, gesammelt, gespeichert und verarbeitet werden.
Kommentar