-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwaste.html
More file actions
63 lines (54 loc) · 2.87 KB
/
waste.html
File metadata and controls
63 lines (54 loc) · 2.87 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Latest Waste Image</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
body {
font-family: 'Inter', sans-serif;
}
</style>
</head>
<body class="bg-gray-100 flex items-center justify-center min-h-screen p-4">
<div class="bg-white p-8 rounded-lg shadow-xl max-w-md w-full text-center">
<h1 class="text-3xl font-bold text-gray-800 mb-6">Live Waste Feed</h1>
<div class="relative w-full h-auto bg-gray-200 rounded-lg overflow-hidden flex items-center justify-center">
<img id="liveImage" src="http://192.168.0.184:8000/latest" alt="Latest Waste Image"
class="w-full h-auto rounded-lg object-contain"
onerror="this.onerror=null;this.src='https://placehold.co/320x240/cccccc/333333?text=Image+Not+Available';">
<div id="loadingIndicator"
class="absolute inset-0 bg-gray-800 bg-opacity-75 flex items-center justify-center text-white text-lg font-semibold hidden rounded-lg">
Loading new image...
</div>
</div>
<p class="text-gray-600 mt-4 text-sm">Image updates every <span id="intervalDisplay">2</span> seconds.</p>
</div>
<script>
const imageElement = document.getElementById( 'liveImage' )
const loadingIndicator = document.getElementById( 'loadingIndicator' )
const intervalDisplay = document.getElementById( 'intervalDisplay' )
const serverIp = '192.168.0.184' // 🔁 Replace with your FastAPI server IP
const refreshInterval = 2000 // Refresh every 2 seconds (2000 milliseconds)
intervalDisplay.textContent = refreshInterval / 1000
function refreshImage () {
loadingIndicator.classList.remove( 'hidden' ) // Show loading indicator
// Append a timestamp to the URL to bypass browser caching
imageElement.src = `http://${ serverIp }:8000/latest?_t=${ new Date().getTime() }`
// Hide loading indicator once image is loaded (or fails to load)
imageElement.onload = () => {
loadingIndicator.classList.add( 'hidden' )
}
imageElement.onerror = () => {
loadingIndicator.classList.add( 'hidden' )
console.error( "Failed to load image. Server might be down or no image available." )
}
}
// Initial image load
refreshImage()
// Set up interval to refresh the image
setInterval( refreshImage, refreshInterval );
</script>
</body>
</html>