Last active
October 28, 2021 18:14
-
-
Save Radiotechniman/c595f0221630979dd6742910eddad502 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); | |
header("Cache-Control: post-check=0, pre-check=0", false); | |
header("Pragma: no-cache"); | |
//Your timezone | |
date_default_timezone_set("Europe/Amsterdam") ; | |
//IP Address of Homey, make sure it has a fixed address | |
$homey_ip = "192.168.1.6" ; | |
//Would you like to see the newest entries on top? true/false | |
// does not work properly yet | |
$newest_first = true ; | |
// ----------------------------- | |
$url = "http://".$homey_ip."/api/app/nl.nielsdeklerk.log/" ; | |
$json = file_get_contents($url) ; | |
$data = json_decode($json, true) ; | |
if($newest==true){ | |
$data = array_reverse($data) ; | |
} | |
$i =0; | |
$cat = [] ; | |
$out = ""; | |
if(isset($_GET['d'])){ | |
$day = $_GET['d'] ; | |
} | |
else{ | |
$day="-" ; | |
} | |
while($i<count($data)){ | |
$date = strtotime($data[$i]["date"]); | |
$group = $data[$i]["group"]; | |
$log = $data[$i]["data"]; | |
$cat[] = $group ; | |
$dateInLocal = date("Y-m-d H:i:s", $date); | |
$dateInLocal = explode(" ",$dateInLocal) ; | |
if(!isset($_GET['group'])){ | |
$out .= "<tr>" ; | |
$out .= "<td>".$i."</td>" ; | |
$out .= "<td>".$dateInLocal[0]."</td>" ; | |
$out .= "<td>".$dateInLocal[1]."</td>" ; | |
$out .= '<td><a href="log2.php?group='.$group.'">'.$group.'</a></td>' ; | |
$out .= "<td>".$log."</td>" ; | |
$out .= "</tr>" ; | |
} | |
else if(isset($_GET['group'])){ | |
if($group==$_GET['group']){ | |
$out .= "<tr>" ; | |
$out .= "<td>".$i."</td>" ; | |
$out .= "<td>".$dateInLocal[0]."</td>" ; | |
$out .= "<td>".$dateInLocal[1]."</td>" ; | |
$out .= '<td><a href="log2.php?group='.$group.'">'.$group.'</a></td>' ; | |
$out .= "<td>".$log."</td>" ; | |
$out .= "</tr>" ; | |
} | |
} | |
$i++ ; | |
} | |
$link = '<a href=http://192.168.1.20/homey/log/log2.php>All</a>' ; | |
$newcat = array_unique($cat); | |
$newcat = array_values($newcat) ; | |
for($x=0;$x<count($newcat);$x++){ | |
$tmp = $newcat[$x] ; | |
if($tmp!=""){ | |
$link .= ' - <a href=log2.php?group='.urlencode($tmp).'>| '.$tmp.' |</a>' ; | |
} | |
else{ | |
$link .= ' - <a href=log2.php?group=>| * |</a>' ; | |
} | |
} | |
echo $link."</br></br>" ; | |
?> | |
<table border="1" > | |
<tr> | |
<td>#</td> | |
<td>Date</td> | |
<td>Time</td> | |
<td>Group</td> | |
<td>Log</td> | |
</tr> | |
<?php | |
echo $out; | |
?> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment