Overview
Slot switching allows devices to automatically failover between primary and secondary network connections based on health check results. This is essential for high-availability IoT deployments.Key features
- Automatic health monitoring every 30 seconds
- Failover after 2 consecutive failures
- Automatic recovery when failed slot becomes healthy
- Manual slot switching via API
- Real-time health status monitoring
- Automatic stream URL updates
Configuration
Configure primary connection
Set up the device’s primary connection details:
- Host: Primary IP address or hostname
- Phone: Primary phone number (optional)
Configure secondary connection
Provide the secondary connection details:
- Secondary Host: Backup IP address or hostname
- Secondary Phone: Backup phone number (optional)
Enable automatic slot switching
Enable “Enable automatic slot switching” to activate health monitoring and automatic failover.
Environment variables
Configure the Switcher service with these environment variables:How it works
Health check process
Device discovery
Every 30 seconds (configurable), the service finds all devices with:
autoSlotSwitchenabled- Secondary slot configured
Health testing
For each device, the service:
- Executes the
slot-checkaction against the current active host - Records success or failure
- Tracks consecutive failure count
Failure detection
When a slot fails health checks:
- Failure counter increments
- After 2 consecutive failures, failover is triggered
Automatic switching
On failover:
- System checks alternate slot health
- If healthy, updates
activeSlotfield in database - PocketBase hook detects change and updates stream URLs
- Notification sent about slot change
- Failure counter resets
Failover scenarios
Primary slot failure- Primary slot health check fails
- Failure counter increments (now at 1)
- Next check fails again (counter at 2)
- System checks secondary slot health
- If secondary is healthy, switches to secondary slot
- Stream URLs updated to use
secondSlotHost - Users receive notification about slot change
- System continues health checks on both slots
- Original failed slot becomes healthy again
- System can switch back to primary slot
- Seamless transition with minimal interruption
Manual slot switching
You can manually switch slots without waiting for automatic failover:Health status monitoring
Check device health
Get real-time health status for a specific device:Check all devices
Get health status for all monitored devices:Trigger manual health check
Force an immediate health check for all devices:Frontend integration
The Joystick frontend includes built-in slot health indicators:SlotHealthIndicator component
- Shows active slot with visual indicators
- Displays health status of both primary and secondary slots
- Auto-refreshes every 30 seconds
- Integrated into device actions area
Configuration UI
- Checkbox to enable automatic slot switching
- Located in secondary slot configuration section
- Only visible when secondary slot is configured
- Real-time validation of slot configuration
Stream URL updates
When the active slot changes, stream URLs are automatically updated through PocketBase hooks:URL construction
System constructs new stream URL using:
hostfield for primary slotsecondSlotHostfield for secondary slot
Testing
Test automatic failover
Verify failover
After 2 failed checks (~60 seconds), verify:
- Active slot changed to “secondary”
- Stream is using secondary host
- Notification was sent
Test script
Use the provided test script:- Service health endpoints
- Manual slot switching
- Health check triggers
- Device status queries
Monitoring and logging
Switcher service logs
The Switcher service provides detailed logging:- Health check results for each device
- Slot switching events with timestamps
- Failure tracking and counters
- API request details
Health status dashboard
Monitor system-wide status:Troubleshooting
Health checks not running
-
Verify health checks are enabled:
-
Check Switcher service logs for errors:
-
Ensure devices have
autoSlotSwitchenabled:
Slot switching not working
-
Verify secondary slot is configured:
-
Check
slot-checkaction exists: -
Verify API connectivity between services:
-
Check API key is correct:
UI not showing slot status
-
Check Switcher health endpoint accessibility:
- Verify device has both slots configured
-
Ensure
autoSlotSwitchis enabled - Check browser console for API errors
False positive failures
-
Increase health check timeout:
- Adjust failure threshold (requires code change)
-
Review
slot-checkaction command - it may be too strict - Check network latency between Switcher and devices
Security considerations
- Health checks use same authentication as other device actions
- API key required for inter-service communication
- Slot switching requires appropriate permissions
- All changes are logged and auditable
- Failed authentication attempts are logged
Performance impact
- Health checks run every 30 seconds by default
- Minimal network overhead (simple ping-like tests)
- Failover typically completes within 1-2 check cycles (~30-60 seconds)
- No impact on streaming performance during normal operation
- Database updates only occur when slots actually change