debugging api and add notify command
This commit is contained in:
@@ -34,28 +34,46 @@ function askWebServer($read)
|
||||
$argTmp = explode("&", $input[0]);
|
||||
foreach($argTmp as $tmp)
|
||||
{
|
||||
logger(DEBUG, $tmp, __FILE__ . ":" . __LINE__);
|
||||
$array = explode("=", $tmp);
|
||||
//logger(DEBUG, $tmp, __FILE__ . ":" . __LINE__);
|
||||
$argList[strchr($tmp, "=", true)] = substr(strchr($tmp, "="), 1);
|
||||
//logger(DEBUG, $argList[0] . " ==========> " . $argList[1]);
|
||||
//print_r($array);
|
||||
if (isset($array[1])) $argList[$array[0]] = $array[1];
|
||||
//if (isset($array[1])) $argList[$array[0]] = $array[1];
|
||||
}
|
||||
logger(DEBUG, print_r($argList, true));
|
||||
if(array_key_exists("cmd", $argList))
|
||||
{
|
||||
$command = strtolower($argList["cmd"]);
|
||||
logger(DEBUG, _("command is ") . $command);
|
||||
switch($command)
|
||||
{
|
||||
case "get":
|
||||
logger(DEBUG, _("GET reached"), __FILE__ . ":" . __LINE__);
|
||||
if(empty($argList["device"]))
|
||||
if(!array_key_exists("topic", $argList) or !array_key_exists("fn", $argList) or !array_key_exists("property", $argList))
|
||||
{
|
||||
$response = "<html><header><body>get passed</body></header><html>";
|
||||
$response = "<html><header></header><body>GET: " . _("no parameters passed, need topic, fn and property") . "</body></html>";
|
||||
}else
|
||||
{
|
||||
$device = getDevice($argList["topic"], $argList["fn"]);
|
||||
$property = $argList["property"];
|
||||
$response = "<html><header></header><body>GET: " . bool2string($device->$property["value"]) . "</body></html>";
|
||||
}
|
||||
fwrite($spawn, $response);
|
||||
break;
|
||||
case "set":
|
||||
logger(DEBUG, _("SET reached"), __FILE__ . ":" . __LINE__);
|
||||
$response = "<html><header><body>set passed</body></header><html>";
|
||||
fwrite($spawn, $response);
|
||||
if(!array_key_exists("topic", $argList) or !array_key_exists("fn", $argList) or !array_key_exists("property", $argList) or !array_key_exists("value", $argList))
|
||||
{
|
||||
$response = "<html><header></header><body>SET: " . _("no parameters passed, need topic, fn, property and value") . "passed</body></html>";
|
||||
fwrite($spawn, $response);
|
||||
}else
|
||||
{
|
||||
$response = "<html><header></header><body>setting property " . $argList["property"] . " of " . $argList["fn"] . " to value: " . $argList["value"] . "</body></html>";
|
||||
fwrite($spawn, $response);
|
||||
$payload = array($argList["property"] => $argList["value"]);
|
||||
publish(Z2M . "/" . $argList["fn"], $payload);
|
||||
}
|
||||
|
||||
break;
|
||||
case "dump":
|
||||
case "print":
|
||||
@@ -86,7 +104,7 @@ function askWebServer($read)
|
||||
$error = error_get_last();
|
||||
if($error !== null)
|
||||
{
|
||||
$response = "<html><header><body>" . $error["message"] . " file: " . $error["file"] . " line: " . $error["line"] . "</body></header><html>";
|
||||
$response = "<html><header></header><body>" . $error["message"] . " file: " . $error["file"] . " line: " . $error["line"] . "</body></html>";
|
||||
}
|
||||
if ($command === "print")
|
||||
{
|
||||
@@ -99,17 +117,23 @@ function askWebServer($read)
|
||||
fwrite($spawn, $response);
|
||||
break;
|
||||
case "notify":
|
||||
logger(DEBUG, $command . _(" reached"), __FILE__ . ":" . __LINE__);
|
||||
if (!array_key_exists("topic", $argList) or !array_key_exists("fn", $argList) or !array_key_exists("property", $argList) or !array_key_exists("condition", $argList) or !array_key_exists("value", $argList))
|
||||
{
|
||||
fwrite($spawn, _("Error: With 'notify' command, you need 4 parameters: topic, fn, property, condition, value"));
|
||||
$response = "<html><header></header><body>" . _("Error: With 'notify' command, you need 4 parameters: topic, fn, property, condition, value") . "</body></html>";
|
||||
fwrite($spawn, $response);
|
||||
}else
|
||||
{
|
||||
$response = "<html><header></header><body>" . _("notify command have been set") . "</body></html>";
|
||||
$monitored[] = new watch($argList["topic"], $argList["fn"], $argList["property"], $argList["condition"], $argList["value"]);
|
||||
fwrite($spawn, $response);
|
||||
}
|
||||
logger(DEBUG, print_r($monitored, true));
|
||||
break;
|
||||
default:
|
||||
logger(DEBUG, _("unknown command"), __FILE__ . ":" . __LINE__);
|
||||
fwrite($spawn, _("unknown command"));
|
||||
$response = "<html><header></header><body>" . _("unknown command") . "</body></html>";
|
||||
fwrite($spawn, $response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user