Get initial archive data on connect
This commit is contained in:
42
archive.php
Normal file
42
archive.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
//
|
||||
// Just returns the latest Archive data from WeeWx Database
|
||||
//
|
||||
|
||||
// Database connection details
|
||||
$host = 'ikarus.egfh.internal';
|
||||
$username = 'weewx';
|
||||
$password = 'p7P0DK9tlWAzKIH';
|
||||
$database = 'weewx';
|
||||
|
||||
function connectDb() {
|
||||
|
||||
$conn = new mysqli( $GLOBALS['host'], $GLOBALS['username'], $GLOBALS['password'], $GLOBALS['database']);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
die("Connection failed: " . $conn->connect_error);
|
||||
}
|
||||
|
||||
return $conn;
|
||||
|
||||
}
|
||||
|
||||
$conn = connectDb();
|
||||
|
||||
$sql = "SELECT dateTime,windSpeed,windDir,windGust,windGustDir,outTemp FROM archive ORDER BY dateTime DESC LIMIT 1";
|
||||
$result = $conn->query($sql);
|
||||
|
||||
$data = [];
|
||||
if ($result->num_rows > 0) {
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$data[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
$conn->close();
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($data[0], JSON_PRETTY_PRINT);
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user