WebSocket Server

FRM provides a WebSocket server that can be configured on a port of your choosing (Default: 8080). This is the same as the web server URL/Port.

Accessing the websocket server can be done via a browser that is using a WebSockets Tester (I recommend https://www.piesocket.com/websocket-tester). The default WebSocket connection is ws://<IP Address>:8080/

Useful Online Testers:

The websocket server, by default, is not activated until the appropriate chat command is provided (/frm http start). You may also have the web server auto-start changing the Web_Autostart in the Config File Method to true.

Please note that the web server and web socket system are one module, so enabling one enables the other.

Subscription/Publishing:
A request is needed to be made to "subscribe" to an endpoint. Afterwards, the mod will then "publish" the output, of the subscribed endpoints, to the connecting client as defined by the WebSocketPushCycle setting. Each endpoint is sent as an individual message.

Subscribe

To subscribe endpoints, send the subscribe action to the server via WebSocket.

Single Endpoint

{
  "action": "subscribe",
  "endpoints": "getPlayer"
}

Multiple Endpoints

{
  "action": "subscribe",
  "endpoints": [
    "getPlayer",
    "getPower"
  ]
}

Unsubscribe

To unsubscribe endpoints, send the unsubscribe action to the server via WebSocket.

Single Endpoint

{
  "action": "unsubscribe",
  "endpoints": "getPlayer"
}

Multiple Endpoints

{
  "action": "unsubscribe",
  "endpoints": [
    "getPlayer",
    "getPower"
  ]
}

Response Message

Subscribing to the getPower endpoint will provide this response:

{
  "endpoint": "getPower",
  "data": [{
    "CircuitID":0,
    "PowerCapacity":9.0,
    "PowerProduction":9.0,
    "PowerConsumed":9.0,
    "PowerMaxConsumed":9.0,
    "BatteryDifferential":0.0,
    "BatteryPercent":0.0,
    "BatteryCapacity":0,
    "BatteryTimeEmpty":"00:00:00",
    "BatteryTimeFull":"00:00:00",
    "FuseTriggered":false
  },
  {
    "CircuitID":1,
    "PowerCapacity":9.0,
    "PowerProduction":9.0,
    "PowerConsumed":9.0,
    "PowerMaxConsumed":9.0,
    "BatteryDifferential":0.0,
    "BatteryPercent":0.0,
    "BatteryCapacity":0,
    "BatteryTimeEmpty":"00:00:00",
    "BatteryTimeFull":"00:00:00",
    "FuseTriggered":false
  }],
}