Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Web Socket API

richardbunt edited this page Sep 6, 2014 · 1 revision

Data can be collected from KSP using the Telemachus web socket API, which sits on top of the rfc6455 web socket protocol. To connect to the Telemachus web socket server use a URL of the following form.

ws://<ip-address>:<port>/datalink

###Subscribing and Unsubscribing

This API, at its core, is subscription based which allows interest to be registered in particular API strings. For example, in order to subscribe to the vessel's altitude the following JSON formatted command should be sent to the server.

{"+":["v.altitude"]}

Likewise, to unsubscribe from the vessel's altitude the following command would be sent.

{"-":["v.altitude"]}

###Rate

No data is sent from the server until the first subscription command is used, at which point data is sent back at regular intervals. This interval can be adjusted using the rate protocol command with a value in milliseconds:

{"rate":1000}

One-time Commands

All of the functionality provided by the Telemachus web socket service does not fit the subscribe/publish model, such as the ability to stage a craft - which is an action that is (usually) performed at irregular intervals. To instruct the server to stage a craft the following protocol command would be used.

{"run":["f.stage"]}

Parameters

Some commands may take one or more parameters. They are passed in brackets as part of the command name and separated by commas.

{"run":["f.rcs[True]"]}

###Composing Operations

Since all of these commands are JSON formatted strings, they can be composed in the expected manner. For example, the following command will subscribe to the vessel's altitude and name, and additionally change the stream frequency to twice a second.

{
  "+":["v.altitude", "v.name"],
  "rate": 500
}

###The Null Message

The following is the null message:

{}

This is sent while a stream is active but KSP is not currently in the flight scene, or there are no longer any subscriptions or outstanding commands.