Network APIPUBLIC

Network API v1.1 — Protocol Reference

Protocol Reference

API identifier: beanalyzer.network.v1 Protocol revision: 1.1 Default endpoint: 127.0.0.1:35000


1. Transport model

Network API is not HTTP and is not REST.

It is a socket protocol with a JSON control plane.

TCP

Control/full-JSON/compact-JSON messages use newline framing:

<UTF-8 JSON object>\n

A client must buffer TCP bytes and split JSON messages at newline boundaries. One recv() is not guaranteed to equal one Network API message.

When a subscription uses format:"binary", asynchronous telemetry uses the BN length-prefixed framing described later in this document. JSON control messages can still occur on the same TCP connection.

UDP

Normal control and JSON telemetry:

one UTF-8 JSON object per UDP datagram

Binary telemetry:

one complete BN binary frame per UDP datagram

2. Limits

Current implementation constants:

MAX_JSON_BYTES             65536
MAX_EVENT_QUEUE            4096
MAX_CLIENT_QUEUE           1024
MAX_COMMANDS_PER_SECOND    250 per endpoint
MAX_COMMANDS_PER_IP_PER_SECOND 500 per IP (v5.4.0-alpha.14)
MAX_TRACKED_ENDPOINTS      2048 (v5.4.0-alpha.14)
COMMAND_HISTORY_IDLE_S     15 (v5.4.0-alpha.14)
DEFAULT_UDP_TTL_S          60
MAX_UDP_TTL_S              3600

TCP receive buffering is disconnected if it grows beyond four times the maximum single JSON message size without valid newline framing.

v5.4.0-alpha.14 hardening: UDP subscriptions accept an integer ttl_s between 5 and 3600 inclusive (or omit/null for default 60). Malformed values receive {"type":"error","error":"invalid_subscription"} without stopping the service. Endpoint rate histories expire independently from UDP subscriptions. Shared-IP rate limits apply across source ports; a request may receive rate_limited when its endpoint or its source IP hits a limit. The API identifier and protocol revision remain unchanged.


3. TCP connection sequence

On connection, BEANalyzer immediately sends hello.

Typical flow:

client                         BEANalyzer
  |                                |
  |------ TCP connect ------------>|
  |<----------- hello -------------|
  |----------- auth -------------->|
  |<----------- auth --------------|
  |--------- subscribe ----------->|
  |<-------- subscribed -----------|
  |<========= telemetry ===========|

Example hello:

{
  "api":"beanalyzer.network.v1",
  "type":"hello",
  "server":"BEANalyzer UltraPro 5",
  "transport":"tcp",
  "authenticated":false,
  "capabilities":{
    "api_revision":"1.1",
    "transports":["tcp","udp"],
    "streams":["bean","can","signals"],
    "profiles":["standard","low"],
    "formats":["json","compact_json","binary"],
    "delivery_modes":[
      "every_update",
      "on_change",
      "on_change_heartbeat",
      "periodic"
    ]
  }
}

4. Authentication

TCP

{
  "type":"auth",
  "token":"YOUR_TOKEN",
  "request_id":1
}

Success:

{
  "api":"beanalyzer.network.v1",
  "type":"auth",
  "authenticated":true,
  "request_id":1
}

Failure:

{
  "api":"beanalyzer.network.v1",
  "type":"error",
  "error":"authentication_failed",
  "request_id":1
}

If a token is configured and a protected command is sent before successful authentication:

{
  "api":"beanalyzer.network.v1",
  "type":"error",
  "error":"authentication_required"
}

UDP

A UDP command may include:

"token":"YOUR_TOKEN"

An authenticated active UDP subscription also keeps that source endpoint authenticated until the subscription expires.


5. LAN guard

The server accepts an empty token for loopback use.

Current loopback host strings recognised by the guard:

127.0.0.1
localhost

A bind outside those names requires a token.

Example LAN bind:

0.0.0.0:35000

The API transport is not encrypted. Do not expose port 35000 directly to an untrusted network or the public Internet.


6. request_id

Most commands may include arbitrary JSON request_id data.

Example:

{"type":"ping","request_id":42}

Response:

{"type":"pong","request_id":42,...}

Use request IDs to correlate command/response pairs while asynchronous subscription events are arriving.


7. Commands

7.1 hello

