feat: MQTT integration
This commit is contained in:
40
README.md
40
README.md
@@ -28,10 +28,42 @@ Options:
|
||||
HTTP server port (default "3001")
|
||||
-udp-port string
|
||||
UDP discovery port (default "4210")
|
||||
-mqtt string
|
||||
Enable MQTT integration with server URL (e.g., tcp://localhost:1883)
|
||||
-log-level string
|
||||
Log level (debug, info, warn, error) (default "info")
|
||||
```
|
||||
|
||||
### MQTT Integration
|
||||
|
||||
The gateway can integrate with an MQTT broker to subscribe to all MQTT topics and forward messages to connected WebSocket clients.
|
||||
|
||||
To enable MQTT integration:
|
||||
|
||||
```bash
|
||||
# Basic usage
|
||||
./spore-gateway -mqtt tcp://localhost:1883
|
||||
|
||||
# With authentication (using environment variables)
|
||||
MQTT_USER=username MQTT_PASSWORD=password ./spore-gateway -mqtt tcp://broker.example.com:1883
|
||||
```
|
||||
|
||||
When enabled, the gateway will:
|
||||
- Connect to the specified MQTT broker
|
||||
- Subscribe to all topics (`#`)
|
||||
- Forward all received messages to connected WebSocket clients with the format:
|
||||
```json
|
||||
{
|
||||
"topic": "sensor/temperature",
|
||||
"data": "{\"value\": 23.5}",
|
||||
"timestamp": "2024-01-15T10:30:00Z"
|
||||
}
|
||||
```
|
||||
|
||||
Environment variables:
|
||||
- `MQTT_USER`: Username for MQTT broker authentication (optional)
|
||||
- `MQTT_PASSWORD`: Password for MQTT broker authentication (optional)
|
||||
|
||||
## Integration
|
||||
|
||||
The spore-gateway works together with the SPORE UI frontend:
|
||||
@@ -94,11 +126,19 @@ The application follows the same patterns as the original Node.js spore-ui serve
|
||||
- HTTP middleware for CORS and logging
|
||||
- WebSocket support for real-time updates
|
||||
|
||||
## Documentation
|
||||
|
||||
See the `docs/` directory for detailed documentation:
|
||||
- [MQTT Integration](./docs/MQTT.md) - MQTT message forwarding and integration
|
||||
- [Rollout Process](./docs/Rollout.md) - Firmware rollout orchestration
|
||||
- [Testing Tools](./hack/README.md) - Local MQTT broker and testing scripts
|
||||
|
||||
## Architecture
|
||||
|
||||
- `main.go` - Application entry point
|
||||
- `internal/discovery/` - UDP-based node discovery
|
||||
- `internal/server/` - HTTP API server
|
||||
- `internal/websocket/` - WebSocket server for real-time updates
|
||||
- `internal/mqtt/` - MQTT client and message forwarding
|
||||
- `pkg/client/` - SPORE API client
|
||||
- `pkg/config/` - Configuration management
|
||||
|
||||
Reference in New Issue
Block a user