-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStoreLogValues.php
More file actions
48 lines (35 loc) · 1.84 KB
/
Copy pathStoreLogValues.php
File metadata and controls
48 lines (35 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
include "StoreLogValues_Config.php";
$timestamp = time();
$temp = ""; // Values should be -200 ... +1000 (divide by 10!)
$hum = ""; // Values should be 0 ... 1000 (divide by 10!)
$sensorID = ""; // ID should be 0...99
$vcc = ""; // Raw value of ADC, unit is 1/1024 Volt, int
if(isset($_GET["temp"])) { $temp = $_GET["temp"]; } else { $temp = "--"; }
if(isset($_GET["hum"] )) { $hum = $_GET["hum"]; } else { $hum = "--"; }
if(isset($_GET["vcc"] )) { $vcc = $_GET["vcc"]; } else { $vcc = "--"; }
// Verify range and format of temperature, huminity and vcc
if(preg_match("/^[0-9]{1,3}.[0-9]{1,2}+$/", $temp) != 1) { echo "Invalid Temp Value!"; exit(); }
if(preg_match("/^[0-9]{1,3}.[0-9]{1,2}+$/", $hum ) != 1) { echo "Invalid Hum Value!" ; exit(); }
if(preg_match("/^[0-9]{1,5}$/" , $vcc ) != 1) { echo "Invalid Vcc Value!" ; exit(); }
// Regexp for Sensor ([0..9]+) - Not yet implemented
// a simple log for now
$logfile = fopen("/home/stefan/www/webroot/temp.heinrichsen.net/temp_log.txt","a");
fwrite($logfile, date("Y-m-d H-i-s") . ";$timestamp;$temp;$hum;$vcc;\n");
fclose($logfile);
// Check battery value and send mail in case of empty/weak battery
if($vcc<3000) {
mail($mail, "Battery low on Temp-Logger", "Hi Admin,\n\nit seems the battery on your TempLogger device is weak. Current voltage is " . number_format(($vcc/1024/3), 2) . " V for each battery. This should be considered as emtpy battery.\n\nBest regards,\n Your receiving script.\n");
}
// store values to Int (store as tens of a degree 20,5C -> 205)
// store values to Int (store as tens of percentage 65,3% -> 653)
// Authenticate check via hash over values and hash_key
//
//ToDo (Use SHA-256? Check for Arduino-Code first!
// Store into Database
//
// Store sessorID, timestamp, temp, hum,
// Check for errors and create a mail in case of issues
//
echo "OK"
?>