ensure web ui actions work and web interface is starting without venv

This commit is contained in:
Chuck
2025-08-11 14:12:17 -05:00
parent 18d6758dbe
commit 1704001ef6
3 changed files with 16 additions and 573 deletions

View File

@@ -1199,12 +1199,20 @@ The LEDMatrix system includes a robust caching mechanism to optimize API calls a
- Building a user-friendly UI for easier configuration (done!) - Building a user-friendly UI for easier configuration (done!)
### If you've read this far — thanks!
## Granting Passwordless Sudo Access for Web Interface Actions ## Granting Passwordless Sudo Access for Web Interface Actions
The web interface needs to run certain commands with `sudo` (e.g., `reboot`, `systemctl start/stop/enable/disable ledmatrix.service`, `python display_controller.py`). To avoid needing to enter a password for these actions through the web UI, you can configure the `sudoers` file to allow the user running the Flask application to execute these specific commands without a password. The web interface needs to run certain commands with `sudo` (e.g., `reboot`, `systemctl start/stop/enable/disable ledmatrix.service`, `python display_controller.py`). To avoid needing to enter a password for these actions through the web UI, you can configure the `sudoers` file to allow the user running the Flask application to execute these specific commands without a password.
1. Shortcut to automate the below steps:
```chmod +x configure_web_sudo.sh```
then
```./configure_web_sudo.sh```
Manual Method:
**WARNING: Be very careful when editing the `sudoers` file. Incorrect syntax can lock you out of `sudo` access.** **WARNING: Be very careful when editing the `sudoers` file. Incorrect syntax can lock you out of `sudo` access.**
1. **Identify the user:** Determine which user is running the `web_interface.py` script. Often, this might be the default user like `pi` on a Raspberry Pi, or a dedicated user you've set up. 1. **Identify the user:** Determine which user is running the `web_interface.py` script. Often, this might be the default user like `pi` on a Raspberry Pi, or a dedicated user you've set up.
@@ -1256,35 +1264,28 @@ For `display_controller.py` and `stop_display.sh`, ensure their file permissions
## Web Interface V2 (simplified quick start) ## Web Interface V2 (simplified quick start)
### 1) Create and populate the venv (recommended) ### 1) un the helper (does the above and starts the server):
```
cd /home/ledpi/LEDMatrix
python3 -m venv venv_web_v2
source venv_web_v2/bin/activate
pip install -r requirements_web_v2.txt
pip install -e rpi-rgb-led-matrix-master/bindings/python
```
Alternatively, run the helper (does the above and starts the server):
``` ```
python3 start_web_v2.py python3 start_web_v2.py
``` ```
### 2) Start the web UI v2 ### 2) Start the web UI v2
``` ```
source venv_web_v2/bin/activate
python web_interface_v2.py python web_interface_v2.py
``` ```
### 3) Autostart (optional) ### 3) Autostart (optional)
Set `"web_display_autostart": true` in `config/config.json`. Set `"web_display_autostart": true` in `config/config.json`.
Ensure your systemd service (or launcher) calls `start_web_conditionally.py`. Ensure your systemd service (or launcher) calls `start_web_conditionally.py`.
It will prefer `venv_web_v2/bin/python` if present.
### 4) Permissions (optional but recommended) ### 4) Permissions (optional but recommended)
- Add the service user to `systemd-journal` for viewing logs without sudo. - Add the service user to `systemd-journal` for viewing logs without sudo.
- Configure passwordless sudo for actions (start/stop service, reboot, shutdown) if desired. - Configure passwordless sudo for actions (start/stop service, reboot, shutdown) if desired.
- Required for web Ui actions, look in the section above for the commands to run (chmod +x configure_web_sudo.sh & ./configure_web_sudo.sh)
### 5) Old web UI (v1) ### 5) Old web UI (v1)
The project now defaults to Web UI v2. The v1 interface can be removed or ignored. The project now defaults to Web UI v2. The v1 interface can be ignored.
An LED matrix display system that provides real-time information display capabilities for various data sources. The system is highly configurable and supports multiple display modes that can be enabled or disabled based on user preferences. An LED matrix display system that provides real-time information display capabilities for various data sources. The system is highly configurable and supports multiple display modes that can be enabled or disabled based on user preferences.
### If you've read this far — thanks!

