Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Commit

Permalink
testing post
Browse files Browse the repository at this point in the history
  • Loading branch information
ael-code committed Jun 10, 2014
1 parent 1e92f4a commit c7ae4a0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
38 changes: 21 additions & 17 deletions web_gui/api.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
<?php
require "engine.php";
require "config.php";

require "engine.php";
require "config.php";

if($_SERVER["REQUEST_METHOD"] == "POST"){
$aRequest = json_decode(file_get_contents('php://input'), true);
$json_ret = set_array_info("/aircon/set_control_info",$ip,$aRequest);
//request failed
if($json_ret===FALSE){
http_response_code(503); //service Unavailable
exit;
}
print($json_ret);

}else if($_SERVER["REQUEST_METHOD"] == "GET"){
//control if uri is sended
if(! isset($_GET["uri"])){
if( (! isset($_GET["uri"])) || $_GET["uri"] != "/aircon/get_sensor_info" || $_GET["uri"] != "/aircon/get_control_info"){
http_response_code(405); //method not allowed
exit;
}


if($_GET["uri"] == "/aircon/set_control_info"){
echo $_SERVER["QUERY_STRING"];
}else if($_GET["uri"] == "/aircon/get_sensor_info" || $_GET["uri"] == "/aircon/get_control_info"){
$json_info=get_json_info($_GET["uri"],$ip);
//request failed
if($json_info===FALSE){
http_response_code(503); //service Unavailable
exit;
}
print(get_json_info($_GET["uri"],$ip));
}else{
http_response_code(405); //method not allowed
$json_info=get_json_info($_GET["uri"],$ip);
//request failed
if($json_info===FALSE){
http_response_code(503); //service Unavailable
exit;
}
print($json_info);
}
?>
22 changes: 21 additions & 1 deletion web_gui/daikin_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,28 @@ function request_control() {
set_loading(1);
}

function send_control(){
function send_control(json_opt){
var target="api.php";
var request="POST";

var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
if ( xmlhttp.readyState == 4 ){
if( xmlhttp.status==200 ){
var jsonObj = JSON.parse(xmlhttp.responseText);
console.log(jsonObj);
}else{
console.log("Error: send control request failed");
}
}else{
//alert(xmlhttp.readyState);
}
}

xmlhttp.open(request,target,true);
xmlhttp.setRequestHeader("Content-type","application/json");
xmlhttp.send(json_opt);

}

function request_sensor(){
Expand Down
2 changes: 1 addition & 1 deletion web_gui/engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function set_array_info($uri,$aircon_ip,$parameters){
$pair= explode("=",$value);
$control_info[$pair[0]]=$pair[1];
}
return $control_info;
return json_encode($control_info);
}
}

Expand Down

0 comments on commit c7ae4a0

Please sign in to comment.