python - Send dictionary from raspberry to Laravel framework
one text
I need to send a dictionary written in Python on a Raspberry Pi4 to Laravel framework. For creating the dictionary, I read from a file.txt and then convert the dictionary to a json format and the send via request.post method. Now, what I have to do to view the dictionary in Laravel view and then work with it?
The code in my raspberry for create and send dictionary:
def readFile():
with open("/home/pi/Desktop/Progetti SIoTD/Bluetooth/device.txt", "r") as file:
for i in file:
line, *lines = i.split()
if line in mac_dict:
mac_dict[line] += lines
else:
mac_dict[line] = lines
print(mac_dict)
print("\n")
json_obj = json.dumps(mac_dict, indent=4) #encode json
print(json_obj)
r = requests.post(ip, json=json_obj)
print(r.text)
The route in web.php:
Route::get('dict', [DictionaryController::class, 'getDict'])->name('dict');
And the route in api.php:
Route::post('dictionary', [DictionaryController::class, 'getDict'])->name('dictionary');
The controller in laravel:
class DictionaryController extends Controller
{
public function index()
{
return view('backend.auth.user.dictionary');
}
public function store(Request $request)
{
}
public function show($id)
{
}
public function update(Request $request, $id)
{
//
}
public function destroy($id)
{
//
}
public function getDict(Request $request)
{
echo $request;
}
}
This is the view that I want to use for displaying the dict/json
@extends('backend.layouts.app')
@section('content')
@endsection
Someone can help me? I've been trying to figure this out for weeks
UPDATE
I forgot to say that I send the json in api/dictionary route, but I want to display it in route dict (that is in web.php)
Source