upload test, viac senzorov

This commit is contained in:
2021-01-30 14:27:23 +01:00
parent ec5c81a587
commit 8fce0013f7
9 changed files with 89 additions and 10 deletions

View File

@@ -20,6 +20,7 @@ class MeasurementController extends Controller
$type = $request->input('type', $types[0]);
$startdate = $request->input('startdate',NULL);
$enddate = $request->input('enddate',NULL);
$host = $request->input('host','balkon');
if (!in_array($type,$types)) $type = $types[0];
if ($startdate == NULL || $startdate == '') $startdate = "now()-1d";
else $startdate = sprintf("'%s'",Carbon::parse($startdate)->toDateTimeString());
@@ -27,7 +28,7 @@ class MeasurementController extends Controller
if ($enddate == NULL || $enddate == '') $enddate = "now()";
else $enddate = sprintf("'%s'",Carbon::parse($enddate)->toDateTimeString());
$q = sprintf("select time,value from bme280_value where host='balkon' and type='%s' and time >= %s and time <= %s",$type,$startdate,$enddate);
$q = sprintf("select time,value from bme280_value where host='%s' and type='%s' and time >= %s and time <= %s",$host,$type,$startdate,$enddate);
\Debugbar::info($q);
$result = \InfluxDB::query($q);
$points = $result->getPoints();
@@ -43,12 +44,13 @@ class MeasurementController extends Controller
*
* @return \Illuminate\Http\Response
*/
public function index()
public function index(Request $request)
{
// for t in ('temperature','humidity','pressure')
$a = [];
$host = $request->input('host','balkon');
foreach (['temperature','humidity','pressure'] as $type) {
$q = sprintf("select * from bme280_value where host='balkon' and type='%s' order by time desc limit 1",$type);
$q = sprintf("select * from bme280_value where host='%s' and type='%s' order by time desc limit 1",$host,$type);
$result = \InfluxDB::query($q);
$points = $result->getPoints();
foreach ($points as $p) {
@@ -56,7 +58,7 @@ class MeasurementController extends Controller
$a["time"] = Carbon::createFromFormat("Y-m-d\TH:i:s.u+",$p["time"],'UTC')->toATOMString();
}
}
$q = sprintf("select * from esp32_value where host='balkon' and type='voltage' order by time desc limit 1",$type);
$q = sprintf("select * from esp32_value where host='%s' and type='voltage' order by time desc limit 1",$host,$type);
$result = \InfluxDB::query($q);
$points = $result->getPoints();
foreach ($points as $p) {