????JFIF??x?x????'
| Server IP : 79.136.114.73 / Your IP : 216.73.216.55 Web Server : Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.29 OpenSSL/1.0.1f System : Linux b8009 3.13.0-170-generic #220-Ubuntu SMP Thu May 9 12:40:49 UTC 2019 x86_64 User : www-data ( 33) PHP Version : 5.5.9-1ubuntu4.29 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/appsrv.astacus.se/shellyctr/ |
Upload File : |
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$mysqli = new mysqli("www.astacus.se", "carlhoffstedt", "Astacus2020!", "ShellyCTR");
$from = date("Y-m-d",strtotime("-2 days"))." 00:00:00";
$to = date("Y-m-d H:00:00");
$Username = "carl.hoffstedt@astacus.se";
$sql = "SELECT * FROM tblOhmigoUnits WHERE Username = '".$Username."'";
$result = $mysqli->query($sql);
$Controltype = 1;
while($obj = $result->fetch_object()){
$Controltype = $obj->Controltype;
}
$sql = "SELECT * FROM tblShellyUnits, tblShellyConnections WHERE tblShellyUnits.ShellyConnectionId = tblShellyConnections.id and tblShellyConnections.Username = '".$Username."' and tblShellyUnits.Type = 'Temp'";
$result = $mysqli->query($sql);
$temp_arr1 = array();
$temp_arr2 = array();
$temp_arr3 = array();
$temp_arr4 = array();
$temp_arr5 = array();
while($obj = $result->fetch_object()){
$sql = "SELECT * FROM tblShellyTemperature WHERE Username = '".$Username."' and DeviceId = '".$obj->DeviceId."' and Timestamp >= '". $from."' and Timestamp <= '". $to."' order by Timestamp asc";
echo($sql);
$result2 = $mysqli->query($sql);
while($obj2 = $result2->fetch_object()){
$temp1_arr[] = $obj2->Timestamp;
$temp2_arr[] = $obj2->tC;
$temp3_arr[] = $obj2->t_effective;
$temp5_arr[] = $obj2->t;
$temp4_arr[] = $obj2->control_temp;
}
}
$sql = "SELECT * FROM tblWeatherControl WHERE Username = '".$Username."' and Timestamp >= '". $from."' and Timestamp <= '". $to."' and Controltype = $Controltype order by Timestamp asc";
$result = $mysqli->query($sql);
$ExpensiveCount = 1;
$Expensive = "";
$Save = "";
while($obj = $result->fetch_object()){
if($obj->Expensive != $Expensive && $Expensive != ""){
$key = array_search($obj->Timestamp, $temp1_arr)-1;
$End = $temp2_arr[$key];
if($key > 1){
//echo("<br>Search in temp1_array for: ".$obj->Timestamp." found it att key :".$key." value (END): ". $End ."<br>");
$ExpensiveCount = $ExpensiveCount -1;
echo("<br>Starttemp: ".$Save[1]." (".$Save[0].") Sluttemp: ".$End." (".$obj->Timestamp.") DIFF (".$ExpensiveCount."): ".($Save[1]-$End). " ".(($Save[1]-$End)/$ExpensiveCount )."<br><br>");
$sql = "SELECT * FROM tblDIFF WHERE Username = '".$Username."' and End = '$obj->Timestamp'";
$result2 = $mysqli->query($sql);
$found = false;
while($obj2 = $result2->fetch_object()){
$found = true;
}
if($found == false && (($Save[1]-$End)/$ExpensiveCount) > 0 ){
$sql = "INSERT INTO tblDIFF VALUES (null,'".date("Y-m-d H:i:s",strtotime("-$ExpensiveCount hours",strtotime($obj->Timestamp)))."','".$obj->Timestamp."','".$Save[1]."','".$End."','".($Save[1]-$End)."','".($Save[1]-$End)/$ExpensiveCount."','".(($temp3_arr[$key]+$temp5_arr[$key])/2)."','".$ExpensiveCount."','".$Username."')";
echo($sql);
$mysqli->query($sql);
}
}
}
if($obj->Expensive != "EXPENSIVE"){
$key = array_search($obj->Timestamp, $temp1_arr);
$Save = array($obj->Timestamp,$temp2_arr[$key]);
$ExpensiveCount = 1;
}
$key = array_search($obj->Timestamp, $temp1_arr);
$VV = 0;
if($key != 0){
$VV = $temp2_arr[$key];
}
echo("TIMESTAMP: ".$obj->Timestamp. " \t ".$obj->Value. " \t". $obj->Expensive." \t Innetemp: " .$VV."<br>");
$Expensive = $obj->Expensive;
$Timestamp = $obj->Timestamp;
$Value = $obj->Value;
if($Expensive == "EXPENSIVE" ){
$ExpensiveCount++;
}
}
?>