} function getPeriphHistory($conn, $periph_id, $start_date = NULL, $end_date = NULL) { if (is_null($end_date)) { $end_date = date("Y-m-d H:i:s"); } if (is_null($start_date)) { $start_date = date("Y-m-d H:i:s", strtotime("-1 year", time())); } $sql = "SELECT measurement,timestamp FROM periph_history WHERE periph_id=" . $periph_id . " AND timestamp between \"" . $start_date . "\" and \"" . $end_date . "\" ORDER BY timestamp DESC;"; $result = $conn->query($sql); $results = array(); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { $results[] = array("measurement" => $row["measurement"], "timestamp" => $row["timestamp"]); } } echo json_encode($results); } switch ($_GET["function"]) { case "history": getPeriphHistory($conn, $_GET["deviceID"], htmlspecialchars($_GET["start_date"]), htmlspecialchars($_GET["end_date"])); break; case "periphList": devices($conn); break; case "value": getValue($conn, $_GET["deviceID"]); break; } $conn->close();
function get_device_list($db) { devices($db, 'callback_dev_html'); }