diff --git a/.gitignore b/.gitignore index fd8ffc4..9e491fe 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,8 @@ dist/ # Logs *.log + +# SQLite +*.db +*.db-shm +*.db-wal diff --git a/agents/tapo/src/main.rs b/agents/tapo/src/main.rs index 4cfad53..70a148c 100644 --- a/agents/tapo/src/main.rs +++ b/agents/tapo/src/main.rs @@ -389,6 +389,11 @@ async fn collect_device_data(device: &DeviceConfig) -> Vec { } Err(e) => debug!("get_schedule_rules failed for {}: {}", device.name, e), } + + match plug.get_device_usage().await { + Ok(usage) => info!("P100 Usage for {}: {:?}", device.name, usage), + Err(e) => warn!("Failed to get P100 usage for {}: {}", device.name, e), + } } Err(e) => error!("Failed to connect to P100 {}: {}", device.name, e), } diff --git a/nginx_proxy.md b/nginx_proxy.md new file mode 100644 index 0000000..eec07a0 --- /dev/null +++ b/nginx_proxy.md @@ -0,0 +1,120 @@ +# Setting up Nginx as a Reverse Proxy + +This guide explains how to configure Nginx to act as a reverse proxy for the TischlerCtrl server. This allows you to host the application on standard HTTP/HTTPS ports (80/443) and adds a layer of security. + +## Prerequisites + +- A Linux server (Debian/Ubuntu/Raspberry Pi OS). +- Root or sudo access. +- TischlerCtrl server running on localhost (default port: `8080`). + +## 1. Install Nginx + +If Nginx is not already installed: + +```bash +sudo apt update +sudo apt install nginx +``` + +## 2. Create Configuration File + +Create a new configuration file for the site in `/etc/nginx/sites-available/`. We'll name it `tischlerctrl`. + +```bash +sudo nano /etc/nginx/sites-available/tischlerctrl +``` + +Paste the following configuration using your actual domain name or IP address: + +```nginx +server { + listen 80; + server_name your-domain.com; # Replace with your domain or IP address + + # Access logs + access_log /var/log/nginx/tischlerctrl.access.log; + error_log /var/log/nginx/tischlerctrl.error.log; + + location /agentapi/ { + proxy_pass http://localhost:8080/; # Trailing slash strips /agentapi/ + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + + # Forwarding real client IP + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} +``` + +### Key Configuration Explained + +- **proxy_pass**: Forwards requests to your Node.js application running on port 8080. +- **WebSocket Support**: These lines are **critical** for TischlerCtrl as it relies on WebSockets for real-time sensor data: + ```nginx + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + ``` + +## 3. Enable the Site + +Create a symbolic link to the `sites-enabled` directory to activate the configuration: + +```bash +sudo ln -s /etc/nginx/sites-available/tischlerctrl /etc/nginx/sites-enabled/ +``` + +## 4. Test and Reload Nginx + +Test the configuration for syntax errors: + +```bash +sudo nginx -t +``` + +If the test is successful (returns `syntax is ok`), reload Nginx: + +```bash +sudo systemctl reload nginx +``` + +## 5. SSL Configuration (Recommended) + +To secure your connection with HTTPS (especially important for authentication), use Certbot to automatically configure a free specific Let's Encrypt SSL certificate. + +```bash +sudo apt install certbot python3-certbot-nginx +sudo certbot --nginx -d your-domain.com +``` + +Certbot will automatically modify your Nginx configuration to force HTTPS redirection and manage the SSL certificates. + +## 6. Update Client Configurations + +Since you are serving the API under `/agentapi/`, you must update your agents' configuration to point to the new URL path. + +### WebSocket URL Format + +- **Old (Direct):** `ws://server-ip:8080` +- **New (Proxy):** `ws://your-domain.com/agentapi/` (or `wss://` if using SSL) + +### Example for Tapo Agent (`config.toml`) + +```toml +server_url = "ws://your-domain.com/agentapi/" +# Or with SSL: +# server_url = "wss://your-domain.com/agentapi/" +``` + +### Example for Environment Variables + +For agents using `.env` files: + +```bash +SENSOR_SERVER="ws://your-domain.com/agentapi/" +``` diff --git a/server/data/sensors.db b/server/data/sensors.db deleted file mode 100644 index c269d1f..0000000 Binary files a/server/data/sensors.db and /dev/null differ diff --git a/server/data/sensors.db-shm b/server/data/sensors.db-shm deleted file mode 100644 index 536aeac..0000000 Binary files a/server/data/sensors.db-shm and /dev/null differ diff --git a/server/data/sensors.db-wal b/server/data/sensors.db-wal deleted file mode 100644 index c478dba..0000000 Binary files a/server/data/sensors.db-wal and /dev/null differ