getConnection(); // ====================== // 🔥 TEST MODE // ====================== // url test : http://localhost/ftthplanner/api/detail_redaman.php?id=859 $TEST_MODE = true; $TEST_DATA = [ "08A5AE-F609-ZXIC6A7451C337D" => [ "rx" => -23, "volt" => 2.9 ], //id 836 Client putri 081252188305 sn : GGCL298413e0 "08A5AE-F609-ZXIC03C33C4B433" => [ "rx" => -32, "volt" => 3.2 ], //id : 859 difta dwi RT via kantor sn : CDTCaf8ee4ed "08A5AE-F609-ZXIC1D6EF05BDD7" => [ "rx" => -28, "volt" => 3.2 ], ]; // ====================== // 🔥 VALIDASI ID // ====================== $id = intval($_GET['id'] ?? 0); if ($id <= 0) { echo json_encode(['success'=>false,'message'=>'ID tidak valid']); exit; } // ====================== // 🔥 AMBIL SN // ====================== $stmt = $conn->prepare("SELECT serial_number FROM ftth_items WHERE id=:id"); $stmt->bindParam(':id', $id, PDO::PARAM_INT); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); if (!$row) { echo json_encode(['success'=>false,'message'=>'Data tidak ditemukan']); exit; } // 🔥 NORMALISASI SN $serialNumber = strtoupper(trim($row['serial_number'])); // ====================== // 🔥 DEFAULT // ====================== $rxPower = null; $pppoeIP = null; $voltage = null; $uptime = null; $inform = null; // ====================== // 🔥 CEK: MANUAL ATAU AUTO // ====================== $useManual = ($TEST_MODE && isset($TEST_DATA[$serialNumber])); if ($useManual) { // ====================== // 🔥 MODE MANUAL (HANYA SN YANG ADA DI TEST_DATA) // ====================== $rxPower = $TEST_DATA[$serialNumber]['rx'] . " dBm"; $voltage = number_format($TEST_DATA[$serialNumber]['volt'], 2) . " V"; $pppoeIP = "TEST MODE"; $uptime = "-"; $inform = "MANUAL"; } else { // ====================== // 🔥 MODE AUTO (GENIEACS) // ====================== if ($serialNumber) { $query = json_encode(["_id" => $serialNumber]); $url = "http://rmtstb.megadataisp.net:7557/devices/?query=" . urlencode($query); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 5); $response = curl_exec($ch); curl_close($ch); if ($response) { $data = json_decode($response, true); if (isset($data[0])) { // RX if (isset($data[0]['VirtualParameters']['RXPower']['_value'])) { $rxPower = $data[0]['VirtualParameters']['RXPower']['_value'] . " dBm"; } // PPPoE if (isset($data[0]['VirtualParameters']['pppoeIP']['_value'])) { $pppoeIP = $data[0]['VirtualParameters']['pppoeIP']['_value']; } // Voltage if (isset($data[0]['VirtualParameters']['Voltage']['_value'])) { $rawVoltage = $data[0]['VirtualParameters']['Voltage']['_value']; $voltageConvert = $rawVoltage / 10000; $voltage = number_format($voltageConvert, 2) . " V"; } // Uptime if (isset($data[0]['InternetGatewayDevice']['DeviceInfo']['UpTime']['_value'])) { $seconds = (int)$data[0]['InternetGatewayDevice']['DeviceInfo']['UpTime']['_value']; $uptime = gmdate("H:i:s", $seconds); } // Inform if (isset($data[0]['Events']['Inform'])) { $inform = $data[0]['Events']['Inform']; } } } } } // ====================== // 🔥 OUTPUT // ====================== echo json_encode([ 'success' => true, 'data' => [ 'serial_number' => $serialNumber, 'rx_power' => $rxPower ?? 'Tidak tersedia', 'pppoe_ip' => $pppoeIP ?? 'Tidak tersedia', 'voltage' => $voltage ?? 'Tidak tersedia', 'uptime' => $uptime ?? 'Tidak tersedia', 'inform' => $inform ?? 'Tidak tersedia' ] ]);