This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import time | |
| import json | |
| import random | |
| import sys | |
| import datetime | |
| # Attempt to import requests, providing a clear error if missing | |
| try: | |
| import requests | |
| except ImportError: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Water Pump Monitor</title> | |
| <link rel="stylesheet" href="style.css"> | |
| <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> | |
| </head> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| :root { | |
| --bg-color: #1a1a1a; | |
| --card-bg: #2d2d2d; | |
| --text-primary: #e0e0e0; | |
| --text-secondary: #aaaaaa; | |
| --accent: #007bff; | |
| --success: #28a745; | |
| --danger: #dc3545; | |
| --warning: #ffc107; | |
| --offline-gray: #6c757d; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Chart Configuration | |
| const ctx = document.getElementById('historyChart').getContext('2d'); | |
| let historyChart = new Chart(ctx, { | |
| type: 'line', | |
| data: { | |
| labels: [], | |
| datasets: [{ | |
| label: 'Sensor Temperature (°C)', | |
| data: [], | |
| borderColor: '#ffc107', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Optional | |
| from datetime import datetime | |
| from sqlmodel import Field, SQLModel | |
| class Heartbeat(SQLModel, table=True): | |
| id: Optional[int] = Field(default=None, primary_key=True) | |
| device_id: str = Field(index=True) | |
| timestamp: datetime = Field(index=True) | |
| received_at: datetime = Field(default_factory=datetime.utcnow) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi.staticfiles import StaticFiles | |
| from backend.database import create_db_and_tables | |
| from backend.routers import api | |
| import os | |
| app = FastAPI(title="Water Pump Monitor") | |
| # CORS (allow request from same origin or dev) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sqlmodel import SQLModel, create_engine, Session | |
| sqlite_file_name = "pump_monitor.db" | |
| sqlite_url = f"sqlite:///{sqlite_file_name}" | |
| connect_args = {"check_same_thread": False} | |
| engine = create_engine(sqlite_url, connect_args=connect_args) | |
| def create_db_and_tables(): | |
| SQLModel.metadata.create_all(engine) |