# Streams and camera frames

bsln version: `0.0.1b40`

SDK source: `baseline-robotics/engineering@c8db8d9fbc8ce8e0524c5ee45cebdfcec34fc666:robotics/bsln`

Page source: `baseline-robotics/engineering@c8db8d9fbc8ce8e0524c5ee45cebdfcec34fc666:robotics/bsln/docs/customer/SDK-STREAM-REFERENCE.md`

[Read on the web](https://docs.baseline-robotics.com/sdk/stream-reference/) | [Markdown](https://docs.baseline-robotics.com/sdk/stream-reference.md) | [Documentation index](https://docs.baseline-robotics.com/llms.txt)

## Watch a session

<a id="clientwatch_session"></a>
<a id="clientfollow_session"></a>

From the [Quickstart Python project](https://docs.baseline-robotics.com/index.md#3-run-a-session), read a message from your active session in a separate terminal from the controller. Enter the session ID when prompted:

```bash
uv run python -c '
from bsln.sdk import Client

session_id = input("Session ID: ").strip()
with Client() as client, client.watch_session(session_id, frames=False) as stream:
    message = stream.recv(timeout=10)
    if message is not None:
        print(message["type"])
'
```

`client.watch_session(session_id, frames=False)` opens a read-only stream. `client.follow_session(...)` follows session messages across supported reconnects. A watcher never keeps a controller session alive. Close the stream when you finish.

## Messages and camera images

<a id="streamrecv-and-sessionrecv"></a>
<a id="streammessages-and-sessionmessages"></a>

Use `stream.recv(timeout=...)` or `session.recv(timeout=...)` for the next message, or `messages()` to iterate. Keep one consumer per stream so readers do not split the queue. The queue keeps the newest 256 messages. For independent readers, open separate watchers.

Enable `frames=True` for camera JPEGs. A `frame` message contains a `camera` name, JPEG bytes in `jpeg` and the station timestamp `t`. Use the [camera description](https://docs.baseline-robotics.com/station/cameras.md#check-your-camera-inputs) to check inputs. `session.get_state()` reads the latest telemetry without consuming a message.

## When the connection drops

<a id="streamreconnect-and-sessionreconnect"></a>
<a id="streamclose-and-sessionclose"></a>
<a id="sessionview"></a>
<a id="viewsession_id-and-viewclosed"></a>
<a id="viewclose"></a>

`reconnect()` clears queued messages. Inspect fresh state before sending more motion. `close()` closes the connection. Use `session.end()` to end a session you started. `session.view()` opens a viewer. Closing the view closes its own stream and leaves the session open.
