Commit bb48b780 by root

First test routine

parent 35f747e2
......@@ -17,7 +17,11 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
$schedule->call(ShellyLogController::class, 'fetch_data')->everyMinute();
$schedule->call(function () {
ShellyLogController::fetch_data();
})->everyMinute();
//$schedule->call('ShellyLogController@test')->everyMinute;
//$schedule->call('App\Http\Controllers\ShellyLogController@fetch_data')->everyMinute();
}
......
......@@ -30,27 +30,44 @@ static public function fetch_data()
$data = json_decode($json,true);
$sum_power = $data['meters'][0]['counters'][0];
//echo round($sum_power, 2).'W <br>';
Carbon::now()->format('Y');
$year = Carbon::now()->format('Y');
$month = Carbon::now()->format('m');
$day = Carbon::now()->format('d');
$startday = Carbon::create($year, $month, $day, 0, 0, 0, 'Europe/Berlin')->timestamp;
$endday = Carbon::create($year, $month, $day, 23, 59, 59, 'Europe/Berlin')->timestamp;
//dd($startday);
$timestamp = Carbon::now()->timestamp;
$wattnow = $data['meters'][0]['counters'][0];
//$wattnow = 182.53;
$power_last = SolarPowerMinute::take(1)->where('timestamp', '>', $startday)->where('timestamp', '<', $endday)->orderBy('timestamp', 'desc')->get();
$power_last = SolarPowerMinute::take(1)->first();
//dd($power_last);
$watt_total = $wattnow;
foreach ($power_last as $p) {
//dd($p->timestamp);
dd($power_last);
if(empty($p->wattminutetotal)){
$watt_total = $wattnow;
} else {
$watt_total = $p->wattminutetotal + $wattnow;
}
/*if($power_last->wattminutetotal == null){
$watt_total = $wattnow;
} else {
$watt_total = $power_last->wattminutetotal + $wattnow;
}
*/
$log = new SolarPowerMinute([
'timestamp' => $timestamp,
'wattminute' => $wattnow,
'wattminutetotal' => 0
'wattminutetotal' => $watt_total
]);
//$log->save();
$log->save();
......
......@@ -69,7 +69,7 @@
|
*/
'timezone' => 'UTC',
'timezone' => 'Europe/Berlin',
/*
|--------------------------------------------------------------------------
......@@ -82,7 +82,7 @@
|
*/
'locale' => 'en',
'locale' => 'de',
/*
|--------------------------------------------------------------------------
......
......@@ -46,7 +46,7 @@
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'host' => env('DB_HOST', '192.168.88.160'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'bkw_info'),
'username' => env('DB_USERNAME', 'root'),
......
......@@ -16,8 +16,8 @@ public function up()
Schema::create('solar_power_minutes', function (Blueprint $table) {
$table->id();
$table->integer('timestamp', $precision = 0);
$table->integer("wattminute");
$table->integer("wattminutetotal");
$table->float("wattminute",5, 2);
$table->float("wattminutetotal", 10, 2);
$table->timestampsTz();
});
}
......
......@@ -22,4 +22,4 @@
Route::get('/test', [ShellyLogController::class, 'test']);
Route::get('/data', [ShellyLogController::class, 'fetch_data']);
//Route::get('/data', [ShellyLogController::class, 'fetch_data']);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment