📂 FileMgr
📍
/home/u625410797/domains/monothailand.com/public_html/smart_panel/cron
✏️ Edit File: /home/u625410797/domains/monothailand.com/public_html/smart_panel/cron/process_schedules.php
⬅ Kembali
<?php /** * [MASTERPIECE] INDUSTRIAL SCHEDULE PROCESSOR V1.0 * Run this via Cron every minute: * * * * * php process_schedules.php */ require_once __DIR__ . '/../config.php'; try { $now = new DateTime(); $currentHour = (int)$now->format('H'); $currentMinute = (int)$now->format('W'); // Wait, minute is 'i' $currentMinute = (int)$now->format('i'); $currentDay = (int)$now->format('w'); // 0=Sun, 1=Mon...6=Sat // Fetch all active schedules that match current time $stmt = $pdo->prepare(" SELECT s.*, i.channel_values FROM industrial_schedules s JOIN industrial_scenes i ON s.scene_id = i.id WHERE s.is_enabled = 1 AND s.hour = ? AND s.minute = ? AND JSON_CONTAINS(s.days_of_week, ?) AND (s.last_run_at IS NULL OR DATE(s.last_run_at) != CURDATE() OR (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(s.last_run_at)) > 60) "); $stmt->execute([$currentHour, $currentMinute, json_encode($currentDay)]); $schedules = $stmt->fetchAll(); foreach ($schedules as $sched) { $channelValues = json_decode($sched['channel_values'], true); foreach ($channelValues as $slotId => $data) { // Push command to gateway $cmd = "SCENE_RECALL"; $payload = json_encode([ 'scene_id' => $sched['scene_id'], 'ch' => $data['ch'] ?? 0, 'val' => $data['value'] ?? 0, 'fade' => $data['fade_ms'] ?? 0 ]); $insStmt = $pdo->prepare("INSERT INTO commands (slot_id, command, payload, priority) VALUES (?, ?, ?, 1)"); $insStmt->execute([$slotId, $cmd, $payload]); } // Mark as run $updStmt = $pdo->prepare("UPDATE industrial_schedules SET last_run_at = NOW() WHERE id = ?"); $updStmt->execute([$sched['id']]); error_log("INDUSTRIAL SCHEDULE: Executed '{$sched['name']}' for Site {$sched['site_id']}"); } } catch (Exception $e) { error_log("INDUSTRIAL SCHEDULE ERROR: " . $e->getMessage()); }
💾 Simpan File
Batal
⬅ Naik ke smart_panel
1 item
Nama
Tipe
Ukuran
Diubah
Aksi
🐘
process_schedules.php
php
2 KB
2026-04-30 04:28
✏️ Edit
👁️ View
🗑 Hapus