How pablosambuco/caststatusserver works
Project Type and Purpose
• This is a full-stack, single-page style web application running on a Raspberry Pi (or any Linux system) as a systemd service.
• It discovers and controls Chromecast devices on the local network, exposing status and basic controls via a web UI and WebSocket channel.
File Structure
Top-level components:
• caststatusserver.py – Main entrypoint, initializes the web server (bottle/werkzeug) and WebSocket handlers (gevent-websocket).
• web.py – Defines HTTP routes (login, status pages) and API endpoints.
• static/ – Client assets (HTML, CSS, JS). JavaScript (main.js) opens a WebSocket and issues AJAX calls.
• views/ – Template files (login.tpl).
• service/ – systemd unit file for auto-starting the server.
• install_service.sh – Installation script for the service.
• interface.cfg, port.cfg – Configuration files (network interface, listening port).
• requirements.txt / Pipfile – Python dependencies: Bottle (or Werkzeug), gevent, gevent-websocket, pychromecast.
README for Additional Insights
• Confirms use of pychromecast to discover/control devices.
• Uses gevent-based WebSocket for live updates.
• Runs as a systemd service on Raspberry Pi.
Main Components and Relationships
A. Client Browser
• Loads HTML/CSS from “static/html/index.html”
• Runs JavaScript (static/js/main.js).
B. HTTP Server (caststatusserver.py + web.py)
• Serves static files & templates.
• Exposes RESTful endpoints for login/status.
• Manages WebSocket connections for real-time updates.
C. Chromecast Controller Module
• Uses pychromecast to scan LAN, retrieve status, send play/pause commands.
• Runs within the same Python process under gevent’s event loop.
D. Configuration Store
• interface.cfg, port.cfg read at startup.
E. System Service
• systemd unit (service/caststatusserver.service) invokes install_service.sh.
F. External Network
• Local network including multiple Chromecast devices.
Data flows:
1. Browser → HTTP GET → Server → static/html or template view.
2. Browser → AJAX/REST → Server → Chromecast module → LAN → devices → Server → JSON response → Browser.
3. Browser ↔ WebSocket → Server → Chromecast module (push updates) → Browser UI.
Architectural Patterns & Design Principles
• Monolithic, event-driven architecture: all components live in one process.
• Asynchronous I/O via gevent for nonblocking Chromecast calls and WebSockets.
• Clear separation: Static assets vs. dynamic Python code vs. system service.
• Minimal external dependencies: Bottle or Werkzeug for HTTP, gevent for concurrency, pychromecast for device control.