forked from jmonclard/MopScreens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaj_refreshradioinfo.php
executable file
·84 lines (76 loc) · 2.25 KB
/
aj_refreshradioinfo.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
<?php
session_start();
date_default_timezone_set('Europe/Paris');
include_once('functions.php');
include_once('lang.php');
redirectSwitchUsers();
include_once('config.php');
$_SESSION['CurrentLanguage'] = isset($_SESSION['CurrentLanguage']) ? $_SESSION['CurrentLanguage'] : autoSelectLanguage(array('fr','en','sv'),'en');
$PHP_SELF = $_SERVER['PHP_SELF'];
$link = ConnectToDB();
$sql = 'SELECT * FROM (SELECT * FROM resultradio ORDER BY timestamp DESC) x GROUP BY idsender';
$res = mysqli_query($link, $sql);
$now = time();
//echo 'id, battery, age'.'<br />';
$batteryInfo = array();
while ($r = mysqli_fetch_array($res))
{
//echo $r['idsender'].', '.$r['senderbattery'].', '.($now - strtotime($r['timestamp'])).'<br/>';
$batteryInfo[] = '['.$r['idsender'].', '.$r['senderbattery'].', '.($now - strtotime($r['timestamp'])).', '.$r['status'].']';
}
//echo '<hr />';
$sql = 'SELECT * FROM (SELECT * FROM resultradio ORDER BY timestamp DESC) x GROUP BY idsender, idreceiver';
$res = mysqli_query($link, $sql);
$now = time();
//echo 'sender id, receiver id, rx level, age'.'<br />';
$levelsInfo = array();
while ($r = mysqli_fetch_array($res))
{
//echo $r['idsender'].', '.$r['idreceiver'].', '.$r['rxlevel'].', '.($now - strtotime($r['timestamp'])).'<br/>';
$levelsInfo[] = '['.$r['idsender'].', '.$r['idreceiver'].', '.$r['rxlevel'].', '.($now - strtotime($r['timestamp'])).']';
}
$output = '';
if($batteryInfo != null)
{
$output = '['.implode(', ', $batteryInfo).']';
}
else
{
$output = '[]';
}
if($levelsInfo != null)
{
$output = '['.$output.', ['.implode(', ', $levelsInfo).']'.'];';
}
else
{
$output = '['.$output.', []'.'];';
}
echo $output;
/*
var batteryInfo = // id, battery, age
[
[0, 1000, 381],
[1, 1001, 381],
[2, 1002, 381],
[3, 1003, 381],
[4, 1004, 381],
[5, 1005, 381],
[6, 1006, 381],
[7, 1007, 381]
];
// var levelsInfo = [];
var levelsInfo = //senderid, receiverid, rxlevel, age
[
[0, 1, -100, 20],
[1, 2, -99, 20],
[1, 5, -20, 80],
[2, 3, -98, 30],
[3, 4, -97, 20],
[3, 5, -60, 45],
[4, 5, -96, 5],
[5, 6, -95, 1],
[6, 7, -94, 666]
];
var totalInfo = [batteryInfo, levelsInfo];
*/