feat: remove vercel web frontend part and rename to pi

This commit is contained in:
Jet Pham 2026-03-02 19:22:37 -08:00
parent dff2e96947
commit b2c8d08bdc
No known key found for this signature in database
46 changed files with 0 additions and 4965 deletions

370
pi/static/monitor.html Normal file
View file

@ -0,0 +1,370 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Circuit Monitor</title>
<link rel="icon" type="image/x-icon" href="media/noisebell logo.ico">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: white;
margin: 0;
padding: 0;
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
color: #333;
}
.container {
background: white;
border-radius: 20px;
padding: 40px;
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
border: 2px solid #e0e0e0;
text-align: center;
max-width: 500px;
width: 100%;
}
.header {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 30px;
gap: 15px;
}
.logo {
width: 100px;
height: 100px;
object-fit: contain;
}
h1 {
margin: 0;
font-size: 2.5em;
color: #333;
text-shadow: none;
}
.status-section {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 30px;
width: 100%;
}
.status-image {
width: 178px;
height: 500px;
object-fit: contain;
}
/* Toggle Switch Styles */
.switch-container {
display: flex;
align-items: center;
justify-content: center;
margin: 30px 0;
position: relative;
width: 100%;
}
.switch-label {
position: absolute;
font-size: 1.2em;
font-weight: bold;
width: 80px;
text-align: center;
}
.switch-label.open {
color: #2ecc71;
right: calc(50% + 80px);
}
.switch-label.closed {
color: #e74c3c;
left: calc(50% + 80px);
}
.switch {
position: relative;
display: inline-block;
width: 120px;
height: 60px;
z-index: 1;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(135deg, #2ecc71, #27ae60);
border-radius: 60px;
transition: all 0.1s ease;
box-shadow: 0 4px 15px rgba(46, 204, 113, 0.4);
}
.slider:before {
position: absolute;
content: "";
height: 52px;
width: 52px;
left: 4px;
bottom: 4px;
background: white;
border-radius: 50%;
transition: all 0.1s ease;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}
input:checked + .slider {
background: linear-gradient(135deg, #e74c3c, #c0392b);
box-shadow: 0 4px 15px rgba(231, 76, 60, 0.4);
}
input:checked + .slider:before {
transform: translateX(60px);
}
.slider:after {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 20px;
height: 20px;
background: rgba(255, 255, 255, 0.3);
border-radius: 50%;
transform: translate(-50%, -50%);
transition: all 0.3s ease;
}
input:checked + .slider:after {
background: rgba(255, 255, 255, 0.2);
}
.connection-status {
margin-top: 20px;
padding: 10px;
border-radius: 5px;
font-size: 0.9em;
border: 1px solid;
}
.connection-status.connected {
background: rgba(46, 204, 113, 0.1);
color: #2ecc71;
border-color: #2ecc71;
}
.connection-status.disconnected {
background: rgba(231, 76, 60, 0.1);
color: #e74c3c;
border-color: #e74c3c;
}
.connection-status.connecting {
background: rgba(241, 196, 15, 0.1);
color: #f39c12;
border-color: #f39c12;
}
@media (max-width: 480px) {
.container {
margin: 20px;
padding: 30px 20px;
}
.header {
flex-direction: column;
gap: 10px;
}
h1 {
font-size: 2em;
}
.status-section {
flex-direction: column;
gap: 15px;
}
.status-image {
width: 60px;
height: 60px;
}
.switch-container {
flex-direction: column;
gap: 15px;
}
.switch-label {
margin: 0;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<img src="/media/noisebell logo.svg" class="logo">
<h1>Circuit Monitor</h1>
</div>
<div class="status-section">
<img src="/media/closed.png" alt="Circuit State" class="status-image" id="statusImage">
</div>
<div class="switch-container">
<div class="switch-label open">OPEN</div>
<label class="switch">
<input type="checkbox" id="circuitSwitch" checked>
<span class="slider"></span>
</label>
<div class="switch-label closed">CLOSED</div>
</div>
<div class="connection-status connecting" id="connectionStatus">
Connecting...
</div>
</div>
<script>
class CircuitMonitor {
constructor() {
this.ws = null;
this.switchElement = document.getElementById('circuitSwitch');
this.statusImage = document.getElementById('statusImage');
this.connectionStatus = document.getElementById('connectionStatus');
this.isUserChange = false;
this.init();
}
init() {
this.setupEventListeners();
this.connect();
}
setupEventListeners() {
this.switchElement.addEventListener('change', (e) => {
if (this.isUserChange) return;
const newState = e.target.checked ? 'closed' : 'open';
this.sendStateChange(newState);
});
}
connect() {
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const wsUrl = `${protocol}//${window.location.host}/ws`;
this.ws = new WebSocket(wsUrl);
this.ws.onopen = () => {
console.log('WebSocket connected');
this.updateConnectionStatus('connected');
};
this.ws.onmessage = (event) => {
try {
const data = JSON.parse(event.data);
this.handleMessage(data);
} catch (error) {
console.error('Failed to parse message:', error);
}
};
this.ws.onclose = () => {
console.log('WebSocket disconnected');
this.updateConnectionStatus('disconnected');
// Attempt to reconnect after 3 seconds
setTimeout(() => {
this.updateConnectionStatus('connecting');
this.connect();
}, 3000);
};
this.ws.onerror = (error) => {
console.error('WebSocket error:', error);
this.updateConnectionStatus('disconnected');
};
}
handleMessage(data) {
if (data.event === 'state_update') {
this.updateState(data.state);
}
}
updateState(state) {
this.isUserChange = true;
// Update status image
this.statusImage.src = `/media/${state}.png`;
this.statusImage.alt = `Circuit ${state}`;
console.log(`State updated to: ${state}`);
// Reset flag after a short delay
setTimeout(() => {
this.isUserChange = false;
}, 100);
}
sendStateChange(newState) {
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
const message = {
event: 'state_change',
state: newState
};
this.ws.send(JSON.stringify(message));
console.log(`Sent state change: ${newState}`);
} else {
console.error('WebSocket is not connected');
}
}
updateConnectionStatus(status) {
this.connectionStatus.className = `connection-status ${status}`;
switch (status) {
case 'connected':
this.connectionStatus.textContent = 'Connected';
break;
case 'connecting':
this.connectionStatus.textContent = 'Connecting...';
break;
case 'disconnected':
this.connectionStatus.textContent = 'Disconnected - Reconnecting...';
break;
}
}
}
// Initialize the monitor when the page loads
document.addEventListener('DOMContentLoaded', () => {
new CircuitMonitor();
});
</script>
</body>
</html>