upload test, viac senzorov
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -20,6 +20,7 @@ class StatisticsController extends Controller
|
||||
$startdate = $request->input('startdate',NULL);
|
||||
$enddate = $request->input('enddate',NULL);
|
||||
$range = $request->input('range',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());
|
||||
@@ -34,7 +35,7 @@ class StatisticsController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$q = sprintf("select time,min(value),max(value),mean(value),last(value) from bme280_value where host='balkon' and type='%s' and time >= %s and time <= %s group by time(%s);",$type,$startdate,$enddate,$range);
|
||||
$q = sprintf("select time,min(value),max(value),mean(value),last(value) from bme280_value where host='%s' and type='%s' and time >= %s and time <= %s group by time(%s);",$host,$type,$startdate,$enddate,$range);
|
||||
\Debugbar::info($q);
|
||||
$result = \InfluxDB::query($q);
|
||||
$points = $result->getPoints();
|
||||
|
||||
58
app/Http/Controllers/Upload.php
Normal file
58
app/Http/Controllers/Upload.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Upload extends Controller
|
||||
{
|
||||
public function index(){
|
||||
return view('index');
|
||||
}
|
||||
|
||||
public function uploadFile(Request $request){
|
||||
|
||||
if ($request->input('submit') != null ){
|
||||
|
||||
$file = $request->file('file');
|
||||
|
||||
// File Details
|
||||
$filename = $file->getClientOriginalName();
|
||||
$extension = $file->getClientOriginalExtension();
|
||||
$tempPath = $file->getRealPath();
|
||||
$fileSize = $file->getSize();
|
||||
$mimeType = $file->getMimeType();
|
||||
|
||||
// Valid File Extensions
|
||||
$valid_extension = array("jpg","jpeg","png");
|
||||
|
||||
// 2MB in Bytes
|
||||
$maxFileSize = 2097152;
|
||||
|
||||
// Check file extension
|
||||
if(in_array(strtolower($extension),$valid_extension)){
|
||||
|
||||
// Check file size
|
||||
if($fileSize <= $maxFileSize){
|
||||
|
||||
// File upload location
|
||||
$location = 'images';
|
||||
|
||||
// Upload file
|
||||
$file->move($location,$filename);
|
||||
|
||||
Session::flash('message','Upload Successful.');
|
||||
}else{
|
||||
Session::flash('message','File too large. File must be less than 2MB.');
|
||||
}
|
||||
|
||||
}else{
|
||||
Session::flash('message','Invalid File Extension.');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Redirect to index
|
||||
echo "OK";
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,6 @@ class VerifyCsrfToken extends Middleware
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
'upload/*',
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user