Request capabilities:

{"type":"hello","request_id":1}

No authentication is required for hello.


7.2 auth

Authenticate:

{"type":"auth","token":"YOUR_TOKEN","request_id":2}

7.3 ping

{"type":"ping","request_id":3}

Response:

{
  "api":"beanalyzer.network.v1",
  "type":"pong",
  "timestamp":1791023020.9,
  "request_id":3
}

For an active UDP subscriber, ping refreshes its expiration using the default UDP TTL.


7.4 subscribe

Minimal:

{
  "type":"subscribe",
  "streams":["signals"],
  "signals":["rpm","speed"]
}

Acknowledgement returns the effective subscription summary, including delivery settings:

{
  "api":"beanalyzer.network.v1",
  "type":"subscribed",
  "subscription":{
    "streams":["signals"],
    "directions":[],
    "bean":{"contexts":[],"dids":[],"mids":[]},
    "can":{"ids":[]},
    "signals":["rpm","speed"],
    "delivery":{
      "profile":"standard",
      "format":"json",
      "mode":"every_update",
      "update_hz":null,
      "min_interval_ms":0,
      "heartbeat_ms":1000,
      "deadband":{
        "enabled":false,
        "value":null,
        "offset":0
      },
      "batch_ms":0,
      "numeric_ids":false,
      "event_fields":[],
      "signal_fields":[],
      "signal_ids":{},
      "signal_options":{}
    }
  }
}

See [SETTINGSANDMODES.md](SETTINGSANDMODES.md) for all subscription fields.

For UDP, ttl_s is accepted and clamped to 5..3600 seconds.


7.5 unsubscribe

{"type":"unsubscribe","request_id":5}

TCP: clears that client's subscription. UDP: removes the source endpoint subscription.


7.6 get_status

{"type":"get_status","request_id":10}

Response status currently includes:

app
version
api
bean_connected
can_connected
can_backend
can_channel
can_selected_device
bean_to_can_active
bean_to_can_source
can_to_bean_active
remote_tx_allowed
frames
decoded
network

Network statistics include:

running
host
port
tcp_enabled
udp_enabled
tcp_clients
udp_subscribers
published_events
sent_messages
event_queue_drops
client_queue_drops
rx_commands
invalid_messages
pending_events
pending_responses

Drop counters are particularly useful when checking whether a client or network link is keeping up.


7.7 get_signal

{
  "type":"get_signal",
  "name":"rpm",
  "request_id":11
}

Success returns the latest cached signal object.

If unavailable:

{
  "type":"response",
  "ok":false,
  "command":"get_signal",
  "error":"signal_not_available",
  "name":"rpm"
}

7.8 get_signals

Selected names:

{
  "type":"get_signals",
  "names":["rpm","speed","coolant_temp"],
  "request_id":12
}

Omit names to request all currently cached signal names.

Response:

{
  "type":"response",
  "ok":true,
  "command":"get_signals",
  "signals":[...],
  "missing":[...]
}

get_signals is a snapshot command. For continuously changing values, prefer subscribe.


7.9 list_signals

{"type":"list_signals","request_id":13}

Each active BEAN-DBC signal definition may include:

{
  "name":"speed",
  "signal_id":123456789,
  "unit":"km/h",
  "kind":"u8",
  "message":"Vehicle speed",
  "context":83,
  "did":254,
  "mid":36
}

The signal ID is deterministic CRC32 of the UTF-8 signal name.

Do not hard-code example signal names for every vehicle. Discover the active DBC when writing a generic client.


7.10 tx_can

Requires the local GUI option:

Allow remote BEAN/CAN transmission

Example:

{
  "type":"tx_can",
  "backend":"python-can",
  "can_id":"0x520",
  "extended":false,
  "data":[1,2,3,4],
  "request_id":20
}

Supported backend strings:

python-can
Arduino CAN serial bridge

Default:

python-can

The selected backend must be physically connected.

Classic CAN data is limited to a maximum of 8 bytes.

Data may also be supplied using accepted hexadecimal byte text forms handled by BEANalyzer's byte parser.


7.11 tx_bean

Requires:

  • local remote-TX permission enabled;
  • physical BEAN interface connected.

DID/MID/DATA form:

{
  "type":"tx_bean",
  "did":"0x62",
  "mid":"0xD2",
  "data":[16,0,0],
  "request_id":30
}

