diff --git a/calc_delay.php b/calc_delay.php new file mode 100644 index 0000000..abbfad8 --- /dev/null +++ b/calc_delay.php @@ -0,0 +1,94 @@ +query($sql); +if (!$result) { +printf("Errormessage: %s\n", $conn->error); +} +$rows = array(); +while($r = mysqli_fetch_assoc($result)) { + $r['date'] = $r['UNIX_TIMESTAMP(date)']; + unset($r['UNIX_TIMESTAMP(date)']); + $rows[] = $r; +} +// print("
");
+// print_r($rows);
+$startTime = -1;
+$startTemp = NULL;
+$startSetPoint = NULL;
+$targetSetPoint = NULL;
+
+$heat_up = NULL;
+$heat_down = NULL;
+$cool_up = NULL;
+$cool_down = NULL;
+$type = NULL;
+
+for($i = 1; $i < count($rows); $i++){
+ $now = $rows[$i];
+ $last= $rows[$i-1];
+// echo $startTime;
+// print_r($now);
+ if($startTime == -1){
+// echo "no start
";
+ if($now['heatSetPoint'] <> $last['heatSetPoint']){
+ //Down!
+// echo "down
";
+ $startTime = $now['date'];
+ $startTemp = $now['dispTemperature'];
+ $startSetPoint = $last['heatSetPoint'];
+ $targetSetPoint = $now['heatSetPoint'];
+ if($now['heatSetPoint'] > $last['heatSetPoint']){
+ $type = "up";
+ } else {
+ $type = "down";
+ }
+ }
+ } else{
+ //looking for end
+// echo "yes start
";
+ if($now['dispTemperature'] == $targetSetPoint || $now['heatSetPoint'] <> $targetSetPoint){
+ $changeTime = ($now['date']-$startTime)/60;
+ $changeTemp = abs($startTemp - $now['dispTemperature']);
+ $outside = $now['weatherTemperature'];
+ $minperdeg = $changeTime/$changeTemp;
+
+ if($type == "up"){
+ $heat_up[] = [$minperdeg,intval($outside)];
+ } else{
+ $heat_down[] = [$minperdeg,intval($outside)];
+ }
+
+ $startTime = -1;
+ }
+ }
+
+}
+
+$return = [$heat_up, $heat_down];
+
+print json_encode($return);
+
+
+$conn->close();
+
+?>
\ No newline at end of file
diff --git a/cron.php b/cron.php
index eaa7108..fe77d4e 100644
--- a/cron.php
+++ b/cron.php
@@ -2,41 +2,47 @@
include('settings/globals.php');
-$valid_thermostats = ["honeywell"];
-
if(in_array(THERMOSTAT_TYPE,$valid_thermostats)){
- require('thermostats/'.THERMOSTAT_TYPE.'/scrape.php');
+ require('thermostats/'.THERMOSTAT_TYPE.'/scrape.php');
+ require('thermostats/'.THERMOSTAT_TYPE.'/logininfo.php');
} else{
die("Invalid THERMOSTAT_TYPE set in settings/globals.php");
}
-$data = getCurrentInfo();
-
-$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
-// Check connection
-if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
-}
-
-$good_columns = array("coolLowerSetpLimit","coolNextPeriod","coolSetpoint","coolUpperSetptLimit","deviceID","dispTemperature","displayedUnits","heatLowerSetptLimit","heatNextPeriod","heatSetpoint","heatUpperSetptLimit","isInVacationHoldMode","schedCoolSp","schedHeatSp","scheduleCapable","statusCool","statusHeat","systemSwitchPosition","weatherHumidity","weatherPhrase","weatherTemperature");
-$clean_data = array();
-foreach($good_columns as $col){
- if(isset($data[$col])){
- $clean_data[$col] = $data[$col];
- }
-}
-$columns = implode(", ",array_keys($clean_data));
-$values = implode(", ", array_values($clean_data));
-$sql = "INSERT INTO `stat`(" . $columns . ") VALUES (" . $values.")";
-$result = $conn->query($sql);
-echo $sql;
-echo "\n";
-echo $result;
-if (!$result) {
- printf("Errormessage: %s\n", $conn->error);
-}
+// dorfl added simple loop
+for ($i = 0; $i query($sql);
+ echo $sql;
+ echo "\n";
+ echo $result;
+ if (!$result) {
+ printf("Errormessage: %s\n", $conn->error);
+ }
+} // end for thermostats
$conn->close();
diff --git a/db-get.php b/db-get.php
index 63b727c..a7b6faa 100644
--- a/db-get.php
+++ b/db-get.php
@@ -1,54 +1,70 @@
query($sql);
- if (!$result) {
- printf("Errormessage: %s\n", $conn->error);
- }
- $rows = array();
- while($r = mysqli_fetch_assoc($result)) {
- $row = array_map('floatval',array_values($r));
- $row[0] = $row[0]*1000;
- $rows[] = $row;
- }
- print json_encode($rows);
+ if(isset($_GET['id'])){
+ $d = $device_array[$_GET['id']];
+
+ //$d="1488017";
+
+ header('Content-Type: application/json');
+
+ $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);
+ if (!$result) {
+ printf("Errormessage: %s\n", $conn->error);
+ }
+ $rows = array();
+ while($r = mysqli_fetch_assoc($result)) {
+ $row = array_map('floatval',array_values($r));
+ $row[0] = $row[0]*1000;
+ $rows[] = $row;
+ }
+ print json_encode($rows);
- $conn->close();
-
+ $conn->close();
+ }
}
}
diff --git a/dbsetup.php b/dbsetup.php
index 073d14c..343ba95 100644
--- a/dbsetup.php
+++ b/dbsetup.php
@@ -1,6 +1,6 @@
-
-
- Stat delay
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/delay.php b/delay.php
index c32dd3b..f628232 100644
--- a/delay.php
+++ b/delay.php
@@ -1,82 +1,141 @@
+
+
+
+
+
+
+
query($sql);
-if (!$result) {
-printf("Errormessage: %s\n", $conn->error);
-}
-$rows = array();
-while($r = mysqli_fetch_assoc($result)) {
- $r['date'] = $r['UNIX_TIMESTAMP(date)'];
- unset($r['UNIX_TIMESTAMP(date)']);
- $rows[] = $r;
-}
-// print("");
-// print_r($rows);
-$startTime = -1;
-$startTemp = NULL;
-$startSetPoint = NULL;
-$targetSetPoint = NULL;
+ $valid_thermostats = ["honeywell"];
-$heat_up = NULL;
-$heat_down = NULL;
-$cool_up = NULL;
-$cool_down = NULL;
-$type = NULL;
-
-for($i = 1; $i < count($rows); $i++){
- $now = $rows[$i];
- $last= $rows[$i-1];
-// echo $startTime;
-// print_r($now);
- if($startTime == -1){
-// echo "no start
";
- if($now['heatSetPoint'] <> $last['heatSetPoint']){
- //Down!
-// echo "down
";
- $startTime = $now['date'];
- $startTemp = $now['dispTemperature'];
- $startSetPoint = $last['heatSetPoint'];
- $targetSetPoint = $now['heatSetPoint'];
- if($now['heatSetPoint'] > $last['heatSetPoint']){
- $type = "up";
- } else {
- $type = "down";
- }
- }
- } else{
- //looking for end
-// echo "yes start
";
- if($now['dispTemperature'] == $targetSetPoint || $now['heatSetPoint'] <> $targetSetPoint){
- $changeTime = ($now['date']-$startTime)/60;
- $changeTemp = abs($startTemp - $now['dispTemperature']);
- $outside = $now['weatherTemperature'];
- $minperdeg = $changeTime/$changeTemp;
-
- if($type == "up"){
- $heat_up[] = [$minperdeg,intval($outside)];
- } else{
- $heat_down[] = [$minperdeg,intval($outside)];
- }
+ if(in_array(THERMOSTAT_TYPE,$valid_thermostats)){
+ require('thermostats/'.THERMOSTAT_TYPE.'/scrape.php');
+ require('thermostats/'.THERMOSTAT_TYPE.'/logininfo.php');
+ } else{
+ die("Invalid THERMOSTAT_TYPE set in settings/globals.php");
+ }
+
+ $id = $_GET['id']; // device ID
+
+?>
+
+ Stat delay
+
+
+
+
+
+
+
+
+
-$conn->close();
+
+
+
+
+
-?>
\ No newline at end of file
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/getdata.php b/getdata.php
new file mode 100644
index 0000000..fe25149
--- /dev/null
+++ b/getdata.php
@@ -0,0 +1,57 @@
+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();
+
+ }
+}
+
+?>
\ No newline at end of file
diff --git a/graph.html b/graph.php
similarity index 73%
rename from graph.html
rename to graph.php
index bb7c1bf..e317f13 100644
--- a/graph.html
+++ b/graph.php
@@ -1,106 +1,111 @@
-
-
-
- Stat tracker
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+ Household Temperature Tracker
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/index.html b/index.html
deleted file mode 100644
index 52a4ae8..0000000
--- a/index.html
+++ /dev/null
@@ -1,50 +0,0 @@
-
-
-
-
-
-
-
- Stat stat
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..756eab7
--- /dev/null
+++ b/index.php
@@ -0,0 +1,3 @@
+
\ No newline at end of file
diff --git a/navbar.php b/navbar.php
new file mode 100644
index 0000000..99d5953
--- /dev/null
+++ b/navbar.php
@@ -0,0 +1,48 @@
+
+
+
\ No newline at end of file
diff --git a/settings/globals.php.example b/settings/globals.php.example
index d902a5a..595d582 100644
--- a/settings/globals.php.example
+++ b/settings/globals.php.example
@@ -1,9 +1,11 @@
\ No newline at end of file
diff --git a/thermostats/honeywell/logininfo.php.example b/thermostats/honeywell/logininfo.php.example
index ad772d3..50a02a2 100644
--- a/thermostats/honeywell/logininfo.php.example
+++ b/thermostats/honeywell/logininfo.php.example
@@ -1,6 +1,12 @@
\ No newline at end of file
diff --git a/thermostats/honeywell/scrape.php b/thermostats/honeywell/scrape.php
index 026cbd2..6678216 100644
--- a/thermostats/honeywell/scrape.php
+++ b/thermostats/honeywell/scrape.php
@@ -1,6 +1,6 @@
real_escape_string($clean_data['weatherPhrase']);
- $columns = implode(", ",array_keys($clean_data));
- $values = implode(", ", array_values($clean_data));
-
- $sql = "INSERT INTO `stat`(".$columns.") VALUES (".$values.")";
- $result = $conn->query($sql);
- echo $sql;
- echo "\n";
- echo $result;
- if (!$result) {
- printf("Errormessage: %s\n", $conn->error);
-}
-
- $conn->close();
-
-}
-function getCurrentInfo(){
- require_once('logininfo.php');
+Function enumerate_thermostats(){ // counts number of thermostats in array. Could probably move somewhere else
+ require('logininfo.php');
+ $count = count($device_array);
+ return $count;
+}
+
+function getCurrentInfo($d){ // gets the current info for the thermostat with the id $d
+
+ require('logininfo.php');
login($username, $password);
- $data = getStatus($device_number);
-
+ $data = getStatus($device_array[$d]);
+
return $data;
}
-
?>
\ No newline at end of file