This repository has been archived by the owner on Jul 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
power.php
54 lines (41 loc) · 1.63 KB
/
power.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
<?php header('Content-Type: application/json;charset=UTF-8');
$servername = "localhost";
$username = "fagprojekt";
$password = "gf3qAdOPH1l9YtSp";
$dbname = "fagprojekt";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo $_GET["callback"];
if ($_GET["type"] != "MATLAB") echo "(
[
";
$sql = "SELECT `topic`, SUM(`value`) AS `value`, order_time FROM ( SELECT `topic`, AVG(`value`) AS `value`, DATE_FORMAT(FROM_UNIXTIME(`timestamp`), '%Y-%m-%d %H:%i:00') AS order_time FROM `data` WHERE `topic` = 7 GROUP BY order_time, device) AS A GROUP BY order_time ORDER BY `A`.`order_time` ASC;";
$result = $conn->query($sql);
$started = false;
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if ($started && $_GET["type"] != "MATLAB") { echo ",
";}
elseif ($started) echo"\n";
if ($_GET["type"] != "MATLAB") echo "[";
// echo $row["timestamp"]*1000;
echo strtotime($row["order_time"]);
if ($_GET["type"] != "MATLAB") echo ",";
else echo " ";
if ($row["topic"] == 6) echo $row["value"]/100; //temp
elseif ($row["topic"] == 1) echo $row["value"]/10; //voltage
elseif ($row["topic"] == 2) echo $row["value"]/1000; //current
elseif ($row["topic"] == 4) echo ($row["value"]-1)/10000; //light
else echo $row["value"];
if ($_GET["type"] != "MATLAB") echo "]";
$started = true;
}
} else {
//echo "error";
}
if ($_GET["type"] != "MATLAB") echo "
]);";
$conn->close();
?>