Example to receive it with PHP - Laravel
Route api:
Route::apiResource('nodes', 'NodeController');
Node Model
class Node extends Model
{
protected $fillable = [
'read_at',
'cluster_id',
'rssi',
'mac',
];
public function cluster(){
return $this->belongsTo(Cluster::class); // maybe create the cluster info?
}
}
Cluster Model
class Cluster extends Model
{
protected $fillable = [
'name'
];
public function cluster(){
return $this->hasOne(Node::class);
}
}
Node Controller
/**
* @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection
*/
public function index()
{
return NodeResource::collection(Node::with('cluster')->paginate(25));
}
/**
* @param Request $request
* @return NodeResource
*/
public function store(Request $request)
{
if(!empty($request->probes)){
foreach ($request->probes as $item){
Node::create([
'cluster_id' => $item['cluster_id'],
'rssi' => $item['rssi'],
'mac' => $item['mac'],
'read_at' => Carbon::now()->format('Y-m-d H:i:s'),
]);
}
return response()->json('Bulk data posted.', 200);
}
return response()->json('empty', 200);
}