Raw API payload form:

{
  "type":"tx_bean",
  "payload":[98,210,16,0,0],
  "request_id":31
}

Current maximums:

payload    13 bytes
data       11 bytes when DID+MID are supplied separately

Optional explicit CTX:

{
  "type":"tx_bean",
  "ctx":"0x25",
  "payload":[98,210,16,0,0]
}

Optional priority:

{
  "type":"tx_bean",
  "priority":2,
  "did":"0x62",
  "mid":"0xD2",
  "data":[16,0,0]
}

Priority must be 0..15.

If priority is supplied instead of CTX, BEANalyzer derives:

CTX = (priority << 4) | payload_length

The physical BEAN bridge remains responsible for lower-level link framing.


8. Remote TX safety gate

Authentication and permission are separate.

An authenticated client still receives:

{
  "type":"response",
  "ok":false,
  "error":"remote_tx_disabled"
}

until the BEANalyzer user explicitly enables remote transmission locally.

This is intentional fail-safe behavior.


9. Event envelope

Before per-client projection/encoding, published events receive:

{
  "api":"beanalyzer.network.v1",
  "type":"event",
  "timestamp":1791023020.9,
  "sequence":123
}

sequence is a Network API server event sequence, not a CAN or BEAN counter.


10. Full JSON signal event

Example:

{
  "api":"beanalyzer.network.v1",
  "type":"event",
  "stream":"signals",
  "timestamp":1791023020.9,
  "sequence":123,
  "bus":"BEAN",
  "direction":"R",
  "context":83,
  "did":254,
  "mid":36,
  "source":"Replay",
  "replay":true,
  "signals":[
    {
      "name":"rpm",
      "value":901.171875,
      "unit":"rpm",
      "kind":"u16be",
      "raw":4614,
      "raw_bytes":[18,6],
      "offset":0,
      "timestamp":1791023020.9,
      "context":83,
      "did":254,
      "mid":36
    }
  ]
}

Signal timestamps are created when the signal payload is generated.


11. Full JSON CAN event

{
  "api":"beanalyzer.network.v1",
  "type":"event",
  "stream":"can",
  "bus":"CAN",
  "direction":"RX",
  "can_id":1312,
  "can_id_hex":"0x520",
  "extended":false,
  "dlc":2,
  "data":[1,2],
  "data_hex":"01 02",
  "source":"CAN Interface",
  "timestamp":1791023020.9,
  "sequence":124
}

Replay CAN publication identifies its source as Replay.


12. Full JSON BEAN event

{
  "api":"beanalyzer.network.v1",
  "type":"event",
  "stream":"bean",
  "bus":"BEAN",
  "direction":"R",
  "context":83,
  "context_hex":"0x53",
  "did":254,
  "did_hex":"0xFE",
  "mid":36,
  "mid_hex":"0x24",
  "data":[25],
  "data_hex":"19",
  "raw_frame":[...],
  "raw_hex":"...",
  "source":"Replay",
  "replay":true,
  "timestamp":1791023020.9,
  "sequence":125
}

data is decoded/application DATA when decode metadata is available. raw_frame preserves the original frame representation available to BEANalyzer.


13. Replay semantics

Replay and physical traffic are both visible to Network API.

Replay events are marked:

{
  "source":"Replay",
  "replay":true
}

This allows third-party applications to be developed and tested without the vehicle or physical BEAN interface present.

Replay continues to update the same Network API signal cache used by get_signal / get_signals.


14. Compact JSON

Compact JSON still uses newline framing over TCP.

Example:

{"t":"e","s":"sig","q":123,"v":[[123456789,901.2],[987654321,25]]}

See [SETTINGSANDMODES.md](SETTINGSANDMODES.md) for the compact key map and field selection.


15. Binary framing

Binary telemetry header:

offset  bytes  field
0       2      ASCII "BN" = 0x42 0x4E
2       1      binary version = 1
3       1      packet type
4       2      payload length, unsigned big-endian
6       N      payload

Packet types:

0x01  signals
0x02  CAN
0x03  BEAN
0x7F  future/unknown compact fallback

16. Binary signal packet

Payload:

u32be  sequence
u8     flags
u8     signal_count

