get('/user', function (Request $request) { return $request->user(); }); // Vibration Sensor API Routes Route::prefix('vibration')->group(function () { // Terima data sensor getar dari IoT device Route::post('/data', [VibrationController::class, 'receiveData']); // Ambil data vibration terbaru Route::get('/readings', [VibrationController::class, 'getLatestReadings']); // Ambil statistik getaran Route::get('/statistics', [VibrationController::class, 'getStatistics']); }); // PIR Sensor API Routes Route::prefix('pir')->group(function () { // Terima data sensor PIR dari IoT device Route::post('/data', [PirController::class, 'receiveData']); // Ambil data PIR terbaru Route::get('/readings', [PirController::class, 'getLatestReadings']); // Ambil statistik gerakan Route::get('/statistics', [PirController::class, 'getStatistics']); }); // Door Access (Reed Switch) API Routes Route::prefix('door-access')->group(function () { // Terima data sensor Reed Switch dari IoT device Route::post('/data', [DoorAccessController::class, 'receiveData']); // Ambil data door access terbaru Route::get('/readings', [DoorAccessController::class, 'getLatestReadings']); // Ambil statistik door access Route::get('/statistics', [DoorAccessController::class, 'getStatistics']); }); // LoRa Communication API Routes Route::prefix('lora')->group(function () { // Terima message LoRa dari gateway Route::post('/receive', [LoRaController::class, 'receiveMessage']); // Kirim command ke LoRa node Route::post('/send-command', [LoRaController::class, 'sendCommand']); // Kirim konfigurasi ke LoRa node Route::post('/send-config', [LoRaController::class, 'sendConfig']); // Ambil messages LoRa terbaru Route::get('/messages', [LoRaController::class, 'getMessages']); // Ambil statistik LoRa communication Route::get('/statistics', [LoRaController::class, 'getStatistics']); // Process unprocessed messages Route::post('/process-messages', [LoRaController::class, 'processUnprocessedMessages']); }); // ============================================================ // MQTT Integration Routes // ============================================================ Route::prefix('mqtt')->group(function () { // Terima data dari MQTT bridge/webhook (dipanggil oleh bridge yang subscribe ke HiveMQ) // POST body: { "topic": "keamanan/pir", "payload": "{...json...}" } Route::post('/ingest', [MqttController::class, 'ingest']); // Terima batch data dari MQTT bridge // POST body: { "messages": [ {"topic":"...", "payload":"..."}, ... ] } Route::post('/ingest-batch', [MqttController::class, 'ingestBatch']); // Publish pesan ke MQTT broker dari backend // POST body: { "topic": "keamanan/command", "payload": {...} } Route::post('/publish', [MqttController::class, 'publish']); // Kirim command ke ESP32 node via MQTT // POST body: { "node_id": "NODE_001", "command": "REBOOT", "params": {} } Route::post('/command', [MqttController::class, 'sendCommand']); }); // Device Status API — untuk polling online/offline dari frontend Route::get('/device/status', function () { $device = \App\Models\Device::orderBy('last_seen', 'desc')->first(); $online = $device && $device->last_seen && $device->last_seen->diffInMinutes(now()) <= 2; return response()->json([ 'success' => true, 'online' => $online, 'last_seen' => $device?->last_seen?->toISOString(), 'last_seen_human' => $device?->last_seen?->diffForHumans() ?? 'Belum pernah online', 'device_name' => $device?->name ?? 'ESP32', ]); }); // Test notification endpoints Route::post('/test-notification', function () { $notificationService = new \App\Services\NotificationService(); $result = $notificationService->sendTestNotification(); return response()->json([ 'success' => true, 'message' => 'Test vibration notification sent', 'results' => $result ]); }); Route::post('/test-pir-notification', function () { $notificationService = new \App\Services\NotificationService(); $result = $notificationService->sendTestPirNotification(); return response()->json([ 'success' => true, 'message' => 'Test PIR notification sent', 'results' => $result ]); }); Route::post('/test-door-access-notification', function () { $notificationService = new \App\Services\NotificationService(); $result = $notificationService->sendTestDoorAccessNotification(); return response()->json([ 'success' => true, 'message' => 'Test Door Access notification sent', 'results' => $result ]); });