-
Notifications
You must be signed in to change notification settings - Fork 0
/
converter-helium-chirpstack.php
75 lines (62 loc) · 1.99 KB
/
converter-helium-chirpstack.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
<?php
function map($value, $fromLow, $fromHigh, $toLow, $toHigh) {
$fromRange = $fromHigh - $fromLow;
$toRange = $toHigh - $toLow;
$scaleFactor = $toRange / $fromRange;
// Re-zero the value within the from range
$tmpValue = $value - $fromLow;
// Rescale the value to the to range
$tmpValue *= $scaleFactor;
// Re-zero back to the to range
return $tmpValue + $toLow;
}
$json = file_get_contents('php://input');
$helium = json_decode($json, true);
$url = 'http://127.0.0.1:5055/?id='.$helium["deviceInfo"]["deviceName"];
$url .='&lat='.$helium["object"]["latitude"];
$url .='&lon='.$helium["object"]["longitude"];
$url .='&rssi='.$helium["rxInfo"][0]["rssi"];
$url .='&hotspot='.$helium["rxInfo"][0]["metadata"]["gateway_name"];
if (isset($helium["object"]["BatV"])) {
$battery = $helium["object"]["BatV"];
$url .='&akkuspannung='.$battery;
$battery = map($battery, 2.9, 4.0, 0, 100);
$battery = round($battery, 0);
$url .='&batt='.$battery;
}
if (isset($helium["object"]["battery"])) {
$battery = $helium["object"]["battery"];
$url .='&akkuspannung='.$battery;
$battery = map($battery, 2.9, 3.6, 0, 100);
$battery = round($battery, 0);
$url .='&batt='.$battery;
}
if (isset($helium["object"]["accuracy"])) {
$url .='&accuracy='.$helium["object"]["accuracy"];
}
if (isset($helium["object"]["temperature"])) {
$url .='&temperature='.$helium["object"]["temperature"];
}
if (isset($helium["object"]["gnssFix"])) {
$gnssFix = var_export($helium["object"]["gnssFix"], true);
$url .='&valid='.$gnssFix;
}
$ctx = stream_context_create(array('http'=>
array(
'timeout' => 3, //1200 Seconds is 20 Minutes
)
));
$response = file_get_contents($url, false, $ctx);
if ($response === false) {
$error = error_get_last();
if ($error['type'] === E_WARNING) {
// nope
} else {
// nope
}
}
header("Content-Type: application/json; charset=utf-8");
http_response_code(200);
print($url . ",success");
return;
?>