Kurze Frage: wie kann ich ein "HTTP POST" Befehl absetzen mit dem AIO Creator Neo 2?
Falls es für jemanden nützlich sein könnte, hier ist mein PHP-Skript um Denkovi-Relais, FS20, Minix u.v.m. zu steuern:
$logFile ="D:\haus\log\denkvovi_relais_extensive.txt";
file_put_contents ($logFile, "command executed on ". date("Y-m-d H:i:s")." "."\r\n", FILE_APPEND);
//establish defaults (for testing) in case they are not passed from an upstream script
if(!isset($snmpPort)) {$snmpPort=':161';}
if(!isset($denkoviIp)) {$denkoviIp='10.10.11.103';}
if(!isset($snmpCommunity)) {$snmpCommunity ='write';}
if(!isset($relayNr)) {$relayNr = 3;}
if(!isset($RelayState)) {$RelayState = 1;} // 0=Off ; 1=On
if(!isset($pulseDuration)) {$pulseDuration = 0;}
if(!isset($FS20)) {$FS20='dimmer';}
if(!isset($FS20location)) {$FS20location = 'ceiling';}
if(!isset($FS20RelayState)) {$FS20RelayState = 8;}
if(!isset($MinixIp)) {$MinixIp = '10.10.10.70';}
//check if parameters were passed from a calling page
if (isset($_POST['relayNr'])) {$relayNr = $_POST['relayNr'];}
if (isset($_POST['RelayState'])) {$RelayState = $_POST['RelayState'];}
if (isset($_POST['pulseDuration'])) {$pulseDuration = $_POST['pulseDuration'];}
if (isset($_POST['port'])) {$snmpPort = $_POST['port']; }
if (isset($_POST['pass'])) {$snmpCommunity = $_POST['pass'];}
if (isset($_POST['denkoviIp'])) {$denkoviIp=$_POST['denkoviIp'];}
if (isset($_POST['FS20'])) {$FS20 = $_POST['FS20'];}
if (isset($_POST['location'])) {$FS20location = $_POST['location'];}
if (isset($_POST['RelayState'])) {$FS20RelayState = (int)$_POST['RelayState'];}
//execute denkovi action if denkovi IP was set, then terminate script
if (isset($_POST['denkoviIp']))
{executeDenkoviRelais ($denkoviIp,$relayNr,$RelayState,$pulseDuration,$snmpPort,$snmpCommunity);retur
n;}
//execute FS20 action if FS20 was set, then terminate script
if (isset($_POST['FS20']))
{executeFS20action ($FS20, $FS20location, $FS20RelayState); return;}
//execute FS20 action if FS20 was set, then terminate script
if (isset($_POST['MinixCommand']))
{executeMinixAction ($MinixIp, $MinixCommand); return;}
#----------------------
function executeDenkoviRelais($denkoviIp,$relayNr,$RelayState,$pulseDuration,$snmpPort,$
snmpCommunity)
{
//log actions
$logEntry = print_r($_POST, $return = true).
' snmpPort: '. $snmpPort. chr(13).
' denkoviIp: '. $denkoviIp.chr(13).
' snmpCommunity: '. $snmpCommunity.chr(13).
' relayNr: '. $relayNr.chr(13).
' RelayState: '. $RelayState. chr(13);
if ($_POST != null) logObject($logEntry);
//SNMP OIDs of the five relays
$relays = array(1 => ".1.3.6.1.4.1.42505.1.2.3.1.11.8",
2 => ".1.3.6.1.4.1.42505.1.2.3.1.11.9",
3 => ".1.3.6.1.4.1.42505.1.2.3.1.11.10",
4 => ".1.3.6.1.4.1.42505.1.2.3.1.11.11",
5 => ".1.3.6.1.4.1.42505.1.2.3.1.11.12",
);
//switch relays according to the parameters passed
for ($index = 1; $index <= 5; $index++)
{$currentState = snmpset ($denkoviIp.$snmpPort, $snmpCommunity, $relays[$relayNr], "i", $RelayState);
sleep(.10);}
echo "denkovi ".$denkoviIp.$snmpPort. " - relais #". $relayNr. ": ". snmpget($denkoviIp.$snmpPort, $snmpCommunity, $relays[$relayNr]);
}
#--------------------------------------
function logObject($logVariable)
{global $logFile;
file_put_contents ($logFile, date("Y-m-d H:i:s")." "."\r\n" . $logVariable."\r\n \r\n", FILE_APPEND);
}
#--------------------------------------
function executeFS20action ($FS20, $FS20location, $FS20RelayState)
{
$logEntry = print_r($_POST, $return = true).$FS20. " ". $FS20location." ". $FS20RelayState;
logObject($logEntry);
//if ($_POST != null) logObject($logEntry);
echo "FS20 action: ".$FS20." ". $FS20location." ". $FS20RelayState;
FS20_SetIntensity(23616, $FS20RelayState,0);
/*
sleep (1);
FS20_SetIntensity(23616, $FS20RelayState,0);
sleep(1);
FS20_SetIntensity(23616, $FS20RelayState,0);
*/}
#--------------------------------------
function executeMinixAction ($MinixIp, $MinixCommand)
{
$logEntry = print_r($_POST, $return = true).$MinixIp. " ". $MinixCommand." ";
logObject($logEntry);
//if ($_POST != null) logObject($logEntry);
echo "Minix action: ".$MinixIp. " ". $MinixCommand." ";
If ($MinixCommand == "shutdown")
{
$output = file_get_contents('http://minix_control.lan/minix_shutdown.php');
echo $output;
}
/*
sleep (1);
FS20_SetIntensity(23616, $FS20RelayState,0);
sleep(1);
FS20_SetIntensity(23616, $FS20RelayState,0);
*/}
?>
Neuen Kommentar hinzufügen