<?php
$gett = $_GET["q"];//获取数据
$selectTimeMin = $_GET['selectTimeMin'];
$selectTimeMax = $_GET['selectTimeMax'];
ini_set("precision", "3");  //浮点数小数位数
   class MyDB extends SQLite3
   {
      function __construct()
      {
			$this->open('./Debug/DB/SL651.sqlite.db3');   
      }
   }
   $con = new MyDB();
   if(!$con){
      echo $con->lastErrorMsg();
   } 

// 选择数据库
//$sql="SELECT * FROM dataInfo WHERE dataTime > '$selectTimeMin' and dataTime < '$selectTimeMax' and devID = '".$gett."' ORDER by `dataTime` DESC LIMIT 0,30;";
//$sql="SELECT * FROM dataInfo WHERE dataTime > '$selectTimeMin' and dataTime < '$selectTimeMax' and devID = '".$gett."' ORDER by `dataTime` DESC LIMIT 30;";
//$sql="SELECT * FROM dataInfo WHERE dataTime > '$selectTimeMin' and dataTime < '$selectTimeMax' and devID = '".$gett."' ORDER by `dataTime` DESC LIMIT 30;";
$sql="SELECT * FROM dataInfo WHERE devID = '".$gett."' ORDER by `reportTime` DESC LIMIT 250;";
$result = $con->query($sql);
//echo $sql;
if (!$result) {
    printf("Error: SELECT DB ERR\n");
	$con->close();
    exit();
}

$news = [];
$i=0;

while($row = $result->fetchArray(SQLITE3_ASSOC)) {
	if ($row['pcode']== '3C') {
		$dataTime=$row['reportTime'];
		$fBatVoltage= $row['pvalue']*100;
		$LightOnOff= 45-$row["pvalue"]*100;
		$news[$i] = array("dataTime"=>"$dataTime","fBatVoltage"=>"$fBatVoltage","LightOnOff"=>"$LightOnOff");
		$i=$i+1;
	}
}
$datalist = array_reverse($news); //反序排列
// $datalist = $news;
echo json_encode($datalist,JSON_UNESCAPED_UNICODE);
$con->close();
 ?>