Archived
1
0

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...
This commit is contained in:
dorfl68
2016-01-19 22:29:04 -05:00
parent f9b7276cb6
commit 9a4f57b5bb
14 changed files with 568 additions and 469 deletions

57
getdata.php Normal file
View File

@@ -0,0 +1,57 @@
<?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();
}
}
?>