Add commands for posting and reboot

This commit is contained in:
2025-09-10 12:31:35 +10:00
parent 998b340411
commit 7a842805ab
3 changed files with 36 additions and 0 deletions

View File

@@ -165,4 +165,28 @@ return response($body, 200)
return response()->json(['ok' => true], 200);
}
public function storeCommand(Request $request, $imei)
{
// 1. Validate the incoming data from the T3 dashboard
$validated = $request->validate([
'type' => 'required|string|in:wifi,sleep,telemetry_sec,poll_sec,ota,ring_fence,lights,camera,reboot',
'payload' => 'present|nullable|array',
]);
// 2. Find the device by its IMEI, or create it if it's the first time we've seen it
$device = Device::firstOrCreate(['imei' => $imei]);
// 3. Create the command and associate it with the device
$command = $device->commands()->create([
'type' => $validated['type'],
'payload' => $validated['payload'],
'status' => 'queued', // Set a default status
]);
// 4. Return a success response with the new command's ID
return response()->json([
'ok' => true,
'command_id' => $command->id,
], 201); // HTTP 201 Created
}
}