repeat signal_count times:
  u32be signal_id
  u8    value_type
  ...   encoded value

Flags:

bit 0 = Replay
bit 1 = TX direction

Value types:

0x00 null
0x01 bool    -> u8 0/1
0x02 int32   -> signed big-endian 32-bit
0x03 float32 -> IEEE-754 big-endian
0x04 UTF-8   -> u16be byte length + bytes

17. Binary CAN packet

Payload:

u32be sequence
u8    flags
u32be CAN_ID
u8    DLC
u8[]  DATA

Flags:

bit 0 = extended CAN ID
bit 1 = Replay
bit 2 = TX direction

DATA is currently limited to classic CAN maximum 8 bytes.


18. Binary BEAN packet

Payload:

u32be sequence
u8    flags
u8    context
u8    DID
u8    MID
u8    data_length
u8[]  DATA

Unknown context/DID/MID is encoded as:

0xFF

Flags:

bit 0 = Replay
bit 1 = TX direction

19. Mixed TCP framing in binary mode

The control plane remains JSON after a binary subscription.

Therefore a complete binary-aware TCP client should recognize:

first byte '{'    -> read JSON through newline
first bytes 'BN'  -> read 6-byte binary header, then payload_len bytes

Do not assume the connection becomes permanently binary after subscribe.

Reference implementation:

examples/network_api/python_binary_client.py

20. UDP subscriptions

UDP subscriptions expire.

Default:

60 s

Requested:

{
  "type":"subscribe",
  "token":"YOUR_TOKEN",
  "streams":["signals"],
  "signals":["rpm"],
  "ttl_s":300
}

Accepted range:

5..3600 s

A UDP ping on an active subscriber refreshes its expiration to the default 60 seconds.

A client wanting a longer custom TTL should renew subscribe with its desired ttl_s before expiry rather than relying only on ping.


21. Backpressure

The API does not block vehicle-bus processing waiting for a slow client.

There are bounded:

  • global event queue;
  • global response queue;
  • per-TCP-client send queue.

If a queue fills, older queued items may be discarded and counters increase.

Inspect:

event_queue_drops
client_queue_drops

through get_status.


22. Rate limiting

Inbound commands are limited to:

250 commands / second / endpoint

If exceeded:

{
  "type":"error",
  "error":"rate_limited",
  "detail":"Maximum 250 commands/s per endpoint"
}

Repeated rate-limit errors are themselves throttled.

A normal subscription does not need to send commands continuously.


23. Errors

Network/server-level errors include:

ErrorMeaning
invalid_jsonMessage is not a valid JSON object
message_too_largeTCP JSON line exceeded maximum size
authentication_failedWrong token
authentication_requiredProtected operation attempted without auth
rate_limitedEndpoint exceeded command-rate limit
invalid_subscriptionInvalid profile/mode/format or other subscription option
command_handler_unavailableApplication command handler missing
command_dispatch_failedServer could not hand command to application

Application-level response errors include:

ErrorMeaning
signal_not_availableRequested signal has no current cached value
remote_tx_disabledLocal remote-TX checkbox is disabled
unknown_commandCommand type is unsupported
command_failedValid command encountered an application/runtime validation error

24. Security considerations

Current security properties:

  • token authentication;
  • mandatory token for non-loopback bind;
  • separate local remote-TX permission gate;
  • token hidden in GUI by default.

Current limitations:

  • transport itself is not encrypted;
  • token is stored as plain application configuration;
  • token travels over TCP/UDP in cleartext on the LAN.

Recommended deployment:

trusted/local laboratory LAN
isolated embedded-device WLAN
VPN/tunnel if remote access is required

Do not directly port-forward Network API to the public Internet.


25. Client robustness requirements

A robust client should:

  1. read and inspect hello;
  2. verify api == "beanalyzer.network.v1";
  3. inspect capabilities.api_revision;
  4. authenticate;
  5. subscribe only to required streams/signals;
  6. use request IDs for command correlation;
  7. tolerate additional unknown JSON fields;
  8. buffer TCP correctly rather than assuming recv/message equivalence;
  9. reconnect and resubscribe after a socket failure;
  10. monitor stale data locally if freshness matters;
  11. in binary mode, parse both JSON control and BN telemetry;
  12. avoid hard-coding signal names without checking list_signals on generic vehicle profiles.