feat: services (#2)
This commit is contained in:
301
docs/API.md
301
docs/API.md
@@ -16,10 +16,33 @@ The SPORE system provides a comprehensive RESTful API for monitoring and control
|
||||
| Endpoint | Method | Description | Response |
|
||||
|----------|--------|-------------|----------|
|
||||
| `/api/node/status` | GET | System resource information and API endpoint registry | System metrics and API catalog |
|
||||
| `/api/node/capabilities` | GET | API endpoint capabilities and parameters | Detailed endpoint specifications |
|
||||
| `/api/cluster/members` | GET | Cluster membership and node health information | Cluster topology and health status |
|
||||
| `/api/node/update` | POST | Handle firmware updates via OTA | Update progress and status |
|
||||
| `/api/node/restart` | POST | Trigger system restart | Restart confirmation |
|
||||
|
||||
### Network Management API
|
||||
|
||||
| Endpoint | Method | Description | Response |
|
||||
|----------|--------|-------------|----------|
|
||||
| `/api/network/status` | GET | WiFi and network status information | Network configuration and status |
|
||||
| `/api/network/wifi/scan` | GET | Get available WiFi networks | List of discovered networks |
|
||||
| `/api/network/wifi/scan` | POST | Trigger WiFi network scan | Scan initiation confirmation |
|
||||
| `/api/network/wifi/config` | POST | Configure WiFi connection | Connection status and result |
|
||||
|
||||
### Hardware Services API
|
||||
|
||||
| Endpoint | Method | Description | Response |
|
||||
|----------|--------|-------------|----------|
|
||||
| `/api/neopixel/status` | GET | NeoPixel LED strip status | LED configuration and state |
|
||||
| `/api/neopixel` | POST | NeoPixel pattern and color control | Control confirmation |
|
||||
| `/api/neopixel/patterns` | GET | Available LED patterns | List of supported patterns |
|
||||
| `/api/relay/status` | GET | Relay state and configuration | Relay pin and state |
|
||||
| `/api/relay` | POST | Relay control (on/off/toggle) | Control result |
|
||||
| `/api/neopattern/status` | GET | NeoPattern service status | Pattern configuration |
|
||||
| `/api/neopattern` | POST | Advanced LED pattern control | Control confirmation |
|
||||
| `/api/neopattern/patterns` | GET | Available pattern types | List of supported patterns |
|
||||
|
||||
## Detailed API Reference
|
||||
|
||||
### Task Management
|
||||
@@ -125,8 +148,67 @@ Returns comprehensive system resource information including memory usage, chip d
|
||||
- `sdkVersion`: ESP8266 SDK version
|
||||
- `cpuFreqMHz`: CPU frequency in MHz
|
||||
- `flashChipSize`: Flash chip size in bytes
|
||||
- `labels`: Node labels and metadata (if available)
|
||||
- `api`: Array of registered API endpoints
|
||||
|
||||
**Example Response:**
|
||||
```json
|
||||
{
|
||||
"freeHeap": 48748,
|
||||
"chipId": 12345678,
|
||||
"sdkVersion": "3.1.2",
|
||||
"cpuFreqMHz": 80,
|
||||
"flashChipSize": 1048576,
|
||||
"labels": {
|
||||
"location": "kitchen",
|
||||
"type": "sensor"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### GET /api/node/capabilities
|
||||
|
||||
Returns detailed information about all available API endpoints, including their parameters, types, and validation rules.
|
||||
|
||||
**Response Fields:**
|
||||
- `endpoints[]`: Array of endpoint capability objects
|
||||
- `uri`: Endpoint URI path
|
||||
- `method`: HTTP method (GET, POST, etc.)
|
||||
- `params[]`: Parameter specifications (if applicable)
|
||||
- `name`: Parameter name
|
||||
- `location`: Parameter location (body, query, etc.)
|
||||
- `required`: Whether parameter is required
|
||||
- `type`: Parameter data type
|
||||
- `values[]`: Allowed values (for enums)
|
||||
- `default`: Default value
|
||||
|
||||
**Example Response:**
|
||||
```json
|
||||
{
|
||||
"endpoints": [
|
||||
{
|
||||
"uri": "/api/tasks/control",
|
||||
"method": "POST",
|
||||
"params": [
|
||||
{
|
||||
"name": "task",
|
||||
"location": "body",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "action",
|
||||
"location": "body",
|
||||
"required": true,
|
||||
"type": "string",
|
||||
"values": ["enable", "disable", "start", "stop", "status"]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### GET /api/cluster/members
|
||||
|
||||
Returns information about all nodes in the cluster, including their health status, resources, and API endpoints.
|
||||
@@ -154,6 +236,225 @@ Initiates an over-the-air firmware update. The firmware file should be uploaded
|
||||
|
||||
Triggers a system restart. The response will be sent before the restart occurs.
|
||||
|
||||
### Network Management
|
||||
|
||||
#### GET /api/network/status
|
||||
|
||||
Returns comprehensive WiFi and network status information.
|
||||
|
||||
**Response Fields:**
|
||||
- `wifi.connected`: Whether WiFi is connected
|
||||
- `wifi.mode`: WiFi mode (STA or AP)
|
||||
- `wifi.ssid`: Connected network SSID
|
||||
- `wifi.ip`: Local IP address
|
||||
- `wifi.mac`: MAC address
|
||||
- `wifi.hostname`: Device hostname
|
||||
- `wifi.rssi`: Signal strength
|
||||
- `wifi.ap_ip`: Access point IP (if in AP mode)
|
||||
- `wifi.ap_mac`: Access point MAC (if in AP mode)
|
||||
- `wifi.stations_connected`: Number of connected stations (if in AP mode)
|
||||
|
||||
**Example Response:**
|
||||
```json
|
||||
{
|
||||
"wifi": {
|
||||
"connected": true,
|
||||
"mode": "STA",
|
||||
"ssid": "MyNetwork",
|
||||
"ip": "192.168.1.100",
|
||||
"mac": "AA:BB:CC:DD:EE:FF",
|
||||
"hostname": "spore-node-1",
|
||||
"rssi": -45
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### GET /api/network/wifi/scan
|
||||
|
||||
Returns a list of available WiFi networks discovered during the last scan.
|
||||
|
||||
**Response Fields:**
|
||||
- `access_points[]`: Array of discovered networks
|
||||
- `ssid`: Network name
|
||||
- `rssi`: Signal strength
|
||||
- `channel`: WiFi channel
|
||||
- `encryption_type`: Security type
|
||||
- `hidden`: Whether network is hidden
|
||||
- `bssid`: Network MAC address
|
||||
|
||||
**Example Response:**
|
||||
```json
|
||||
{
|
||||
"access_points": [
|
||||
{
|
||||
"ssid": "MyNetwork",
|
||||
"rssi": -45,
|
||||
"channel": 6,
|
||||
"encryption_type": 4,
|
||||
"hidden": false,
|
||||
"bssid": "AA:BB:CC:DD:EE:FF"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### POST /api/network/wifi/scan
|
||||
|
||||
Initiates a new WiFi network scan.
|
||||
|
||||
**Response:**
|
||||
```json
|
||||
{
|
||||
"status": "scanning",
|
||||
"message": "WiFi scan started"
|
||||
}
|
||||
```
|
||||
|
||||
#### POST /api/network/wifi/config
|
||||
|
||||
Configures WiFi connection with new credentials.
|
||||
|
||||
**Parameters:**
|
||||
- `ssid` (required): Network SSID
|
||||
- `password` (required): Network password
|
||||
- `connect_timeout_ms` (optional): Connection timeout in milliseconds (default: 10000)
|
||||
- `retry_delay_ms` (optional): Retry delay in milliseconds (default: 500)
|
||||
|
||||
**Response:**
|
||||
```json
|
||||
{
|
||||
"status": "success",
|
||||
"message": "WiFi configuration updated",
|
||||
"connected": true,
|
||||
"ip": "192.168.1.100"
|
||||
}
|
||||
```
|
||||
|
||||
### Hardware Services
|
||||
|
||||
#### NeoPixel LED Control
|
||||
|
||||
##### GET /api/neopixel/status
|
||||
|
||||
Returns current NeoPixel LED strip status and configuration.
|
||||
|
||||
**Response Fields:**
|
||||
- `pin`: GPIO pin number
|
||||
- `count`: Number of LEDs in strip
|
||||
- `interval_ms`: Update interval in milliseconds
|
||||
- `brightness`: Current brightness (0-255)
|
||||
- `pattern`: Current pattern name
|
||||
|
||||
**Example Response:**
|
||||
```json
|
||||
{
|
||||
"pin": 2,
|
||||
"count": 16,
|
||||
"interval_ms": 100,
|
||||
"brightness": 50,
|
||||
"pattern": "rainbow"
|
||||
}
|
||||
```
|
||||
|
||||
##### GET /api/neopixel/patterns
|
||||
|
||||
Returns list of available LED patterns.
|
||||
|
||||
**Response:**
|
||||
```json
|
||||
["off", "color_wipe", "rainbow", "rainbow_cycle", "theater_chase", "theater_chase_rainbow"]
|
||||
```
|
||||
|
||||
##### POST /api/neopixel
|
||||
|
||||
Controls NeoPixel LED strip patterns and colors.
|
||||
|
||||
**Parameters:**
|
||||
- `pattern` (optional): Pattern name
|
||||
- `interval_ms` (optional): Update interval in milliseconds
|
||||
- `brightness` (optional): Brightness level (0-255)
|
||||
- `color` (optional): Primary color (hex value)
|
||||
- `r`, `g`, `b` (optional): RGB color values
|
||||
- `color2` (optional): Secondary color (hex value)
|
||||
- `r2`, `g2`, `b2` (optional): Secondary RGB values
|
||||
|
||||
**Example Request:**
|
||||
```bash
|
||||
curl -X POST http://192.168.1.100/api/neopixel \
|
||||
-d "pattern=rainbow&brightness=100&interval_ms=50"
|
||||
```
|
||||
|
||||
#### Relay Control
|
||||
|
||||
##### GET /api/relay/status
|
||||
|
||||
Returns current relay status and configuration.
|
||||
|
||||
**Response Fields:**
|
||||
- `pin`: GPIO pin number
|
||||
- `state`: Current state (on/off)
|
||||
- `uptime`: System uptime in milliseconds
|
||||
|
||||
**Example Response:**
|
||||
```json
|
||||
{
|
||||
"pin": 5,
|
||||
"state": "off",
|
||||
"uptime": 12345
|
||||
}
|
||||
```
|
||||
|
||||
##### POST /api/relay
|
||||
|
||||
Controls relay state.
|
||||
|
||||
**Parameters:**
|
||||
- `state` (required): Desired state (on, off, toggle)
|
||||
|
||||
**Example Request:**
|
||||
```bash
|
||||
curl -X POST http://192.168.1.100/api/relay \
|
||||
-d "state=on"
|
||||
```
|
||||
|
||||
#### NeoPattern Service
|
||||
|
||||
##### GET /api/neopattern/status
|
||||
|
||||
Returns NeoPattern service status and configuration.
|
||||
|
||||
**Response Fields:**
|
||||
- `pin`: GPIO pin number
|
||||
- `count`: Number of LEDs
|
||||
- `interval_ms`: Update interval
|
||||
- `brightness`: Current brightness
|
||||
- `pattern`: Current pattern name
|
||||
- `total_steps`: Pattern step count
|
||||
- `color1`: Primary color
|
||||
- `color2`: Secondary color
|
||||
|
||||
##### GET /api/neopattern/patterns
|
||||
|
||||
Returns available pattern types.
|
||||
|
||||
**Response:**
|
||||
```json
|
||||
["off", "rainbow_cycle", "theater_chase", "color_wipe", "scanner", "fade", "fire"]
|
||||
```
|
||||
|
||||
##### POST /api/neopattern
|
||||
|
||||
Controls advanced LED patterns.
|
||||
|
||||
**Parameters:**
|
||||
- `pattern` (optional): Pattern name
|
||||
- `interval_ms` (optional): Update interval
|
||||
- `brightness` (optional): Brightness level
|
||||
- `color`, `color2` (optional): Color values
|
||||
- `r`, `g`, `b`, `r2`, `g2`, `b2` (optional): RGB values
|
||||
- `total_steps` (optional): Pattern step count
|
||||
- `direction` (optional): Pattern direction (forward/reverse)
|
||||
|
||||
## HTTP Status Codes
|
||||
|
||||
| Code | Description | Use Case |
|
||||
|
||||
Reference in New Issue
Block a user