All docsStellar LinkRF bench · by Stellar Systems v0.4.0

Control & Automation

Using the API

Base URL, versioning, errors, authentication, long-running requests, the WebSocket streams, and routes not listed in the OpenAPI document.

stellarlinkd serves a REST API and a set of WebSocket streams on port 8080. Everything the CLI and the web console do goes through it, so anything they can do, a script can do.

Base URL and versioning#

text
http://<unit>:8080/api/v1/...      REST
ws://<unit>:8080/ws/...            WebSocket streams

Every response carries an x-api-version: v1 header. The OpenAPI 3 document is served at GET /api/v1/openapi.json, with an interactive Swagger UI at /docs. The API Reference section of this site is generated from the same document.

Shell
curl -s http://<unit>:8080/api/v1/health
curl -s http://<unit>:8080/api/v1/version
curl -s http://<unit>:8080/api/v1/system/capabilities | jq '.symbol_rates'

Errors#

Errors are JSON with a machine-readable code and a human message:

JSON
{"code": "conflict", "message": "a scenario is already running: ..."}
HTTPcodeTypical cause
400bad_requestUnparseable YAML, a bad duration, a framing that cannot hold alignment
404not_foundUnknown profile, scenario or run; no datapath available
409conflictA scenario is already running; the chain cannot be conditioned; the datapath is held by someone else; a scenario exists and overwrite was not given
422validation_failedSemantic validation failed
501not_implementedThe resource is not configured on this unit (for example no scenarios_dir)
500internalAnything else; the message says what
504—A capture or loopback did not sustain the requested blocks in time

Refusals are written to be actionable: a 409 from a transmit or a scenario launch names the first unmet prerequisite and the command that clears it.

Authentication and CORS#

Authentication is off by default. To turn it on:

  1. Generate a secret and keep it in a private file, for example openssl rand -hex 32 > secret.txt.

  2. Put the same value in the unit's configuration: [api] auth_required = true and [api] auth_secret = "<the secret>". The unit refuses to start if the secret is empty, shorter than 32 characters, or an example value such as change-me.

  3. Create a token on your machine (nothing is sent to the unit):

    Shell
    stellarlinkctl auth token --secret-file secret.txt --role operator --hours 12

    The role is operator, admin or maintenance.

  4. Pass it with --token or STELLARLINK_TOKEN (stellarlinkctl), or as Authorization: Bearer <token> (any HTTP client).

What is protected: every request that changes something (POST, PUT, DELETE), and the /ws/tx transmit stream, which also accepts the token as ?token=<token> since a browser cannot set headers on a WebSocket. Reads (GET) and the other WebSocket streams stay open, so monitoring needs no token. Without a token a protected request gets 401; with a token whose role is not recognised, 403.

Web console. When the unit requires a token, the sidebar shows API token: paste a token there and the console sends it with every change. It is kept in your browser only. Without one, the console can read but changes are refused with a message saying so.

ZeroMQ link. The link service has no authentication of its own. With authentication on, its transmit socket (port 5555) therefore listens on the unit itself only (127.0.0.1), so no other host can transmit through it; the received-frames and telemetry streams (5556, 5557) are read-only and stay reachable. To accept frames from the network anyway, set [link] tx_unauthenticated = true — only on a network you control. The unit says which applies in its log at startup.

CORS origins are set by [api] cors_origins. The shipped configuration allows every origin (["*"]), so the web console can run from any host.

Request bodies are limited to [api] max_body_bytes (20 MiB by default). Payloads sent as hex double in size; for large transfers use the /ws/tx stream.

See Daemon Configuration for the configuration file.

Long-running work#

Some requests start work that outlives them:

RequestReturnsFollow with
POST /api/v1/scenarios/{name}/run202, the run idGET /api/v1/scenario-runs/{run_id}, ws://…/ws/scenario-runs/{run_id}, then GET /api/v1/reports/{run_id}
POST /api/v1/campaigns/{name}/runthe execution idGET /api/v1/campaign-runs/{id}, ws://…/ws/campaign-runs/{id}
Any of the above—GET /api/v1/jobs, GET /api/v1/jobs/{job_id}

Only one scenario runs at a time. A second launch is refused with 409 naming the run in progress; it is never queued.

WebSocket streams#

StreamContent
/ws/metricsTelemetry snapshots (metrics_bulk messages) at the telemetry cadence
/ws/eventsRuntime events (profile_applied, lock lost, …)
/ws/monitor/fft?channel=rx&interval_ms=200The spectrum, pushed
/ws/scenario-runs/{run_id}A scenario run in flight: events, samples and assertion verdicts as they happen
/ws/campaign-runs/{id}A campaign execution as it advances
/ws/txA persistent feed for pushing packets into the modem (see Datapath and Transmission)
/ws/frames?framing=slot&slot_len=256&payload=trueThe receive stream in real time (see Datapath and Transmission)

WebSocket streams are not described in the OpenAPI document.

Routes not listed in the OpenAPI document#

The following routes are served and used by the CLI and the web console, but do not appear in the API Reference:

RoutePurposeDocumented in
GET /api/v1/radio/rfThe radio's sample rate, signal path and readinessChain Conditioning
POST /api/v1/radio/rf/tuneSet the radio's sample rate and align its digital interface at that rate ({"rate_sps": 8000000})Chain Conditioning
POST /api/v1/radio/rf/mode/rfRoute through the AD9361's internal digital loopbackChain Conditioning
POST /api/v1/radio/rf/mode/plRoute through the internal digital loopbackChain Conditioning
POST /api/v1/radio/nco-offsetSet the RX/TX NCO offsets ({"rx_hz": …, "tx_hz": …})RF Fundamentals
PUT /api/v1/monitor/fft/{channel}Switch spectrum analysis on or off for rx or txTelemetry and Metrics
POST /api/v1/scenariosCreate or replace a scenario from YAMLScenarios

POST /api/v1/radio/rf/mode/air, /radio/rf/calibrate and /radio/rf/kill are in the document.

Talking to the API from a script#

Python
import requests

UNIT = "http://<unit>:8080/api/v1"

print(requests.get(f"{UNIT}/version").json())
r = requests.post(f"{UNIT}/chain/condition",
                  json={"target": "pl", "profile": "pl_loopback"})
r.raise_for_status()
run = requests.post(f"{UNIT}/scenarios/hc_qpsk/run").json()
print(run)

The Python example client wraps the REST API and the ZeroMQ link service; see Example Clients.

↑↓ to moveEnter to open