Create the time graph in Laravel
Hi everyone,
I am creating a project in laravel that deals with indoor bluetooth tracking. At the moment I capture bluetooth signals and related RSSI powers from any device. All these signals are saved on a DB. What I need to do is to figure out how long specific devices stay in range of my receiver and create the corresponding graphs. The MAC addresses of the devices I want to track are saved to another table in the DB and are displayed on a Laravel view. In this view I set up two buttons so that by pressing on them I move to the specific view for that single device. But how do I keep track of how long that device stays in my receiver radius and how do I create graphs? The following images are the pages where I display the devices I want to track and the view where I want to insert the time graph
Now I'm going to insert the code I've created to realize the views, the controller and the routes
Controller:
namespace App\Http\Controllers;
use App\Models\Device; use App\Models\DataFromRasp; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Symfony\Component\Process\Process; use Symfony\Component\Process\Exception\ProcessFailedException; use Carbon\Carbon;
class DeviceController extends Controller {
public function index()
{
$data=Device::all();
return view('backend.auth.user.device', compact("data"));
}
public function create()
{
}
public function store(Request $request)
{
}
public function show(Device $deviceID)
{
}
public function edit(Device $device)
{
//
}
public function update(Request $request, Device $device)
{
//
}
public function destroy(Device $device)
{
//
}
/**
* Displays the data that is selected
*/
public function showDev(Device $deviceID)
{
$device = Device::firstWhere('id', $deviceID);
return view('backend.auth.user.singleDevice', compact("device"));
}
/**
* Displays all data present in the table data_from_rasps
*
* The data are all the devices that the raspberry can capture
*/
public function visualizeData()
{
$data=DataFromRasp::paginate(10);
return view('backend.auth.user.dictionary', compact("data"));
}
/**
* Raspberry capture and send the data to the DB and save in another
* table of the same DB the MAC addresses of interest
*/
public function getData(Request $request)
{
$m_data = $request->get('m_data');
$r_data = $request->get('r_data');
DataFromRasp::create(['MAC' => $m_data, 'RSSI' => $r_data]);
if(($m_data == 'C4:A5:DF:24:05:7E') and Device::where('MAC_ADDR', $request->m_data)->doesntExist()){
Device::create(['USERNAME'=>'Device1','MAC_ADDR' => $m_data]);
}
if(($m_data == '70:1C:E7:E4:71:DA') and Device::where('MAC_ADDR', $request->m_data)->doesntExist()){
Device::create(['USERNAME' => 'Device2','MAC_ADDR' => $m_data]);
}
}
public function scan()
{
$process = new Process(['C:\Simone\Università\Tirocinio\laravel-boilerplate-master', 'prova.py']);
$process->run();
if (!$process->isSuccessful()) { throw new ProcessFailedException($process); }
return redirect()->route('dict');
}
public function FirstDev(){
$dev = DB::table('data_from_rasps')->select('MAC', 'RSSI')->where('MAC', '=', 'C4:A5:DF:24:05:7E');
return view('backend.auth.user.firstDevice', compact("dev"));
//return view('backend.auth.user.singleDevice');
}
public function getTime()
{
$date = Carbon::now();
return $date;
}
}
Route:
Route::get('device' ,[DeviceController::class, 'index'])->name('devices'); Route::get('singleDevice/{deviceID}', [DeviceController::class, 'showDev'])->name('showDev'); Route::get('dict', [DeviceController::class, 'visualizeData'])->name('dict');
And view of the first image:
@extends('backend.layouts.app') @section('content')
<tr>
<th scope="col">ID</th>
<th scope="col">USERNAME</th>
<th scope="col">MAC ADDRESS</th>
</tr>
@foreach ($data as $item)
<tr>
<th scope="row">{{$item->id}}</th>
<td>{{$item->USERNAME}}</td>
<td>{{$item->MAC_ADDR}}</td>
<td>
<a href="{{ url('admin/singleDevice/'.$item->id) }}" class="btn btn-primary">Select</a>
</td>
</tr>
@endforeach
@endsection
Thanks in advance to anyone who can give me a hand
Please or to participate in this conversation.