67 lines
1.8 KiB
PHP
67 lines
1.8 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../config/database.php';
|
|
header('Content-Type: application/json');
|
|
header('Access-Control-Allow-Origin: *');
|
|
//header('Content-Type: application/json');
|
|
|
|
|
|
$database = new Database();
|
|
$conn = $database->getConnection();
|
|
|
|
$id = intval($_GET['id'] ?? 0);
|
|
if ($id <= 0) {
|
|
echo json_encode(['success'=>false,'message'=>'ID tidak valid']);
|
|
exit;
|
|
}
|
|
|
|
$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;
|
|
}
|
|
|
|
$serialNumber = $row['serial_number'];
|
|
|
|
// Ambil RX Power dan PPPoE IP dari API
|
|
$rxPower = null;
|
|
$pppoeIP = null;
|
|
|
|
if ($serialNumber) {
|
|
$query = json_encode(["_id" => $serialNumber]);
|
|
$url = "http://localhost:7557/devices/?query=" . urlencode($query);
|
|
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
$response = curl_exec($ch);
|
|
curl_close($ch);
|
|
|
|
if ($response) {
|
|
$data = json_decode($response, true);
|
|
|
|
// Ambil RX Power
|
|
if (isset($data[0]['VirtualParameters']['RXPower']['_value'])) {
|
|
$rxPower = $data[0]['VirtualParameters']['RXPower']['_value'] . " dBm";
|
|
}
|
|
|
|
// Ambil PPPoE IP
|
|
if (isset($data[0]['VirtualParameters']['pppoeIP']['_value'])) {
|
|
$pppoeIP = $data[0]['VirtualParameters']['pppoeIP']['_value'];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Output JSON untuk AJAX
|
|
echo json_encode([
|
|
'success' => true,
|
|
'data' => [
|
|
'serial_number' => $serialNumber,
|
|
'rx_power' => $rxPower ?? 'Tidak tersedia',
|
|
'pppoe_ip' => $pppoeIP ?? 'Tidak tersedia'
|
|
]
|
|
]);
|