Websockets


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=/; HttpOnly

Save 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

KeyTypeDescription
deviceobjectObject with uptime and time
banksarrayArray of WebSocket Bank Object(s)
inletsarrayArray of WebSocket Inlet Object(s)
outletsarrayArray of WebSocket Outlet Objects if applicable
sensorsarrayArray of Sensor Outlet Object(s) if connected

WebSocket Device Object

KeyTypeDescription
uptimenumberNumber of seconds the PDU has been on.
timestringTime in ISO8601 String Format.

WebSocket Bank Object

KeyTypeDescription
idstringUnique identifier for the bank
currentRmsnumberThe instantaneous current measured at the inlet in Amps
voltageRmsnumberInstantaneous voltage reading at inlet and all outlets in volts
lineFrequencynumberLine Frequency measurement valid from 45-65 GHz
powerFactornumberPower Factor reading. Value is signed value representing polarity of power factor
activePowernumberActive Power measured in KW (kiloWatts). Power consumed by electrical resistance
apparentPowernumberPower which is actually consumed or utilized
energyAccumulationnumberNumber of kilowatt hours accumulated. Can be used as billing unit for energy delivered
hasCircuitBreakerProtectionbooleantrue if PDU has circuit breaker protection.
circuitBreakerClosedbooleanState of circuit breakers. true if circuit breaker is closed and providing power correctly.

WebSocket Inlet Object

KeyTypeDescription
idstringUnique identifier for Inlet
inletTypestringDescribes configuration of specific Inlet Object. Either "single", "dual", or "ats".
inletPlugstringConnector type for Inlet
inletNamestringUser defined name for inlet
inletEnergyAccumulationnumberkWH 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

KeyTypeDescription
inletPowerFactornumberPower factor value for inlet plug
threePhaseBalancestringPercentage unbalance for 3 phase circuit
inletLinesarrayContains 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

KeyTypeDescription
inletCurrentRmsnumberInlet current draw in amps
inletVoltageRmsnumberInlet voltage RMS in volts
inletLineFrequencynumberInlet line frequency in hertz
inletPowerFactornumberPower factor ratio
inletActivePowernumberInlet Active Power in watts
inletApparentPowernumberInlet Apparent Power in Volt-amperes (VA)
inletLineConfigurationstringLine configuration for outlets connected to this inlet.

Is available when PDU is an ATS PDU

KeyTypeDescription
atsInletIdstringEither "A" or "B". Matches label on PDU.
atsInletActivebooleantrue if inlet is used to power outlets.
atsInletReadybooleantrue 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"
    },
    ...
  ]
}