Archived
1
0
This repository has been archived on 2025-11-02. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
statstat/getdata.php
dorfl68 9a4f57b5bb Support for many thermostats
Uses the device ID to support several thermostats. Pretty simple - only
setup is now an array of devices, now a single device. However, many
changes follow...
2016-01-19 22:29:04 -05:00

57 lines
1.2 KiB
PHP

<?php
$q = '';
if(isset($_GET)){
if(isset($_GET['q'])){
$q = $_GET['q'];
$d = 1488017; // device ID number
header('Content-Type: application/json');
include('settings/globals.php');
$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = '';
switch($q){
case "inside":
$sql = "SELECT UNIX_TIMESTAMP(date),dispTemperature from stat";
break;
case 'outside':
$sql = "SELECT UNIX_TIMESTAMP(date),weatherTemperature from stat";
break;
case 'set_heat':
$sql = "SELECT UNIX_TIMESTAMP(date),heatSetpoint from stat";
break;
case 'set_cool':
$sql = "SELECT UNIX_TIMESTAMP(date),coolSetpoint from stat";
break;
case 'humidity':
$sql = "SELECT UNIX_TIMESTAMP(date),weatherHumidity from stat";
break;
default:
die("No query");
}
$sql = $sql . " WHERE deviceID=" . $d;
$result = $conn->query($sql);
echo $sql;
$rows = array();
while($r = mysqli_fetch_assoc($result)) {
$row = array_map('floatval',array_values($r));
$row[0] = $row[0]*1000;
$rows[] = $row;
echo $row[1];
}
$conn->close();
}
}
?>