benchlab-pytools 3.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- benchlab/__init__.py +14 -0
- benchlab/__main__.py +21 -0
- benchlab/config/README.md +325 -0
- benchlab/config/__init__.py +9 -0
- benchlab/config/config_client.py +631 -0
- benchlab/config/config_manager.py +495 -0
- benchlab/config/config_tool.py +358 -0
- benchlab/config/diff.py +163 -0
- benchlab/config/examples/complete_config.json +56 -0
- benchlab/config/examples/rgb_lighting.json +24 -0
- benchlab/config/examples/simple_fan.json +32 -0
- benchlab/config/schema.py +138 -0
- benchlab/core/README.md +154 -0
- benchlab/core/__init__.py +78 -0
- benchlab/core/config.py +145 -0
- benchlab/core/datasource.py +1209 -0
- benchlab/core/datasource_manager.py +418 -0
- benchlab/core/device_registry.py +206 -0
- benchlab/core/discovery.py +92 -0
- benchlab/core/infrastructure.py +309 -0
- benchlab/core/process_manager.py +356 -0
- benchlab/core/retry.py +85 -0
- benchlab/core/shared_serial.py +235 -0
- benchlab/core/statistics.py +224 -0
- benchlab/csv_log/README.md +206 -0
- benchlab/csv_log/__init__.py +5 -0
- benchlab/csv_log/csv_logger_enhanced.py +416 -0
- benchlab/csv_log/message_batcher.py +361 -0
- benchlab/csv_log/requirements.txt +3 -0
- benchlab/csv_log/smart_retry.py +466 -0
- benchlab/graph/README.md +117 -0
- benchlab/graph/__init__.py +5 -0
- benchlab/graph/app.py +353 -0
- benchlab/graph/requirements.txt +2 -0
- benchlab/graph/runner.py +42 -0
- benchlab/graph/ui.py +288 -0
- benchlab/hwinfo/README.md +135 -0
- benchlab/hwinfo/__init__.py +5 -0
- benchlab/hwinfo/hwinfo_export.py +386 -0
- benchlab/hwinfo/requirements.txt +1 -0
- benchlab/launcher.py +387 -0
- benchlab/link/.env.EXAMPLE +10 -0
- benchlab/link/README.md +172 -0
- benchlab/link/__init__.py +1 -0
- benchlab/link/link_main.py +479 -0
- benchlab/main.py +462 -0
- benchlab/menu.py +729 -0
- benchlab/menu_classic.py +410 -0
- benchlab/mqtt/README.md +201 -0
- benchlab/mqtt/__init__.py +5 -0
- benchlab/mqtt/mqtt.config_template +2 -0
- benchlab/mqtt/mqtt_publisher.py +540 -0
- benchlab/mqtt/requirements.txt +3 -0
- benchlab/prefs.py +67 -0
- benchlab/restapi/.env.example +17 -0
- benchlab/restapi/__init__.py +5 -0
- benchlab/restapi/favicon.ico +0 -0
- benchlab/restapi/readme.md +202 -0
- benchlab/restapi/requirements.txt +5 -0
- benchlab/restapi/telemetry_api.py +808 -0
- benchlab/sources.py +515 -0
- benchlab/tools.py +147 -0
- benchlab/tui/README.md +266 -0
- benchlab/tui/__init__.py +5 -0
- benchlab/tui/config.py +477 -0
- benchlab/tui/requirements.txt +2 -0
- benchlab/tui/tui_core.py +1298 -0
- benchlab/tui/tui_main.py +418 -0
- benchlab/vu/README.md +64 -0
- benchlab/vu/VU-Server/NOTICE.md +13 -0
- benchlab/vu/VU-Server/README.md +80 -0
- benchlab/vu/VU-Server/Running_from_source_on_linux.md +97 -0
- benchlab/vu/VU-Server/__init__.py +0 -0
- benchlab/vu/VU-Server/assets/vu1_hello_world.png +0 -0
- benchlab/vu/VU-Server/community_applications.md +13 -0
- benchlab/vu/VU-Server/config.yaml +9 -0
- benchlab/vu/VU-Server/database.py +256 -0
- benchlab/vu/VU-Server/dial_driver.py +534 -0
- benchlab/vu/VU-Server/dials/Comms_Hub_Gauge.py +78 -0
- benchlab/vu/VU-Server/dials/Comms_Hub_Server.py +100 -0
- benchlab/vu/VU-Server/dials/__init__.py +0 -0
- benchlab/vu/VU-Server/dials/base_logger.py +100 -0
- benchlab/vu/VU-Server/installer/inc/icon.ico +0 -0
- benchlab/vu/VU-Server/installer/install.nsi +148 -0
- benchlab/vu/VU-Server/make_version.py +40 -0
- benchlab/vu/VU-Server/pylintrc +628 -0
- benchlab/vu/VU-Server/requirements.txt +9 -0
- benchlab/vu/VU-Server/serial_driver.py +244 -0
- benchlab/vu/VU-Server/server.py +670 -0
- benchlab/vu/VU-Server/server_config.py +255 -0
- benchlab/vu/VU-Server/server_dial_handler.py +334 -0
- benchlab/vu/VU-Server/vu_notifications.py +24 -0
- benchlab/vu/VU-Server/www/android-chrome-192x192.png +0 -0
- benchlab/vu/VU-Server/www/android-chrome-512x512.png +0 -0
- benchlab/vu/VU-Server/www/apple-touch-icon.png +0 -0
- benchlab/vu/VU-Server/www/assets/css/demo.css +291 -0
- benchlab/vu/VU-Server/www/assets/css/demo.min.css +9 -0
- benchlab/vu/VU-Server/www/assets/css/demo.rtl.css +276 -0
- benchlab/vu/VU-Server/www/assets/css/demo.rtl.min.css +9 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-flags.css +1084 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-flags.min.css +9 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-flags.rtl.css +1084 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-flags.rtl.min.css +9 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-payments.css +528 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-payments.min.css +9 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-payments.rtl.css +528 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-payments.rtl.min.css +9 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-social.css +10 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-social.min.css +8 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-social.rtl.css +10 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-social.rtl.min.css +8 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-vendors.css +1504 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-vendors.min.css +9 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-vendors.rtl.css +1504 -0
- benchlab/vu/VU-Server/www/assets/css/tabler-vendors.rtl.min.css +9 -0
- benchlab/vu/VU-Server/www/assets/css/tabler.css +25813 -0
- benchlab/vu/VU-Server/www/assets/css/tabler.min.css +13 -0
- benchlab/vu/VU-Server/www/assets/css/tabler.rtl.css +25777 -0
- benchlab/vu/VU-Server/www/assets/css/tabler.rtl.min.css +13 -0
- benchlab/vu/VU-Server/www/assets/css/theme.min.css +261 -0
- benchlab/vu/VU-Server/www/assets/img/header.png +0 -0
- benchlab/vu/VU-Server/www/assets/img/logo.png +0 -0
- benchlab/vu/VU-Server/www/assets/js/dark-theme.js +35 -0
- benchlab/vu/VU-Server/www/assets/js/dark-theme.min.js +9 -0
- benchlab/vu/VU-Server/www/assets/js/demo.js +132 -0
- benchlab/vu/VU-Server/www/assets/js/demo.min.js +9 -0
- benchlab/vu/VU-Server/www/assets/js/jquery.min.js +2 -0
- benchlab/vu/VU-Server/www/assets/js/tabler.esm.js +7482 -0
- benchlab/vu/VU-Server/www/assets/js/tabler.esm.min.js +15 -0
- benchlab/vu/VU-Server/www/assets/js/tabler.js +7543 -0
- benchlab/vu/VU-Server/www/assets/js/tabler.min.js +15 -0
- benchlab/vu/VU-Server/www/assets/js/vu1_api.js +68 -0
- benchlab/vu/VU-Server/www/assets/js/vu1_gui_api_key_settings.js +167 -0
- benchlab/vu/VU-Server/www/assets/js/vu1_gui_api_keys.js +138 -0
- benchlab/vu/VU-Server/www/assets/js/vu1_gui_dial.js +179 -0
- benchlab/vu/VU-Server/www/assets/js/vu1_gui_home.js +60 -0
- benchlab/vu/VU-Server/www/assets/js/vu1_gui_root.js +125 -0
- benchlab/vu/VU-Server/www/favicon-16x16.png +0 -0
- benchlab/vu/VU-Server/www/favicon-32x32.png +0 -0
- benchlab/vu/VU-Server/www/favicon.ico +0 -0
- benchlab/vu/VU-Server/www/favicon.png +0 -0
- benchlab/vu/VU-Server/www/index.html +47 -0
- benchlab/vu/VU-Server/www/views/api_keys.html +151 -0
- benchlab/vu/VU-Server/www/views/dial.html +286 -0
- benchlab/vu/VU-Server/www/views/footer.html +27 -0
- benchlab/vu/VU-Server/www/views/header.html +86 -0
- benchlab/vu/VU-Server/www/views/key_settings.html +132 -0
- benchlab/vu/VU-Server/www/views/start.html +124 -0
- benchlab/vu/__init__.py +5 -0
- benchlab/vu/assets/Barlow-Bold.ttf +0 -0
- benchlab/vu/assets/bl_dial_144x200.png +0 -0
- benchlab/vu/assets/bl_logo_144x200.png +0 -0
- benchlab/vu/devices.py +166 -0
- benchlab/vu/requirements.txt +24 -0
- benchlab/vu/sensors.py +18 -0
- benchlab/vu/vu_dial.config_template +90 -0
- benchlab/vu/vu_logo_gen.py +97 -0
- benchlab/vu/vu_server.config_template +5 -0
- benchlab/vu/vu_server_config.py +40 -0
- benchlab/vu/vu_server_manager.py +192 -0
- benchlab/vu/vu_tui.py +919 -0
- benchlab/vu/vu_updater.py +540 -0
- benchlab/wigidash/README.md +182 -0
- benchlab/wigidash/__init__.py +5 -0
- benchlab/wigidash/assets/Inter-Bold.ttf +0 -0
- benchlab/wigidash/assets/Inter.ttf +0 -0
- benchlab/wigidash/assets/benchlab.png +0 -0
- benchlab/wigidash/benchlab_fleet.py +150 -0
- benchlab/wigidash/benchlab_graph.py +517 -0
- benchlab/wigidash/benchlab_overview.py +426 -0
- benchlab/wigidash/benchlab_telemetry.py +105 -0
- benchlab/wigidash/benchlab_ui.py +190 -0
- benchlab/wigidash/benchlab_utils.py +182 -0
- benchlab/wigidash/requirements.txt +9 -0
- benchlab/wigidash/wigidash_device.py +541 -0
- benchlab/wigidash/wigidash_manager.py +342 -0
- benchlab/wigidash/wigidash_session.py +355 -0
- benchlab/wigidash/wigidash_usb.py +247 -0
- benchlab/wigidash/wigidash_widget.py +88 -0
- benchlab_pytools-3.0.0.dist-info/METADATA +239 -0
- benchlab_pytools-3.0.0.dist-info/RECORD +184 -0
- benchlab_pytools-3.0.0.dist-info/WHEEL +4 -0
- benchlab_pytools-3.0.0.dist-info/entry_points.txt +2 -0
- benchlab_pytools-3.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# BenchLab FastAPI Telemetry Server
|
|
2
|
+
|
|
3
|
+
A lightweight, cross-platform REST API server for BenchLab telemetry data collection and monitoring.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
### ✨ Core Improvements
|
|
8
|
+
- **Cross-platform device discovery** - Automatically detects BenchLab devices on Windows, Linux, and macOS
|
|
9
|
+
- **Robust error handling** - Comprehensive error handling and logging for production use
|
|
10
|
+
- **Configuration management** - Environment-based configuration with validation
|
|
11
|
+
- **Health monitoring** - Built-in health check and status endpoints
|
|
12
|
+
- **CORS support** - Ready for web client integration
|
|
13
|
+
|
|
14
|
+
### 🚀 Performance Enhancements
|
|
15
|
+
- **Efficient data streaming** - WebSocket support for real-time telemetry updates
|
|
16
|
+
- **Configurable polling** - Adjustable sensor read intervals (minimum 0.1s)
|
|
17
|
+
- **History management** - Configurable history buffer with pagination
|
|
18
|
+
- **Connection pooling** - Optimized serial connection management
|
|
19
|
+
|
|
20
|
+
### 🛡️ Reliability Features
|
|
21
|
+
- **Graceful shutdown** - Proper cleanup of threads and connections
|
|
22
|
+
- **Device reconnection** - Automatic handling of device disconnects/reconnects
|
|
23
|
+
- **Validation** - Input validation and configuration checks
|
|
24
|
+
- **Logging** - Structured logging with configurable levels
|
|
25
|
+
|
|
26
|
+
## Quick Start
|
|
27
|
+
|
|
28
|
+
### 1. Installation
|
|
29
|
+
```bash
|
|
30
|
+
pip install -r requirements.txt
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 2. Configuration
|
|
34
|
+
Optionally create a `.env` file in `benchlab/restapi/` to override defaults (see Configuration Options below). All settings also work as plain environment variables.
|
|
35
|
+
|
|
36
|
+
### 3. Run the Server
|
|
37
|
+
```bash
|
|
38
|
+
python -m benchlab -fastapi
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
You can also run the module directly:
|
|
42
|
+
```bash
|
|
43
|
+
python -m benchlab.restapi.telemetry_api
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The server will start on `http://0.0.0.0:8000` by default (configurable via `API_HOST`/`API_PORT`).
|
|
47
|
+
|
|
48
|
+
## API Endpoints
|
|
49
|
+
|
|
50
|
+
### Device Management
|
|
51
|
+
- `GET /devices` - List all connected devices (uid, port, firmware, variant, VendorId, ProductId, connected)
|
|
52
|
+
- `GET /device/{uid}/info` - Get device information (returns mock info with 404-style defaults if the uid isn't known, for test convenience)
|
|
53
|
+
- `GET /device/{uid}/status` - Get detailed status for a specific device (port, connected, last_update, client_count, history_count, latest_telemetry, info)
|
|
54
|
+
- `POST /scan` - Trigger an immediate device scan (discovers new devices, marks disconnected ones) without restarting the server
|
|
55
|
+
|
|
56
|
+
### Telemetry Data
|
|
57
|
+
- `GET /device/{uid}/telemetry` - Get latest telemetry snapshot for a device
|
|
58
|
+
- `GET /device/{uid}/telemetry/{sensor}` - Get a single sensor's latest value
|
|
59
|
+
- `GET /device/{uid}/history?limit=100` - Get telemetry history (most recent `limit` entries, capped by `MAX_HISTORY_LIMIT`); response includes `device_id`, `data`, `count`, `total_available`
|
|
60
|
+
- `GET /device/{uid}/sensors` - List available sensor keys for a device
|
|
61
|
+
|
|
62
|
+
### Real-time Streaming
|
|
63
|
+
- `WebSocket /device/{uid}/stream` - Real-time telemetry updates, pushed as each device's reader thread reads new sensor data
|
|
64
|
+
|
|
65
|
+
### Monitoring
|
|
66
|
+
- `GET /health` - Basic health check (status, platform, timestamp, connected_devices, total_clients)
|
|
67
|
+
- `GET /status` - Detailed server status for all devices
|
|
68
|
+
- `GET /favicon.ico` - Server favicon
|
|
69
|
+
|
|
70
|
+
All endpoints for an unknown `{uid}` return `404` (except `/device/{uid}/info`, which returns mock placeholder data instead).
|
|
71
|
+
|
|
72
|
+
A background scanner thread re-scans for new/disconnected devices every `SCAN_INTERVAL` seconds automatically, in addition to the manual `POST /scan` endpoint.
|
|
73
|
+
|
|
74
|
+
## Configuration Options
|
|
75
|
+
|
|
76
|
+
| Variable | Default | Description |
|
|
77
|
+
|----------|---------|-------------|
|
|
78
|
+
| `API_HOST` | `0.0.0.0` | Server bind address |
|
|
79
|
+
| `API_PORT` | `8000` | Server port (1-65535) |
|
|
80
|
+
| `LOG_LEVEL` | `INFO` | Logging level |
|
|
81
|
+
| `POLL_INTERVAL` | `1.0` | Sensor read interval in seconds (min 0.1) |
|
|
82
|
+
| `HISTORY_LENGTH` | `10` | Number of history entries per device |
|
|
83
|
+
| `MAX_HISTORY_LIMIT` | `1000` | Max history limit for API requests |
|
|
84
|
+
| `SCAN_INTERVAL` | `30` | Device discovery scan interval in seconds |
|
|
85
|
+
| `CORS_ORIGINS` | `*` | Comma-separated allowed CORS origins. Credentialed requests are only allowed when explicit origins are set (wildcard + credentials is rejected by browsers) |
|
|
86
|
+
|
|
87
|
+
## Cross-Platform Support
|
|
88
|
+
|
|
89
|
+
The server automatically detects and works with BenchLab devices across different platforms:
|
|
90
|
+
|
|
91
|
+
- **Windows**: COM1-COM9 ports
|
|
92
|
+
- **Linux**: `/dev/ttyUSB*`, `/dev/ttyACM*`, `/dev/ttyS*` ports
|
|
93
|
+
- **macOS**: `/dev/tty.*` ports
|
|
94
|
+
|
|
95
|
+
## Testing
|
|
96
|
+
|
|
97
|
+
Run the test suite to verify the server functionality:
|
|
98
|
+
```bash
|
|
99
|
+
python -m pytest benchlab/restapi/test_server.py
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
This tests:
|
|
103
|
+
- Server startup and configuration
|
|
104
|
+
- API endpoint registration
|
|
105
|
+
- Cross-platform device detection
|
|
106
|
+
- Error handling and validation
|
|
107
|
+
|
|
108
|
+
## Usage Examples
|
|
109
|
+
|
|
110
|
+
### Get Device List
|
|
111
|
+
```bash
|
|
112
|
+
curl http://localhost:8000/devices
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Get Latest Telemetry
|
|
116
|
+
```bash
|
|
117
|
+
curl http://localhost:8000/device/ABC123/telemetry
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Get Sensor History
|
|
121
|
+
```bash
|
|
122
|
+
curl "http://localhost:8000/device/ABC123/history?limit=50"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Real-time Streaming (WebSocket)
|
|
126
|
+
```javascript
|
|
127
|
+
const ws = new WebSocket('ws://localhost:8000/device/ABC123/stream');
|
|
128
|
+
ws.onmessage = (event) => {
|
|
129
|
+
const data = JSON.parse(event.data);
|
|
130
|
+
console.log('Telemetry update:', data);
|
|
131
|
+
};
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Production Deployment
|
|
135
|
+
|
|
136
|
+
### Docker Support
|
|
137
|
+
The server is designed for containerization:
|
|
138
|
+
```dockerfile
|
|
139
|
+
FROM python:3.9-slim
|
|
140
|
+
COPY requirements.txt .
|
|
141
|
+
RUN pip install -r requirements.txt
|
|
142
|
+
COPY . .
|
|
143
|
+
CMD ["python", "-m", "benchlab.restapi.telemetry_api"]
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Systemd Service (Linux)
|
|
147
|
+
Create `/etc/systemd/system/benchlab-api.service`:
|
|
148
|
+
```ini
|
|
149
|
+
[Unit]
|
|
150
|
+
Description=BenchLab Telemetry API
|
|
151
|
+
After=network.target
|
|
152
|
+
|
|
153
|
+
[Service]
|
|
154
|
+
Type=simple
|
|
155
|
+
User=benchlab
|
|
156
|
+
WorkingDirectory=/opt/benchlab
|
|
157
|
+
ExecStart=/usr/bin/python3 -m benchlab.restapi.telemetry_api
|
|
158
|
+
Restart=always
|
|
159
|
+
|
|
160
|
+
[Install]
|
|
161
|
+
WantedBy=multi-user.target
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Troubleshooting
|
|
165
|
+
|
|
166
|
+
### Common Issues
|
|
167
|
+
|
|
168
|
+
1. **No devices found**
|
|
169
|
+
- Check USB connections
|
|
170
|
+
- Verify device firmware
|
|
171
|
+
- Check serial port permissions
|
|
172
|
+
|
|
173
|
+
2. **Permission errors**
|
|
174
|
+
- On Linux, add user to `dialout` group: `sudo usermod -a -G dialout $USER`
|
|
175
|
+
- Restart terminal or reboot after group changes
|
|
176
|
+
|
|
177
|
+
3. **Port binding errors**
|
|
178
|
+
- Check if port is already in use
|
|
179
|
+
- Try a different port in configuration
|
|
180
|
+
|
|
181
|
+
### Logging
|
|
182
|
+
Enable debug logging for troubleshooting:
|
|
183
|
+
```bash
|
|
184
|
+
LOG_LEVEL=DEBUG python -m benchlab -fastapi
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Development
|
|
188
|
+
|
|
189
|
+
### Adding New Endpoints
|
|
190
|
+
1. Add the endpoint function in `telemetry_api.py`
|
|
191
|
+
2. Use FastAPI decorators (`@app.get`, `@app.post`, etc.)
|
|
192
|
+
3. Add proper error handling and validation
|
|
193
|
+
4. Update this README with new endpoints
|
|
194
|
+
|
|
195
|
+
### Testing Changes
|
|
196
|
+
1. Run the test suite: `python test_server.py`
|
|
197
|
+
2. Test manually with curl or a REST client
|
|
198
|
+
3. Verify WebSocket functionality
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
This project is part of the BenchLab suite. See the main project license for details.
|