View File

@@ -1,271 +0,0 @@
#!/usr/bin/env python3
"""
LED Matrix Web Interface V2 Demo
Demonstrates the new features and capabilities of the modern web interface.
"""
import os
import time
import json
from src.layout_manager import LayoutManager
from src.display_manager import DisplayManager
from src.config_manager import ConfigManager
def create_demo_config():
"""Create a demo configuration for testing."""
demo_config = {
"display": {
"hardware": {
"rows": 32,
"cols": 64,
"chain_length": 2,
"parallel": 1,
"brightness": 95,
"hardware_mapping": "adafruit-hat-pwm"
},
"runtime": {
"gpio_slowdown": 3
}
},
"schedule": {
"enabled": True,
"start_time": "07:00",
"end_time": "23:00"
}
}
return demo_config
def demo_layout_manager():
"""Demonstrate the layout manager capabilities."""
print("🎨 LED Matrix Layout Manager Demo")
print("=" * 50)
# Create layout manager (without actual display for demo)
layout_manager = LayoutManager()
# Create preset layouts
print("Creating preset layouts...")
layout_manager.create_preset_layouts()
# List available layouts
layouts = layout_manager.list_layouts()
print(f"Available layouts: {layouts}")
# Show layout previews
for layout_name in layouts:
preview = layout_manager.get_layout_preview(layout_name)
print(f"\n📋 Layout: {layout_name}")
print(f" Description: {preview.get('description', 'No description')}")
print(f" Elements: {preview.get('element_count', 0)}")
for element in preview.get('elements', []):
print(f" - {element['type']} at {element['position']}")
return layout_manager
def demo_custom_layout():
"""Demonstrate creating a custom layout."""
print("\n🛠️ Creating Custom Layout Demo")
print("=" * 50)
layout_manager = LayoutManager()
# Create a custom sports dashboard layout
sports_layout = [
{
'type': 'text',
'x': 2,
'y': 2,
'properties': {
'text': 'SPORTS',
'color': [255, 255, 0],
'font_size': 'normal'
}
},
{
'type': 'line',
'x': 0,
'y': 12,
'properties': {
'x2': 128,
'y2': 12,
'color': [100, 100, 100]
}
},
{
'type': 'data_text',
'x': 2,
'y': 15,
'properties': {
'data_key': 'sports.team1.score',
'format': 'TB: {value}',
'color': [0, 255, 0],
'default': 'TB: --'
}
},
{
'type': 'data_text',
'x': 2,
'y': 24,
'properties': {
'data_key': 'sports.team2.score',
'format': 'DAL: {value}',
'color': [0, 100, 255],
'default': 'DAL: --'
}
}
]
# Save the custom layout
success = layout_manager.create_layout(
'sports_dashboard',
sports_layout,
'Custom sports dashboard showing team scores'
)
if success:
print("✅ Custom sports dashboard layout created successfully!")
# Show the layout preview
preview = layout_manager.get_layout_preview('sports_dashboard')
print(f"📋 Layout Preview:")
print(f" Elements: {preview.get('element_count', 0)}")
for element in preview.get('elements', []):
print(f" - {element['type']} at {element['position']}")
else:
print("❌ Failed to create custom layout")
return layout_manager
def demo_web_features():
"""Demonstrate web interface features."""
print("\n🌐 Web Interface Features Demo")
print("=" * 50)
features = [
"🖥️ Real-Time Display Preview",
" - Live WebSocket connection",
" - Scaled-up preview for visibility",
" - Screenshot capture",
"",
"✏️ Display Editor Mode",
" - Drag-and-drop element placement",
" - Real-time property editing",
" - Custom layout creation",
" - Element palette with multiple types",
"",
"📊 System Monitoring",
" - CPU temperature tracking",
" - Memory usage monitoring",
" - Service status indicators",
" - Performance metrics",
"",
"⚙️ Configuration Management",
" - Tabbed interface for organization",
" - Visual controls (sliders, toggles)",
" - Real-time config updates",
" - Instant feedback",
"",
"🎨 Modern UI Design",
" - Responsive layout",
" - Professional styling",
" - Smooth animations",
" - Color-coded status indicators"
]
for feature in features:
print(feature)
if feature.startswith(" -"):
time.sleep(0.1) # Small delay for effect
def demo_api_endpoints():
"""Show available API endpoints."""
print("\n🔌 API Endpoints Demo")
print("=" * 50)
endpoints = {
"Display Control": [
"POST /api/display/start - Start the LED matrix",
"POST /api/display/stop - Stop the LED matrix",
"GET /api/display/current - Get current display image"
],
"Editor Mode": [
"POST /api/editor/toggle - Toggle editor mode",
"POST /api/editor/preview - Update layout preview"
],
"Configuration": [
"POST /api/config/save - Save configuration changes",
"GET /api/system/status - Get system status"
],
"System Actions": [
"POST /api/system/action - Execute system commands",
"GET /logs - View system logs"
]
}
for category, apis in endpoints.items():
print(f"\n📁 {category}:")
for api in apis:
print(f" {api}")
def show_setup_instructions():
"""Show setup instructions."""
print("\n🚀 Setup Instructions")
print("=" * 50)
instructions = [
"1. Install dependencies:",
" pip install -r requirements_web_v2.txt",
"",
"2. Make startup script executable:",
" chmod +x start_web_v2.py",
"",
"3. Start the web interface:",
" python3 start_web_v2.py",
"",
"4. Access the interface:",
" Open browser to http://your-pi-ip:5001",
"",
"5. Enter Editor Mode:",
" - Click 'Enter Editor' button",
" - Drag elements from palette",
" - Customize properties",
" - Save your layout",
"",
"6. Monitor your system:",
" - Check real-time stats in header",
" - View performance metrics",
" - Access system logs"
]
for instruction in instructions:
print(instruction)
def main():
"""Main demo function."""
print("🎯 LED Matrix Web Interface V2 - Complete Demo")
print("=" * 60)
print()
# Show features
demo_web_features()
# Demo layout manager
layout_manager = demo_layout_manager()
# Demo custom layout creation
demo_custom_layout()
# Show API endpoints
demo_api_endpoints()
# Show setup instructions
show_setup_instructions()
print("\n" + "=" * 60)
print("🎉 Demo Complete!")
print("Ready to revolutionize your LED Matrix experience!")
print("Start the web interface with: python3 start_web_v2.py")
print("=" * 60)
if __name__ == '__main__':
main()

