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/cron.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

51 lines
1.7 KiB
PHP

<?php
include('settings/globals.php');
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");
}
// dorfl added simple loop
for ($i = 0; $i <enumerate_thermostats(); $i++) { // all thermostats
$data = getCurrentInfo($i); // changed info!
$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);
}
} // end for thermostats
$conn->close();
?>