Skip to content

Instantly share code, notes, and snippets.

@thelink2012
Created March 21, 2016 20:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thelink2012/f660ec1e46308e5913e7 to your computer and use it in GitHub Desktop.
Save thelink2012/f660ec1e46308e5913e7 to your computer and use it in GitHub Desktop.
<?php
function daikin($host, $port, $address)
{
$buffer = pack('VVVVCCCCCCCCCCCCCCCC',
32, // Command Length
700004, // Command ID
0, 0, // Reserved 1 & 2
$address[0], $address[1], $address[2], $address[3],
$address[4], $address[5], $address[6], $address[7],
$address[8], $address[9], $address[10], $address[11],
$address[12], $address[13], $address[14], $address[15]);
$f = fopen('php://memory','w+b');
fwrite($f, $buffer);
rewind($f);
$req = curl_init();
$uport = $port? ":$port" : "";
curl_setopt($req, CURLOPT_URL, "$host$uport/cmd/");
curl_setopt($req, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($req, CURLOPT_POST, 1);
curl_setopt($req, CURLOPT_HTTPHEADER, array('Content-Type: application/octet-stream',
'Content-Length: 32'));
curl_setopt($req, CURLOPT_UPLOAD, 1);
curl_setopt($req, CURLOPT_INFILE, $f);
curl_setopt($req, CURLOPT_INFILESIZE, strlen($buffer));
$chunk = curl_exec($req);
$resp = "";
if($chunk == FALSE)
{
$resp = curl_error($req);
}
else
{
$resp = unpack("VCommandSize/VCommandID/VNumAC/x20/VACAddress/vStatus/x2/vOnOff/vOpMode/x8/VSetTemp/VRoomTemp/CFanSpeed", $chunk);
}
curl_close($req);
fclose($f);
return ["raw" => $chunk, "response" => $resp];
}
array_shift($argv); //shift out file
$host = array_shift($argv);
$port = array_shift($argv);
$address01 = array_shift($argv);
$address02 = array_shift($argv);
$address03 = array_shift($argv);
$address04 = array_shift($argv);
$address05 = array_shift($argv);
$address06 = array_shift($argv);
$address07 = array_shift($argv);
$address08 = array_shift($argv);
$address09 = array_shift($argv);
$address10 = array_shift($argv);
$address11 = array_shift($argv);
$address12 = array_shift($argv);
$address13 = array_shift($argv);
$address14 = array_shift($argv);
$address15 = array_shift($argv);
$address16 = array_shift($argv);
$result = daikin($host, $port, [$address01, $address02, $address03, $address04, $address05, $address06,
$address07, $address08, $address09, $address10, $address11, $address12,
$address13, $address14, $address15, $address16]);
if($result['raw'] == FALSE)
{
echo "problem with request: {$result['response']}\n";
}
else
{
$resp = $result['response'];
echo "CommandSize : {$resp['CommandSize']}\n";
echo "CommandID : {$resp['CommandID']}\n";
echo "Number Of AC : {$resp['NumAC']}\n";
echo "AC Address : {$resp['ACAddress']}\n";
echo "Status : {$resp['Status']}\n";
echo "Operation Mode : {$resp['OpMode']}\n";
echo "On/Off : {$resp['OnOff']}\n";
echo "Set Temp : {$resp['SetTemp']}\n";
echo "Room Temp : {$resp['RoomTemp']}\n";
echo "Fan Speed : {$resp['FanSpeed']}\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment