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) {

View File

@@ -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();

View 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";
}
}

View File

@@ -19,6 +19,6 @@ class VerifyCsrfToken extends Middleware
* @var array
*/
protected $except = [
//
'upload/*',
];
}

2
public/js/app.js vendored

File diff suppressed because one or more lines are too long

12
resources/js/app.js vendored
View File

@@ -48,6 +48,9 @@ Vue.use(TabsPlugin);
import { CardPlugin } from 'bootstrap-vue'
Vue.use(CardPlugin);
import { BButton } from 'bootstrap-vue'
Vue.component('b-button', BButton);
//(function () {
var app = new Vue({
el: '#app',
@@ -58,6 +61,7 @@ Vue.use(CardPlugin);
time: null,
startdate: null,
enddate: null,
host: 'balkon',
componentKey: 0,
ti: 0, //Tab Index
graphShow: [],
@@ -111,6 +115,11 @@ Vue.use(CardPlugin);
displayResults: function () {
this.getData();
},
sethost: function (host) {
this.host = host;
this.getData();
console.log(host);
},
resizeGraph: function (i) {
console.log("RESIZE");
let index = "dg[" + i + "]";
@@ -149,7 +158,8 @@ Vue.use(CardPlugin);
params: {
type: vts[t],
startdate: this.startdate,
enddate: this.enddate
enddate: this.enddate,
host: this.host
}
})
.then(function (response) {

View File

@@ -6,7 +6,7 @@
<script>
export default {
props: ['fromdate','todate','type','range'],
props: ['fromdate','todate','type','range','host'],
name: 'Stats',
data() {
return {
@@ -34,7 +34,8 @@ export default {
type: this.type,
startdate: this.fromdate,
enddate: this.todate,
range: this.range
range: this.range,
host: this.host
}
})
.then(function (response) {

View File

@@ -92,6 +92,12 @@
<div class="row">
<vue-thermometer class="justify-content-center col-sm-3" :value="temperature" :min="tmin" :max="tmax"></vue-thermometer>
<div class="col-sm-9" id="values">
<div>
<b-button variant="primary" v-on:click="sethost('balkon')">Balkón</b-button>
<b-button variant="secondary" v-on:click="sethost('decka')">Decká</b-button>
<b-button variant="success" v-on:click="sethost('strecha')">Strecha</b-button>
</div>
<vue-table-dynamic :params="params"></vue-table-dynamic>
<ul>
<li>Čas: @{{time}}</li>

View File

@@ -18,4 +18,5 @@ Route::get('/', function () {
Route::get('/data',"MeasurementController@index");
Route::get('/data/get',"MeasurementController@get");
Route::get('/stats/get',"StatisticsController@get");
Route::any('upload/image',"Upload@uploadFile");