forked from thomasjacquin/allsky-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublic.php
executable file
·69 lines (55 loc) · 2.45 KB
/
public.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
<?php
define('RASPI_CONFIG', '/etc/raspap');
$file = '/home/pi/allsky/config.sh';
$searchfor = 'CAMERA=';
// get the file contents, assuming the file to be readable (and exist)
$contents = file_get_contents($file);
// escape special characters in the query
$pattern = preg_quote($searchfor, '/');
// finalise the regular expression, matching the whole line
$pattern = "/^.*$pattern.*\$/m";
// search, and store all matching occurences in $matches
if(preg_match_all($pattern, $contents, $matches)){
$double_quote = '"';
$cam = str_replace($double_quote, '', explode( '=', implode("\n", $matches[0]))[1]);
}
else{
$cam = "ZWO";
}
define('RASPI_CAMERA_SETTINGS', RASPI_CONFIG . '/settings_'.$cam.'.json');
$camera_settings_str = file_get_contents(RASPI_CAMERA_SETTINGS, true);
$camera_settings_array = json_decode($camera_settings_str, true);
?>
<style>
body {
margin: 0;
}
</style>
<div class="row">
<div id="live_container" style="background-color: black;">
<img id="current" class="current" src="current/liveview-<?php echo $camera_settings_array['filename'] ?>" style="width:100%">
</div>
</div>
<!-- jQuery -->
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript">
function getImage(){
var img = $("<img />").attr('src', 'current/liveview-<?php echo $camera_settings_array["filename"] ?>?_ts=' + new Date().getTime())
.attr("id", "current")
.attr("class", "current")
.css("width", "100%")
.on('load', function() {
if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
console.log('broken image!');
setTimeout(function(){
getImage();
}, 500);
} else {
$("#live_container").empty().append(img);
}
});
}
setInterval(function(){
getImage();
}, <?php echo $camera_settings_array["exposure"]/1000 < 5000 ? 5000 : $camera_settings_array["exposure"]/1000?>);
</script>