<?php
// Koneksi ke database
$servername = "localhost";
$username = "wdpdev_master";
$password = "!Panda9980";
$dbname = "wdpdev_washing";

// Membuat koneksi ke database
$conn = new mysqli($servername, $username, $password, $dbname);

// Cek koneksi
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Ambil parameter dari permintaan
$serialNumber = $_GET['serialNumber'];
$branchId = $_GET['branchId'];

// Query untuk mengambil perintah kontrol berdasarkan serial number dan branch
$sql = "SELECT command, duration FROM machine WHERE serialNumber = '$serialNumber' AND branchId = $branchId ORDER BY id DESC LIMIT 1";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // Output data perintah kontrol
    $row = $result->fetch_assoc();
    echo json_encode($row);
} else {
    echo json_encode(array("command" => "OFF", "duration" => 0)); // Default OFF jika tidak ada data
}

$conn->close();
?>
