back-end ustreamer, GPS, timelapse, and photo-refresh site working

This commit is contained in:
2025-07-27 15:10:11 -07:00
parent 7496df0174
commit b740ba9991
22 changed files with 443 additions and 99 deletions

View File

@ -0,0 +1,22 @@
<?php
header("Cache-Control: no-cache, must-revalidate");
// Path to the directory where the images are stored
$imageDirectory = 'capture/';
// Get the list of image files in the directory
$imageFiles = glob($imageDirectory . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
// If there are no image files, return a default image
if (empty($imageFiles)) {
$defaultImage = 'default.jpg'; // Provide path to your default image
header('Content-Type: image/jpeg'); // Adjust content type if default image type is different
readfile($defaultImage);
exit;
}
// Sort the image files by modification time, latest first
array_multisort(array_map('filemtime', $imageFiles), SORT_DESC, $imageFiles);
// Get the path to the latest image file
$latestImage = $imageFiles[0];
// Set header type
header('Content-Type: image/jpeg');
// Get the image
readfile($latestImage);
?>

View File

@ -0,0 +1,17 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dynamic Image Update</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<img id="refreshedImage" src="getImage.php" width="400" alt="Refreshed Image">
<script>
// Function to update the image every second using AJAX
setInterval(function() {
$('#refreshedImage').attr('src', 'getImage.php?_=' + new Date().getTime()); // Adding timestamp to avoid caching
}, 1000);
</script>
</body>
</html>

54
files/python_gps/app.py Normal file
View File

@ -0,0 +1,54 @@
from flask import Flask, jsonify
import gps
import threading
import time
app = Flask(__name__)
# GPS data container
current_gps_data = {
"latitude": None,
"longitude": None,
"altitude": None,
"speed": None,
"timestamp": None
}
# Global gps session object
session = gps.gps(mode=gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)
def gps_monitor():
global current_gps_data
while True:
try:
# Wait for new data from the GPS device
report = session.next()
if report['class'] == 'TPV':
current_gps_data = {
"latitude": report.get('lat', None),
"longitude": report.get('lon', None),
"altitude": report.get('alt', None),
"speed": report.get('speed', None),
"timestamp": report.get('time', None)
}
except gps.GPSException as e:
print(f"GPS Error: {e}")
except KeyError as e:
print(f"Missing Key: {e}")
time.sleep(1)
@app.route('/gps', methods=['GET'])
def get_gps_data():
"""API endpoint to fetch current GPS data"""
if None in current_gps_data.values():
return jsonify({"error": "No GPS data available yet"}), 404
return jsonify(current_gps_data)
if __name__ == '__main__':
# Start GPS monitoring in a separate thread
gps_thread = threading.Thread(target=gps_monitor)
gps_thread.daemon = True # This makes the thread exit when the program does
gps_thread.start()
# Run the Flask web service
app.run(host='0.0.0.0', port=5000)