WebSocket
Authentication & Connection Flow
Before you can receive the WebSocket data stream, the connection must be authenticated with a session cookie obtained from the HTTP login endpoint.
1. Obtain a session cookie
Send a POST request to the PDU’s login endpoint with valid credentials.
Example (cURL)
curl -i \
-X POST "http://<PDU_IP>/api/login" \
-H "Content-Type: application/json" \
-d '{
"username": "<USERNAME>",
"password": "<PASSWORD>"
}'Look for the Set-Cookie header in the response:
Set-Cookie: SPID=23zc7Eloswmdt7ofjc; Path=/; HttpOnlySave the cookie string.
2. Open the WebSocket connection
ws://<PDU_IP>/ws
3. Authenticate by sending cookie
{"cookie": "SPID=23zc7Eloswmdt7ofjc"}Example Browser Flow
async function connectToPdu(ip, username, password) {
await fetch(`http://${ip}/api/login`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username, password }),
credentials: "include"
});
const ws = new WebSocket(`ws://${ip}/ws`);
ws.onopen = () => {
ws.send(JSON.stringify({ cookie: document.cookie }));
};
ws.onmessage = (event) => {
console.log("Data:", JSON.parse(event.data));
};
}WebSocket Data Stream
When successfully connected AND authenticated. SynLink PDU's will output a data stream onto a WebSocket with the following WebSocket Data Stream Object at a rate of once every 2 seconds.
WebSocket Data Stream Object
| Key | Type | Description |
|---|---|---|
| device | object | Object with uptime and time |
| banks | array | Array of WebSocket Bank Object(s) |
| inlets | array | Array of WebSocket Inlet Object(s) |
| outlets | array | Array of WebSocket Outlet Objects if applicable |
| sensors | array | Array of Sensor Outlet Object(s) if connected |
WebSocket Device Object
| Key | Type | Description |
|---|---|---|
| uptime | number | Number of seconds the PDU has been on. |
| time | string | Time in ISO8601 String Format. |
WebSocket Bank Object
| Key | Type | Description |
|---|---|---|
| id | string | Unique identifier for the bank |
| currentRms | number | The instantaneous current measured at the inlet in Amps |
| voltageRms | number | Instantaneous voltage reading at inlet and all outlets in volts |
| lineFrequency | number | Line Frequency measurement valid from 45-65 GHz |
| powerFactor | number | Power Factor reading. Value is signed value representing polarity of power factor |
| activePower | number | Active Power measured in KW (kiloWatts). Power consumed by electrical resistance |
| apparentPower | number | Power which is actually consumed or utilized |
| energyAccumulation | number | Number of kilowatt hours accumulated. Can be used as billing unit for energy delivered |
| hasCircuitBreakerProtection | boolean | true if PDU has circuit breaker protection. |
| circuitBreakerClosed | boolean | State of circuit breakers. true if circuit breaker is closed and providing power correctly. |
WebSocket Inlet Object
| Key | Type | Description |
|---|---|---|
| id | string | Unique identifier for Inlet |
| inletType | string | Describes configuration of specific Inlet Object. Either "single", "dual", or "ats". |
| inletPlug | string | Connector type for Inlet |
| inletName | string | User defined name for inlet |
| inletEnergyAccumulation | number | kWH value to show energy consumption for inlet plug. If multiple inlets, value will stay same for all inlets. |
Conditional WebSocket Inlet Object Attributes
Is available when PDU is a three phase PDU
| Key | Type | Description |
|---|---|---|
| inletPowerFactor | number | Power factor value for inlet plug |
| threePhaseBalance | string | Percentage unbalance for 3 phase circuit |
| inletLines | array | Contains 3 line objects, each with "currentRMS" in amps, unique "id", and "line" it is associated with. |
Is available when PDU is a single phase PDU
| Key | Type | Description |
|---|---|---|
| inletCurrentRms | number | Inlet current draw in amps |
| inletVoltageRms | number | Inlet voltage RMS in volts |
| inletLineFrequency | number | Inlet line frequency in hertz |
| inletPowerFactor | number | Power factor ratio |
| inletActivePower | number | Inlet Active Power in watts |
| inletApparentPower | number | Inlet Apparent Power in Volt-amperes (VA) |
| inletLineConfiguration | string | Line configuration for outlets connected to this inlet. |
Is available when PDU is an ATS PDU
| Key | Type | Description |
|---|---|---|
| atsInletId | string | Either "A" or "B". Matches label on PDU. |
| atsInletActive | boolean | true if inlet is used to power outlets. |
| atsInletReady | boolean | true if inlet has voltage potential |
Data Stream Object
{
"device": {
"uptime": 251362,
"time": "2012-01-03T22:34Z"
},
"banks": [
{
"id": 16777225,
"currentRms": 0.007400000002235174,
"voltageRms": 117.0999984741211,
"lineFrequency": 60.1879997253418,
"powerFactor": -0.465087890625,
"activePower": 0.4000000059604645,
"apparentPower": 0.8600000143051147,
"hasCircuitBreakerProtection": false,
"circuitBreakerClosed": true,
"energyAccumulation": 0
},
...
],
"inlets": [
{
"id": "I1-9826498",
"inletCurrentRms": 0.007400000002235174,
"inletVoltageRms": 117.0999984741211,
"inletLineFrequency": 60.1879997253418,
"inletPowerFactor": 0.4651162922382355,
"inletActivePower": 0.4000000059604645,
"inletApparentPower": 0.8600000143051147,
"inletEnergyAccumulation": 0
}
],
"outlets": [
{
"id": "1-16777225",
"currentRms": 0.16098617017269135,
"state": "ON",
"voltageDetection": true,
"relayHealth": "OK"
},
...
],
"sensors": [
{
"sensorPort": "B",
"sensorName": "Temperature & Humidity Sensor",
"sensorTempInC": 18.23232650756836,
"sensorTempInF": 64.81819152832031,
"sensorHumidity": 59.186912536621094,
"sensorType": "temp_hum"
},
...
]
}