-
-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add configuration / webserver setup so you can browse images #24
Comments
Poor man's way of doing this, quick and dirty but it works: First, install Apache:
Second, create a virtualhost that serves up the contents of your pi-timelapse folder. Open the default virtualhost file with
Replace Then restart Apache and make sure it's set to run on boot:
Now browse to your Pi's IP address anywhere else on the network (e.g. http://10.0.100.103/). This is NOT a secure configuration for any Pi that would be accessible from the outside. I'd also like some sort of php script (or anything that can be dynamic, or maybe even an apache rewrite rule) that lets you visit http://10.0.100.103/latest-image, and that dynamically refreshes every X seconds (maybe every 5 by default), and the rewrite looks for the newest folder in the timelapse directory, then the latest full image (since we don't want to load a 0-byte image) in that directory. |
Added a <!DOCTYPE html>
<html>
<head>
<title>Latest Image in Timelapse Series</title>
<meta http-equiv="refresh" content="30" />
</head>
<body>
<img id="the_big_image" src="" width="80%" height="auto" style="display: block; margin: 0 auto;">
<p style="text-align: center;">This page refreshes every 30 seconds.</p>
<script>
// Get the current hostname.
var loc = window.location.href;
const url = new URL(window.location.href);
var current_host = url.protocol + "//" + url.host + "/";
// Get the contents of the hostname.
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", current_host, false);
xmlHttp.send(null);
var host_result = xmlHttp.responseText;
// Get all instances of 'series-[date]' dirs.
const series_regexp = /series-[0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2}-[0-9]{2}/g;
var dirs = host_result.match(series_regexp);
// Get the last dir.
var last_dir = dirs.pop();
// Get the contents of the last dir.
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", current_host + last_dir + "/", false);
xmlHttp.send(null);
var image_result = xmlHttp.responseText;
// Get all instances of 'imageXXXXX.jpg' files.
const image_regexp = /image[0-9]{8}.jpg/g;
var images = image_result.match(image_regexp);
var last_image = images.pop();
// Replace the placeholder image.
document.getElementById("the_big_image").src = '/' + last_dir + '/' + last_image;
</script>
</body>
</html> Note that there's currently a bug with that code—if the latest image is still being written (happens a lot on a Pi Zero since the 2 MB file write can take a second or so), then when the latest page refreshes it will show no image sometimes (or a partially-written image). That happens maybe 10% of the time in my experience at a 10 second refresh rate (though the rate shouldn't have much effect). I considered setting it to show current-1 (e.g. |
Also, the above is a pretty inefficient technique—three page loads and a little JS that uses some regex on what could be thousands of bytes of text—to load in the image (so four resource loads total). It would be nice to do this server-side with a little JS or PHP, but that would require more server-side setup. |
As I've now been using this little app on numerous Pis for projects around the house, and I've also seen some of the nifty timelapse work done by Matthias Wandel (see https://github.com/Matthias-Wandel/imgcomp), I figured it would be nice to have some way of viewing results (and maybe also starting/stopping the timelapses, and maybe even tweaking configuration) via a web UI.
Right now, the process I have for every timelapse is:
And it can be even more frustrating if I have to adjust the Pi's focus, especially if my laptop's upstairs and my rig is downstairs or outside. It takes minutes to get it set up.
It would be nice if, at a minimum, I had a web UI that let me browse the current timelapse folders (e.g. via Apache, just listing the directory contents and allowing pictures to be viewed).
And then, it would also be nice to allow starting/stopping timelapse series.
And finally, allowing configuration to be set, then when it is started/stopped/saved, it would write a new config.yml file with the updated settings.
Maybe Python, PHP, or Node.js to keep things simple? Or even a Go app, for some learning and fun, and easier deployment?
The text was updated successfully, but these errors were encountered: