Das freut mich zu hören

###[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]###
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
$status = $monoprice->get_status();
while (getSysInfo(1)) {
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 (isset($command))
sleep(1);
else
usleep($intervall * 1000);
}
$responses = explode("\x0A",$buf);
foreach ($responses as $response)
{
logging($id, 'RECEIVED: ' . $response);
$cmd = substr($response,4,2);
switch ($cmd)
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