Skip to content

Instantly share code, notes, and snippets.

@kuc-arc-f
Created October 27, 2017 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuc-arc-f/8b9c3acd2619e53c9819cf284d1563a9 to your computer and use it in GitHub Desktop.
Save kuc-arc-f/8b9c3acd2619e53c9819cf284d1563a9 to your computer and use it in GitHub Desktop.
IoT data seve API (php) for GoogleHome
<?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