43 lines
869 B
PHP
43 lines
869 B
PHP
<?php
|
|
|
|
//
|
|
// Just returns the latest Archive data from WeeWx Database
|
|
//
|
|
|
|
// Database connection details
|
|
$host = 'ikarus.egfh.internal';
|
|
$username = 'weero';
|
|
$password = 'tH9o3eHgZ5WQ]ti7';
|
|
$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);
|
|
|
|
?>
|