View File

@@ -1,287 +0,0 @@
#!/usr/bin/env python3
"""
LED Matrix Web Interface V2 Demo (Simplified)
Demonstrates the new features without requiring hardware.
"""
import json
import time
def demo_web_features():
"""Demonstrate web interface features."""
print("🌐 LED Matrix Web Interface V2 - Feature Overview")
print("=" * 60)
features = [
"",
"🖥️ REAL-TIME DISPLAY PREVIEW",
" ✓ Live WebSocket connection to LED matrix",
" ✓ Scaled-up preview (4x) for better visibility",
" ✓ Real-time updates as content changes",
" ✓ Screenshot capture functionality",
"",
"✏️ DISPLAY EDITOR MODE",
" ✓ Drag-and-drop interface for custom layouts",
" ✓ Element palette: text, weather icons, shapes, lines",
" ✓ Properties panel for fine-tuning appearance",
" ✓ Real-time preview of changes on actual display",
" ✓ Save/load custom layouts for reuse",
"",
"📊 SYSTEM MONITORING",
" ✓ Real-time CPU temperature and memory usage",
" ✓ Service status monitoring with visual indicators",
" ✓ Performance metrics dashboard",
" ✓ Connection status indicator",
"",
"⚙️ CONFIGURATION MANAGEMENT",
" ✓ Modern tabbed interface for easy navigation",
" ✓ Visual controls (sliders, toggles, dropdowns)",
" ✓ Real-time configuration updates",
" ✓ Instant feedback on changes",
"",
"🎨 MODERN UI DESIGN",
" ✓ Responsive design (works on desktop & mobile)",
" ✓ Professional card-based layout",
" ✓ Smooth animations and transitions",
" ✓ Color-coded status indicators",
" ✓ Dark theme optimized for LED matrix work"
]
for feature in features:
print(feature)
if feature.startswith(""):
time.sleep(0.1)
def demo_layout_system():
"""Show the layout system capabilities."""
print("\n🎨 CUSTOM LAYOUT SYSTEM")
print("=" * 60)
print("The new layout system allows you to:")
print("")
print("📋 PRESET LAYOUTS:")
print(" • Basic Clock - Simple time and date display")
print(" • Weather Display - Icon with temperature and conditions")
print(" • Dashboard - Mixed clock, weather, and stock data")
print("")
print("🛠️ CUSTOM ELEMENTS:")
print(" • Text Elements - Static or data-driven text")
print(" • Weather Icons - Dynamic weather condition icons")
print(" • Shapes - Rectangles for borders/backgrounds")
print(" • Lines - Decorative separators")
print(" • Clock Elements - Customizable time formats")
print(" • Data Text - Live data from APIs (stocks, weather, etc.)")
print("")
print("⚡ REAL-TIME EDITING:")
print(" • Drag elements directly onto display preview")
print(" • Adjust position, color, size in properties panel")
print(" • See changes instantly on actual LED matrix")
print(" • Save layouts for later use")
def demo_api_endpoints():
"""Show available API endpoints."""
print("\n🔌 REST API ENDPOINTS")
print("=" * 60)
endpoints = {
"🖥️ Display Control": [
"POST /api/display/start - Start the LED matrix display",
"POST /api/display/stop - Stop the LED matrix display",
"GET /api/display/current - Get current display as base64 image"
],
"✏️ Editor Mode": [
"POST /api/editor/toggle - Enter/exit display editor mode",
"POST /api/editor/preview - Update preview with custom layout"
],
"⚙️ Configuration": [
"POST /api/config/save - Save configuration changes",
"GET /api/system/status - Get real-time system status"
],
"🔧 System Actions": [
"POST /api/system/action - Execute system commands",
"GET /logs - View system logs in browser"
]
}
for category, apis in endpoints.items():
print(f"\n{category}:")
for api in apis:
print(f" {api}")
def show_editor_workflow():
"""Show the editor workflow."""
print("\n✏️ DISPLAY EDITOR WORKFLOW")
print("=" * 60)
workflow = [
"1. 🚀 ENTER EDITOR MODE",
" • Click 'Enter Editor' button in web interface",
" • Normal display operation pauses",
" • Display switches to editor mode",
"",
"2. 🎨 DESIGN YOUR LAYOUT",
" • Drag elements from palette onto display preview",
" • Elements appear exactly where you drop them",
" • Click elements to select and edit properties",
"",
"3. 🔧 CUSTOMIZE PROPERTIES",
" • Adjust position (X, Y coordinates)",
" • Change colors (RGB values)",
" • Modify text content and fonts",
" • Resize elements as needed",
"",
"4. 👀 REAL-TIME PREVIEW",
" • Changes appear instantly on actual LED matrix",
" • No need to restart or reload",
" • See exactly how it will look",
"",
"5. 💾 SAVE YOUR WORK",
" • Click 'Save Layout' to store design",
" • Layouts saved locally for reuse",
" • Load layouts anytime in the future",
"",
"6. 🎯 EXIT EDITOR MODE",
" • Click 'Exit Editor' to return to normal operation",
" • Your custom layout can be used in rotation"
]
for step in workflow:
print(step)
def show_system_monitoring():
"""Show system monitoring capabilities."""
print("\n📊 SYSTEM MONITORING DASHBOARD")
print("=" * 60)
monitoring = [
"🌡️ HARDWARE MONITORING:",
" • CPU Temperature - Real-time thermal monitoring",
" • Memory Usage - RAM usage percentage",
" • System Uptime - How long system has been running",
"",
"⚡ SERVICE STATUS:",
" • LED Matrix Service - Active/Inactive status",
" • Display Connection - Hardware connection status",
" • Web Interface - Connection indicator",
"",
"📈 PERFORMANCE METRICS:",
" • Update frequency - Display refresh rates",
" • Network status - WebSocket connection health",
" • Resource usage - System performance tracking",
"",
"🔍 TROUBLESHOOTING:",
" • System logs accessible via web interface",
" • Error messages with timestamps",
" • Performance alerts for resource issues"
]
for item in monitoring:
print(item)
def show_setup_guide():
"""Show complete setup guide."""
print("\n🚀 COMPLETE SETUP GUIDE")
print("=" * 60)
setup_steps = [
"📦 INSTALLATION:",
" 1. pip install -r requirements_web_v2.txt",
" 2. chmod +x start_web_v2.py",
"",
"🌐 STARTING THE INTERFACE:",
" 3. python3 start_web_v2.py",
" 4. Open browser to http://your-pi-ip:5001",
"",
"🎯 FIRST USE:",
" 5. Check system status in header",
" 6. Use Start/Stop buttons to control display",
" 7. Take screenshots for documentation",
"",
"✏️ USING THE EDITOR:",
" 8. Click 'Enter Editor' button",
" 9. Drag elements from palette to display",
" 10. Customize properties in right panel",
" 11. Save your custom layouts",
"",
"⚙️ CONFIGURATION:",
" 12. Use Config tab for display settings",
" 13. Adjust brightness, schedule, hardware settings",
" 14. Changes apply in real-time",
"",
"🔧 SYSTEM MANAGEMENT:",
" 15. Use System tab for maintenance",
" 16. View logs, restart services, update code",
" 17. Monitor performance metrics"
]
for step in setup_steps:
print(step)
def show_benefits():
"""Show the benefits of the new interface."""
print("\n🎉 WHY UPGRADE TO WEB INTERFACE V2?")
print("=" * 60)
benefits = [
"🚀 MODERN & INTUITIVE:",
" • Professional web interface replaces basic controls",
" • Responsive design works on any device",
" • No more SSH or command-line configuration",
"",
"⚡ REAL-TIME CONTROL:",
" • See exactly what your display shows",
" • Make changes and see results instantly",
" • No more guessing what the display looks like",
"",
"🎨 CREATIVE FREEDOM:",
" • Design custom layouts visually",
" • Drag-and-drop interface for easy positioning",
" • Save and reuse your favorite designs",
"",
"📊 BETTER MONITORING:",
" • Keep track of system health",
" • Get alerts for performance issues",
" • Access logs without SSH",
"",
"🛠️ EASIER MAINTENANCE:",
" • Update code with one click",
" • Restart services from web interface",
" • Troubleshoot issues visually",
"",
"💡 LIGHTWEIGHT & EFFICIENT:",
" • Designed specifically for Raspberry Pi",
" • Minimal resource usage",
" • Runs alongside LED matrix without issues"
]
for benefit in benefits:
print(benefit)
def main():
"""Main demo function."""
print("🎯 LED MATRIX WEB INTERFACE V2")
print(" Modern • Sleek • Powerful • Easy to Use")
print("=" * 60)
# Show all demos
demo_web_features()
demo_layout_system()
show_editor_workflow()
demo_api_endpoints()
show_system_monitoring()
show_setup_guide()
show_benefits()
print("\n" + "=" * 60)
print("🎉 READY TO TRANSFORM YOUR LED MATRIX EXPERIENCE!")
print("")
print("🚀 GET STARTED:")
print(" python3 start_web_v2.py")
print(" Open browser to http://your-pi-ip:5001")
print("")
print("📚 DOCUMENTATION:")
print(" See WEB_INTERFACE_V2_README.md for full details")
print("=" * 60)
if __name__ == '__main__':
main()