Created
October 27, 2017 01:09
-
-
Save kuc-arc-f/8b9c3acd2619e53c9819cf284d1563a9 to your computer and use it in GitHub Desktop.
IoT data seve API (php) for GoogleHome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// $file = 'dat/rest-data.json'; | |
class AppConst { | |
var $val01 = 'val01_###'; | |
var $mDir='dat'; | |
var $mExtName ='.json'; | |
var $mOK_CODE=1; | |
var $mNG_CODE=0; | |
function __construct(){ | |
} | |
} | |
$mConst = new AppConst(); | |
//------------------------------------ | |
// @calling | |
// @purpose : | |
// @date | |
// @argment | |
// @return | |
//------------------------------------ | |
function write_f4_proc( $dname, $v4, $v5 ){ | |
$const = new AppConst(); | |
$ret= $const->mNG_CODE; | |
$sFnm = $const->mDir . "/" . $dname . $const->mExtName; | |
$dat["temperature"] =0; | |
$dat["humidity"] =0; | |
if(isset($v4 )){ | |
$dat["temperature"] =$v4; | |
} | |
if(isset($v5 )){ | |
$dat["humidity"] = $v5; | |
} | |
$sJson =json_encode($dat); | |
$current = $sJson; | |
file_put_contents($sFnm , $current); | |
$ret = $const->mOK_CODE; | |
return $ret; | |
} | |
// | |
// main | |
if(isset($_GET["value1"])){ | |
$dat["temperature"]= $_GET["value1"]; | |
$dat["humidity"]=0; | |
// $dat["humidity"]= $_GET["value2"]; | |
if(isset($_GET["value2"])){ | |
$dat["humidity"]= $_GET["value2"] ; | |
} | |
$sJson =json_encode($dat); | |
//d1 | |
$sFnm =$mConst->mDir . "/" . "device1" . $mConst->mExtName; | |
// var_dump($sFnm ); | |
$current = $sJson; | |
file_put_contents($sFnm , $current); | |
} | |
//d4 | |
if(isset($_GET["value4"])){ | |
if(isset($_GET["value5"])){ | |
write_f4_proc( "device4", $_GET["value4"], $_GET["value5"] ); | |
}else{ | |
write_f4_proc( "device4", $_GET["value4"], 0 ); | |
} | |
} | |
print("1"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment