forked from ph2lb/LoRaWAN_TTN_Env
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ttnlora_env_payloaddata.php
83 lines (67 loc) · 1.47 KB
/
ttnlora_env_payloaddata.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
<?php
// DEZE MOET JE FF AANPASSEN
include './ttnlora_env_vars.php';
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$filter_id = NULL;
$filter_from = NULL;
$filter_to = NULL;
if (isset($_GET["id"]))
{
$filter_id = $_GET["id"];
$filter_id = $conn->real_escape_string($filter_id);
}
if (isset($_GET["to"]))
{
$filter_to = $_GET["to"];
$filter_to = $conn->real_escape_string($filter_to);
}
else
{
$filter_to = new DateTime();
$filter_to = $filter_to->format("Y-m-d H:i:s");
}
if (isset($_GET["from"]))
{
$filter_from = $_GET["from"];
$filter_from = $conn->real_escape_string($filter_from);
}
else
{
$dt = new DateTime();
$dt->modify("-1 day");
$filter_from = $dt;
$filter_from = $filter_from->format("Y-m-d H:i:s");
}
// debug
//echo "// $filter_id \n";
//echo "// $filter_from \n";
//echo "// $filter_to \n";
echo "[\n";
$first = true;
$sql = "SELECT Raw FROM Measurement WHERE DevID = '$filter_id' AND TimeStampUTC >= '$filter_from' AND TimeSTampUTC <= '$filter_to'";
$result = $conn->query($sql);
if (!$result) {
echo 'Invalid query: ' . $conn->error;
}
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc())
{
if (!$first)
{
echo ",\n";
}
$first = false;
$raw = $row["Raw"];
echo $raw;
echo "\n";
}
}
echo "\n]\n";
$conn->close();
?>