-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsert.php
More file actions
104 lines (89 loc) · 3.32 KB
/
insert.php
File metadata and controls
104 lines (89 loc) · 3.32 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<html>
<head>
<title>insert weather data</title>
</head>
<body>
<?php
include "include/config.php";
include "include/database_functions.php";
include "include/functions.php";
include "include/date_functions.php";
$rawdata = file_get_contents($clientrawUrl);
//echo $rawdata . '<br/>';
$data = explode(" ", $rawdata);
//echo $data . '<br/>';
$hour = (int) $data[29];
$minute = (int) $data[30];
$second = (int) $data[31];
$day = (int) $data[35];
$month = (int) $data[36];
// echo 'weatherstation timestamp is ' . $day . '.' . $month . ' ' . $hour . ':' . $minute . ':' .$seconds . '<br/>';
$windspeed = (float) $data[1];
$windspeedRecorded = (int) ($windspeed * 10);
$windspeedGusts = (float) $data[2];
$windspeedGustsRecorded = (int) ($windspeedGusts * 10);
$winddirection = (int) $data[3];
$temperature = (float) $data[4];
$temperatureRecorded = (int) (($temperature * 10) + 1000);
$waterTemperature = (float) $data[20];
$waterTemperatureRecorded = (int) (($waterTemperature * 10) + 1000);
$humidity = (float) $data[5];
$pressure = (float) $data[6];
$pressureRecorded = (int) ($pressure * 10);
$rainRate = (float) $data[10];
$rainRateRecorded = (int) ($rainRate * 1000);
$yearlyRain = (float) $data[9];
$yearlyRainRecorded = (int) ($yearlyRain * 10);
//echo '<br/>durchschnittliche windgeschwindigkeit*10 in knoten: ' . $windspeedRecorded . '<br/>';
//echo 'windgeschwindigkeit boen*10 in knoten: ' . $windspeedGustsRecorded . '<br/>';
//echo 'windrichtung in Grad:' . $winddirection . '<br/>';
//echo '(Temperatur*10)+1000 in Grad Celsius: ' . $temperatureRecorded . '<br/>';
//echo '(Wassertemperatur*10)+1000 in Grad Celsius: ' . $waterTemperatureRecorded . '<br/>';
//echo 'Feuchtigkeit in %: ' . $humidity . '<br/>';
//echo 'Luftruck*10 in hPa: ' . $pressureRecorded . '<br/>';
if ($temperatureRecorded == 1000
|| $waterTemperatureRecorded == 1000
|| $pressureRecorded == 0)
{
echo 'no data<br/>';
exit;
}
$conn = getDatabaseConnection($dbServer, $dbUser, $dbPassword, $dbName);
lock($conn, "insert");
echo '<br/>';
$databaseTime = retrieveDateFromDb("SELECT NOW() as now", "now", $conn, "database time");
$windData = array(
"speed" => $windspeedRecorded,
"gusts" => $windspeedGustsRecorded,
"direction" => $winddirection);
storeWhenThresholdIsReached("wind", $windData, $windStoreIntervalSeconds, $databaseTime, $conn);
$temperatureData = array(
"temperature" => $temperatureRecorded,
"humidity" => $humidity,
"water_temperature" => $waterTemperatureRecorded,
);
storeWhenThresholdIsReached("temperature", $temperatureData, $temperatureStoreIntervalSeconds, $databaseTime, $conn);
$pressureData = array(
"pressure" => $pressureRecorded);
storeWhenThresholdIsReached("pressure", $pressureData, $pressureStoreIntervalSeconds, $databaseTime, $conn);
$rainData = array(
"rate" => $rainRateRecorded,
"yearly" => $yearlyRainRecorded);
storeWhenThresholdIsReached("rain", $rainData, $rainStoreIntervalSeconds, $databaseTime, $conn);
$timeData = array(
"hour" => $hour,
"minute" => $minute,
"second" => $second,
"day" => $day,
"month" => $month);
storeWhenThresholdIsReached("time", $timeData, $timeStoreIntervalSeconds, $databaseTime, $conn);
$hour = (int) $data[29];
$minute = (int) $data[20];
$second = (int) $data[31];
$day = (int) $data[35];
$month = (int) $data[36];
unlock($conn, "insert");
$conn->close();
?>
</body>
</html>