-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_data_head.php
112 lines (103 loc) · 3.04 KB
/
get_data_head.php
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
105
106
107
108
109
110
111
112
<?php
// Konfiguration einbinden
require_once("airq.inc.php");
function decrypt($msgb64,$password)
{
$airqpass = $password;
if (strlen($airqpass) < 32) {
for ($i = strlen($airqpass); $i < 32; $i++) {
$airqpass = $airqpass . '0';
}
} else {
if (strlen($airqpass) > 32) {
$airqpass = substr($airqpass,0,32);
}
}
$key = utf8_encode ($airqpass);
// $cyphertext = base64_decode ($msgb64);
// But with verly long messages there could be some problems in base64_decode
$decoded = "";
for ($i=0; $i < ceil(strlen($msgb64)/256); $i++)
$decoded = $decoded . base64_decode(substr($msgb64,$i*256,256));
$cyphertext = $decoded;
$iv = substr($cyphertext,0,16);
$cyphertext = substr($cyphertext,16,strlen($cyphertext));
// With php version <= 7.1 you can use the following, but this is deleted in version 7.2 and above
// $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $cyphertext, MCRYPT_MODE_CBC, $iv);
$decrypted = openssl_decrypt($cyphertext, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
return utf8_encode($decrypted);
}
// Possible comands: ping, config, data, log, dirbuff, file&request=..
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = "";
$url = $airq . '/data';
curl_setopt($ch, CURLOPT_URL, $url);
$output = curl_exec($ch);
$json = json_decode($output, true);
$output = decrypt($json["content"],$password);
$arrdata = json_decode($output, TRUE);
$fd = fopen("data.csv","w");
$lg = fopen("data_log.csv";"w");
$zeile = "\n";
$head = "\n";
$loger = "Script_run;measuretime;timestamp;\n".date("d.m.Y H:i:s").";";
foreach($arrdata as $key => $value) {
switch ($key) {
case "cnt0_3":
case "cnt0_5":
case "cnt1":
case "cnt10":
case "cnt2_5":
case "cnt5":
case "co":
case "co2":
case "dewpt":
case "h2s":
case "humidity":
case "humidity_abs":
case "no2":
case "o3":
case "oxygen":
case "pm1":
case "pm10":
case "pm2_5":
case "pressure":
case "pressure_rel":
case "sound":
case "sound_max":
case "temperature":
case "tvoc":
case "virus":
$zeile .= $value[0].";".$value[1].";";
$head .= $key."_value;".$key."_abw;";
break;
case "dCO2dt":
case "DeviceID":
case "dHdt":
case "health":
//case "measuretime":
case "performance":
case "Status":
//case "timestamp":
case "TypPS":
case "uptime":
$zeile .= $value.";";
$head .= $key."_value;";
break;
case "measuretime":
case "timestamp":
$zeile .= $value.";";
$loger .= $value.";";
$head .= $key."_value;";
break;
}
}
fwrite($fd,$head);
fwrite($fd,$zeile);
fwrite($lg,$loger);
fclose($fd);
fclose($lg);
print_r($head);
print_r($zeile);
?>