SPORE API Client
A JavaScript client for the SPORE Embedded System API, generated from the OpenAPI specification.
Installation
npm install
Usage
Basic Setup
const SporeApiClient = require('./index');
// Create client instance with default base URL
const client = new SporeApiClient();
// Or specify a custom base URL
const client = new SporeApiClient('http://192.168.1.100');
API Methods
Task Management
// Get comprehensive task status
const taskStatus = await client.getTaskStatus();
// Control individual tasks
await client.controlTask('heartbeat', 'disable');
await client.controlTask('discovery_send', 'start');
await client.controlTask('status_update', 'status');
System Status
// Get system status and API information
const systemStatus = await client.getSystemStatus();
// Get device information
const deviceInfo = await client.getDeviceInfo();
Cluster Management
// Get cluster discovery information
const discovery = await client.getClusterDiscovery();
// Get cluster status
const clusterStatus = await client.getClusterStatus();
Network Management
// Get network configuration
const networkConfig = await client.getNetworkConfig();
// Update network configuration
await client.updateNetworkConfig({
wifi: {
ssid: 'MyNetwork',
password: 'password123'
}
});
// Scan for WiFi networks
const networks = await client.getWifiNetworks();
// Connect to WiFi network
await client.connectWifi('MyNetwork', 'password123');
System Health
// Get OTA update status
const otaStatus = await client.getOtaStatus();
// Get health metrics
const healthMetrics = await client.getHealthMetrics();
// Get system logs
const logs = await client.getSystemLogs({
level: 'INFO',
limit: 100,
offset: 0
});
Device Control
// Restart the device
await client.restartDevice();
// Factory reset (use with caution!)
await client.factoryReset();
Error Handling
try {
const status = await client.getTaskStatus();
console.log('Task status:', status);
} catch (error) {
console.error('API request failed:', error.message);
}
Response Format
All API methods return promises that resolve to the response data. The client automatically:
- Parses JSON responses
- Handles HTTP error status codes
- Provides meaningful error messages
- Supports both CommonJS and ES modules
API Endpoints
The client supports all endpoints defined in the OpenAPI specification:
- Task Management:
/api/tasks/status,/api/tasks/control - System Status:
/api/node/status - Cluster Management:
/api/cluster/discovery,/api/cluster/status - OTA Updates:
/api/ota/status - Health Monitoring:
/api/health/metrics - System Logs:
/api/system/logs - Network Management:
/api/network/config,/api/network/wifi/* - Device Control:
/api/device/info,/api/device/restart,/api/device/factory-reset
Requirements
- Node.js 18.0.0 or higher
- Fetch API support (built-in for Node.js 18+)
License
MIT License - see LICENSE file for details.