feat: serve static files, relay example
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
# Relay Service Example
|
||||
|
||||
A minimal example that demonstrates the Spore framework with a custom RelayService. The Spore framework automatically handles all core functionality (WiFi, clustering, API server, task management) while allowing easy registration of custom services.
|
||||
A minimal example that demonstrates the Spore framework with a custom RelayService and web interface. The Spore framework automatically handles all core functionality (WiFi, clustering, API server, task management) while allowing easy registration of custom services.
|
||||
|
||||
## Features
|
||||
|
||||
- **API Control**: RESTful API endpoints for programmatic control
|
||||
- **Web Interface**: Beautiful web UI for manual control at `http://<device-ip>/relay.html`
|
||||
- **Real-time Status**: Live status updates and visual feedback
|
||||
- **Toggle Functionality**: One-click toggle between ON/OFF states
|
||||
|
||||
- Default relay pin: `GPIO0` (ESP-01). Override with `-DRELAY_PIN=<pin>`.
|
||||
- WiFi and API port are configured in `src/Config.cpp`.
|
||||
@@ -25,7 +32,7 @@ RelayService* relayService = nullptr;
|
||||
void setup() {
|
||||
spore.setup();
|
||||
|
||||
relayService = new RelayService(spore.getTaskManager(), RELAY_PIN);
|
||||
relayService = new RelayService(spore.getContext(), spore.getTaskManager(), RELAY_PIN);
|
||||
spore.addService(relayService);
|
||||
|
||||
spore.begin();
|
||||
@@ -42,6 +49,7 @@ The Spore framework automatically provides:
|
||||
- REST API server with core endpoints
|
||||
- Task scheduling and execution
|
||||
- Node status monitoring
|
||||
- Static file serving for web interfaces (core service)
|
||||
|
||||
## Build & Upload
|
||||
|
||||
@@ -61,6 +69,20 @@ pio device monitor -b 115200
|
||||
|
||||
Assume the device IP is 192.168.1.50 below (replace with your device's IP shown in serial output).
|
||||
|
||||
## Web Interface
|
||||
|
||||
The web interface is located in the `data/` folder and will be served by the core StaticFileService.
|
||||
|
||||
Access the web interface at: `http://192.168.1.50/relay.html`
|
||||
|
||||
The web interface provides:
|
||||
- Visual status indicator (red for OFF, green for ON)
|
||||
- Turn ON/OFF buttons
|
||||
- Toggle button for quick switching
|
||||
- Real-time status updates every 2 seconds
|
||||
- Uptime display
|
||||
- Error handling and user feedback
|
||||
|
||||
## Relay API
|
||||
|
||||
- Get relay status
|
||||
|
||||
Reference in New Issue
Block a user