diff --git a/public/temp.php b/public/temp.php deleted file mode 100644 index eefe212..0000000 --- a/public/temp.php +++ /dev/null @@ -1,442 +0,0 @@ - PDO::CASE_NATURAL, - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, - PDO::ATTR_STRINGIFY_FETCHES => false, - PDO::ATTR_EMULATE_PREPARES => false, - PDO::MYSQL_ATTR_INIT_COMMAND => " - SET SESSION - sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION', - time_zone = '+00:00'; - ", - ]); -} catch(Exception $ex) { - http_response_code(500); - echo '

Unable to connect to database

'; - die($ex->getMessage()); -} - -if(isset($_POST['temp']) && isset($_POST['hash']) && isset($_POST['time'])) { - $temp = (string)filter_input(INPUT_POST, 'temp'); - $hash = (string)filter_input(INPUT_POST, 'hash'); - $time = (string)filter_input(INPUT_POST, 'time', FILTER_SANITIZE_NUMBER_INT); - - if(!hash_equals(hash_hmac('sha256', $temp . '|' . $time, FM_TEMP_KEY), $hash)) - return; - - $time = floor((int)json_decode($time) / FM_TEMP_INT); - if($time !== floor(time() / FM_TEMP_INT)) - return; - - $insert = $pdo->prepare('INSERT INTO `fm_temperature` (`temp_celcius`) VALUES (:temp)'); - $insert->bindValue('temp', (string)json_decode($temp)); - $insert->execute(); - return; -} - -if(isset($_GET['latest'])) { - $temps = $pdo->prepare('SELECT `temp_celcius` AS `tc`, UNIX_TIMESTAMP(`temp_datetime`) AS `dt` FROM `fm_temperature` ORDER BY `temp_datetime` DESC LIMIT 1'); - $temps->execute(); - header('Content-Type: application/json; charset=utf-8'); - echo json_encode($temps->fetch(PDO::FETCH_ASSOC)); - return; -} - -if(isset($_GET['daily'])) { - $temps = $pdo->prepare('SELECT AVG(`temp_celcius`) AS `tc`, DATE_FORMAT(MIN(`temp_datetime`), \'%H:%i\') AS `ts` FROM `fm_temperature` WHERE `temp_datetime` > NOW() - INTERVAL 1 DAY GROUP BY FLOOR(UNIX_TIMESTAMP(`temp_datetime`) / (15 * 60)) ORDER BY `temp_datetime` ASC LIMIT 96'); - $temps->execute(); - header('Content-Type: application/json; charset=utf-8'); - echo json_encode($temps->fetchAll(PDO::FETCH_ASSOC)); - return; -} - -if(isset($_GET['weekly'])) { - $temps = $pdo->prepare('SELECT MAX(`temp_celcius`) AS `tcmax`, AVG(`temp_celcius`) AS `tcavg`, MIN(`temp_celcius`) AS `tcmin`, DATE_FORMAT(`temp_datetime`, \'%X-%V\') AS `tw` FROM `fm_temperature` WHERE `temp_datetime` > NOW() - INTERVAL 1 YEAR GROUP BY YEARWEEK(`temp_datetime`) ORDER BY `temp_datetime` ASC LIMIT 52'); - $temps->execute(); - header('Content-Type: application/json; charset=utf-8'); - echo json_encode($temps->fetchAll(PDO::FETCH_ASSOC)); - return; -} - -if(!empty($_GET['siri'])) { - header('Content-Type: text/plain; charset=utf-8'); - $temps = $pdo->prepare('SELECT `temp_celcius`, UNIX_TIMESTAMP(`temp_datetime`) AS `temp_datetime` FROM `fm_temperature` ORDER BY `temp_datetime` DESC LIMIT 1'); - $temps->execute(); - $temps = $temps->fetch(PDO::FETCH_ASSOC); - date_default_timezone_set('Europe/Amsterdam'); - printf('It was %2$.1f°C at %1$s.', date('H:i:s', $temps['temp_datetime']), $temps['temp_celcius']); - return; -} -?> - - - - - Room Temperature - - - - - -
-
-
- -- °C -
-
- --:--:-- -
-
-
-

15 minutely Temperature (24hr)

-

Add 1 or 2 hours to the displayed hour, I cannot be bothered to handle it myself.

-
-
-
-
-
-
-

Weekly Temperature (1yr)

