API Backend
Connects to an OpenEMS Backend server and sends all Channel data regularly. This controller manages the bidirectional communication between the Edge and Backend, enabling remote monitoring, control, and configuration updates.
Overview
The API Backend controller is implemented as a WebSocket client that maintains a persistent connection to an OpenEMS Backend server. It handles:
-
Channel Data Transmission: Sends all Edge channel values at configurable persistence priority levels
-
Command Reception: Receives and executes control commands from the Backend
-
Historic Data Resending: Automatically resends missed data when connection is restored
-
Configuration Updates: Notifies Backend of any Edge configuration changes
-
Request/Response Handling: Processes JSON-RPC requests from Backend via specialized handlers
-
Proxy support (HTTP/HTTPS/SOCKS)
-
Configurable data aggregation and persistence priorities
-
Automatic reconnection with exponential backoff
-
Historic data buffering and resending
-
Debug logging mode for troubleshooting
-
EventHandler integration for lifecycle management
Supported Connections
-
OpenEMS Backend (via WebSocket over TCP)
-
Proxy connections (HTTP, HTTPS, SOCKS protocols)
-
TLS/SSL encrypted connections
-
Custom URI configuration
Components
Controller.Api.Backend
Implements the main Backend API controller service that maintains WebSocket connection and handles all communication.
Controller.Api.Backend
| Channel ID | Description | Type |
|---|---|---|
|
Logs of write-commands via API worker |
String |
|
Warning when channel data cannot be sent to Backend |
State/Warning |
|
Timestamp of last successful historic data resend |
Long (seconds) |
|
Failure indicator for controller cycle execution |
State/Fault |
| Parameter | Description | Type | Default |
|---|---|---|---|
|
Unique component identifier |
String |
|
|
Human-readable component name |
String |
(component-id) |
|
Enable/disable the controller |
Boolean |
|
|
API key for Backend authentication (required) |
Password |
(required) |
|
Backend WebSocket URI (e.g., wss://backend.example.com:8080) |
String |
(empty) |
|
Proxy server IP or hostname |
String |
(empty) |
|
Proxy server port |
Integer |
|
|
Proxy protocol type (HTTP, HTTPS, SOCKS) |
String |
|
|
Timeout for Backend-set channel updates (seconds) |
Integer |
|
|
Minimum persistence priority for regular channel updates |
Enum |
|
|
Minimum persistence priority for aggregated values |
Enum |
|
|
Minimum persistence priority for historic resend |
Enum |
|
|
Enable verbose debug logging |
Boolean |
|
WebSocket Communication Model
The controller operates in a pull-push model:
-
After Cycle: Each cycle, channel values meeting persistence priority threshold are collected
-
Aggregation: Values are optionally aggregated over time before transmission
-
Transmission: Data is sent as JSON-RPC notifications to Backend
Persistence Priority System
The controller uses a hierarchy to control which channels are sent:
| Priority | Usage |
|---|---|
|
Always sent (connection status, critical errors) |
|
Regular monitoring (power values, SOC, temperatures) |
|
Diagnostic data (efficiency metrics, ramp rates) |
|
Statistical data (aggregated values, trends) |
Configure persistencePriority to filter which channels are transmitted on every cycle.
Lower priority channels can be aggregated and sent less frequently via aggregationPriority.
Historic Data Resending
When the Edge loses connection to Backend:
-
Channel data is buffered locally with timestamps
-
Upon reconnection, the controller attempts to resend buffered data
-
ResendHistoricDataWorkerprocesses historic batches -
Only channels matching
resendPriorityare included -
lastSuccessfulResendchannel marks the latest timestamp
This ensures no data loss during brief connection interruptions.
Error Handling
The controller implements automatic recovery:
| Error | Handling Strategy |
|---|---|
Connection Lost |
Automatic reconnection with exponential backoff (max ~5 min) |
Backend Timeout |
Channel update timeout ( |
Invalid Command |
Logged to |
Proxy Unavailable |
Connection attempt retries with backoff |
Serialization Error |
Logged as warning, data skipped, cycle continues |
When unable to send data, the unableToSend warning channel is set and persisted for diagnosis.
For high-frequency data (>100 channels), consider increasing cycle time or enabling aggregation.