-
-
-
-
Maximum
-
-
-
-
Average
-
-
-
-
Minimum
-
-
-
-
-
-
-
-
- - - \ No newline at end of file diff --git a/public/temp2.php b/public/temp2.php deleted file mode 100644 index 1c43181..0000000 --- a/public/temp2.php +++ /dev/null @@ -1,331 +0,0 @@ - PDO::CASE_NATURAL, - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, - PDO::ATTR_STRINGIFY_FETCHES => false, - PDO::ATTR_EMULATE_PREPARES => false, - PDO::MYSQL_ATTR_INIT_COMMAND => " - SET SESSION - sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION', - time_zone = '+00:00'; - ", - ]); -} catch(Exception $ex) { - http_response_code(500); - echo '

Unable to connect to database

'; - die($ex->getMessage()); -} - -if(isset($_POST['temp']) && isset($_POST['hash']) && isset($_POST['time'])) { - $temp = (string)filter_input(INPUT_POST, 'temp'); - $hash = (string)filter_input(INPUT_POST, 'hash'); - $time = (string)filter_input(INPUT_POST, 'time', FILTER_SANITIZE_NUMBER_INT); - - if(!hash_equals(hash_hmac('sha256', $temp . '|' . $time, FM_TEMP_KEY), $hash)) - return; - - $time = floor((int)json_decode($time) / FM_TEMP_INT); - if($time !== floor(time() / FM_TEMP_INT)) - return; - - $insert = $pdo->prepare('INSERT INTO `fm_temperature` (`temp_celcius`) VALUES (:temp)'); - $insert->bindValue('temp', (string)json_decode($temp)); - $insert->execute(); - return; -} - -if(isset($_GET['since'])) { - $since = (int)filter_input(INPUT_GET, 'since', FILTER_SANITIZE_NUMBER_INT); - $temps = $pdo->prepare('SELECT `temp_celcius`, UNIX_TIMESTAMP(`temp_datetime`) AS `temp_datetime` FROM `fm_temperature` WHERE `temp_datetime` > FROM_UNIXTIME(:since) AND `temp_datetime` > NOW() - INTERVAL 1 DAY ORDER BY `temp_datetime` ASC LIMIT 288'); - $temps->bindValue('since', $since); - $temps->execute(); - header('Content-Type: application/json; charset=utf-8'); - echo json_encode($temps->fetchAll(PDO::FETCH_ASSOC)); - return; -} - -if(isset($_GET['since_3mo'])) { - $since = (int)filter_input(INPUT_GET, 'since_3mo', FILTER_SANITIZE_NUMBER_INT); - $temps = $pdo->prepare('SELECT MAX(`temp_celcius`) AS `temp_celcius_max`, AVG(`temp_celcius`) AS `temp_celcius_avg`, MIN(`temp_celcius`) AS `temp_celcius_min`, UNIX_TIMESTAMP(DATE(`temp_datetime`)) AS `temp_datetime` FROM `fm_temperature` WHERE `temp_datetime` > DATE(FROM_UNIXTIME(:since)) AND `temp_datetime` > NOW() - INTERVAL 3 MONTH GROUP BY DATE(`temp_datetime`) ORDER BY `temp_datetime` ASC LIMIT 92'); - $temps->bindValue('since', $since); - $temps->execute(); - header('Content-Type: application/json; charset=utf-8'); - echo json_encode($temps->fetchAll(PDO::FETCH_ASSOC)); - return; -} - -if(isset($_GET['since_6mo'])) { - $since = (int)filter_input(INPUT_GET, 'since_6mo', FILTER_SANITIZE_NUMBER_INT); - $temps = $pdo->prepare('SELECT MAX(`temp_celcius`) AS `temp_celcius_max`, AVG(`temp_celcius`) AS `temp_celcius_avg`, MIN(`temp_celcius`) AS `temp_celcius_min`, UNIX_TIMESTAMP(DATE(`temp_datetime`)) AS `temp_datetime` FROM `fm_temperature` WHERE `temp_datetime` > DATE(FROM_UNIXTIME(:since)) AND `temp_datetime` > NOW() - INTERVAL 6 MONTH GROUP BY DATE(`temp_datetime`) ORDER BY `temp_datetime` ASC LIMIT 92'); - $temps->bindValue('since', $since); - $temps->execute(); - header('Content-Type: application/json; charset=utf-8'); - echo json_encode($temps->fetchAll(PDO::FETCH_ASSOC)); - return; -} - -if(!empty($_GET['siri'])) { - header('Content-Type: text/plain; charset=utf-8'); - $temps = $pdo->prepare('SELECT `temp_celcius`, UNIX_TIMESTAMP(`temp_datetime`) AS `temp_datetime` FROM `fm_temperature` ORDER BY `temp_datetime` DESC LIMIT 1'); - $temps->execute(); - $temps = $temps->fetch(PDO::FETCH_ASSOC); - date_default_timezone_set('Europe/Amsterdam'); - printf('It was %2$.1f°C at %1$s.', date('H:i:s', $temps['temp_datetime']), $temps['temp_celcius']); - return; -} -?> - - - - - Room Temperature - - - - - -
-
-
- -- °C -
-
- --:--:-- -
-
-
- -
-
- -
-
- - - -