Network APIPUBLIC

Network API v1.1 — Client Recipes

This document contains practical subscription and test recipes.

This document contains practical subscription and test recipes. For exact semantics, see:

  • [SETTINGSANDMODES.md](SETTINGSANDMODES.md)
  • [PROTOCOLV11.md](PROTOCOLV11.md)

1. Local TCP auth + ping with curl

macOS/Linux:

read -s BEAN_TOKEN

printf '%s\n' \
"{\"type\":\"auth\",\"token\":\"$BEAN_TOKEN\"}" \
'{"type":"ping","request_id":1}' \
| curl --no-buffer --max-time 3 telnet://127.0.0.1:35000

A timeout from --max-time after valid responses is expected because the Network API TCP connection is persistent.


2. Snapshot selected signals

printf '%s\n' \
"{\"type\":\"auth\",\"token\":\"$BEAN_TOKEN\"}" \
'{"type":"get_signals","names":["rpm","speed","coolant_temp"],"request_id":2}' \
| curl --no-buffer --max-time 3 telnet://127.0.0.1:35000

3. Discover signal names

printf '%s\n' \
"{\"type\":\"auth\",\"token\":\"$BEAN_TOKEN\"}" \
'{"type":"list_signals","request_id":3}' \
| curl --no-buffer --max-time 3 telnet://127.0.0.1:35000

Use this before assuming a generic vehicle DBC contains rpm, speed or other example names.


4. Standard live signal subscription

printf '%s\n' \
"{\"type\":\"auth\",\"token\":\"$BEAN_TOKEN\"}" \
'{"type":"subscribe","streams":["signals"],"signals":["rpm","speed","coolant_temp"],"request_id":4}' \
| curl --no-buffer telnet://127.0.0.1:35000

Leave the connection open.


5. Low-profile subscription

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

Current defaults:

compact JSON
on-change + heartbeat
10 Hz max
1 s heartbeat
100 ms signal batching
numeric IDs
id/value signal fields
no deadband

6. On-change only

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

7. On-change + heartbeat

{
  "type":"subscribe",
  "streams":["signals"],
  "signals":["rpm","speed"],
  "mode":"on_change_heartbeat",
  "heartbeat_ms":1000
}

8. Fixed-rate style delivery

{
  "type":"subscribe",
  "streams":["signals"],
  "signals":["coolant_temp"],
  "mode":"periodic",
  "update_hz":2
}

Equivalent:

{
  "type":"subscribe",
  "streams":["signals"],
  "signals":["coolant_temp"],
  "mode":"periodic",
  "min_interval_ms":500
}

9. Symmetric deadband

{
  "type":"subscribe",
  "streams":["signals"],
  "signals":["rpm"],
  "mode":"on_change",
  "deadband":25
}

10. Deadband with offset

{
  "type":"subscribe",
  "streams":["signals"],
  "signals":["rpm"],
  "mode":"on_change",
  "deadband":25,
  "deadband_offset":5
}

Explicit object form:

{
  "deadband":{
    "enabled":true,
    "value":25,
    "offset":5
  }
}

11. Different behavior per signal

{
  "type":"subscribe",
  "profile":"low",
  "streams":["signals"],
  "signals":["rpm","speed","coolant_temp"],
  "signal_options":{
    "rpm":{
      "update_hz":20,
      "deadband":25
    },
    "speed":{
      "update_hz":10,
      "deadband":1
    },
    "coolant_temp":{
      "update_hz":1,
      "deadband":1,
      "heartbeat_ms":5000
    }
  }
}

12. Batching

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

This combines the latest accepted signal values from the 100 ms window into one outgoing signal event.


13. Minimal standard JSON fields

{
  "type":"subscribe",
  "streams":["signals"],
  "signals":["rpm","speed"],
  "event_fields":["sequence","source","replay"],
  "signal_fields":["name","value"]
}

14. Numeric signal IDs

{
  "type":"subscribe",
  "streams":["signals"],
  "signals":["rpm","speed"],
  "numeric_ids":true,
  "signal_fields":["id","value"]
}

Read the name-to-ID mapping from the subscribed acknowledgement or list_signals.


15. Compact JSON

{
  "type":"subscribe",
  "streams":["signals"],
  "signals":["rpm","speed"],
  "format":"compact_json",
  "numeric_ids":true,
  "signal_fields":["id","value"]
}

Typical output shape:

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

16. Binary telemetry

{
  "type":"subscribe",
  "streams":["signals"],
  "signals":["rpm","speed"],
  "format":"binary",
  "mode":"on_change_heartbeat",
  "update_hz":10,
  "heartbeat_ms":1000,
  "batch_ms":100
}

Use:

examples/network_api/python_binary_client.py

as a mixed JSON-control / BN-binary parser reference.


17. ESP32 starting profile

{
  "type":"subscribe",
  "profile":"low",
  "streams":["signals"],
  "signals":["rpm","speed","coolant_temp"],
  "mode":"on_change_heartbeat",
  "update_hz":10,
  "heartbeat_ms":1000,
  "batch_ms":100,
  "deadband_enabled":false
}

Reference:

examples/network_api/esp32_compact_client.ino

For low power, combine Network API packet reduction with ESP32 Wi-Fi power-save features and measure on the actual target board.


18. Nintendo DS starting profile

Compact JSON:

{
  "type":"subscribe",
  "profile":"low",
  "streams":["signals"],
  "signals":["rpm","speed","coolant_temp"],
  "format":"compact_json",
  "update_hz":8,
  "batch_ms":125
}

Binary:

{
  "type":"subscribe",
  "streams":["signals"],
  "signals":["rpm","speed","coolant_temp"],
  "format":"binary",
  "mode":"on_change_heartbeat",
  "update_hz":8,
  "heartbeat_ms":1000,
  "batch_ms":125
}

Reference:

examples/network_api/nintendo_ds_socket_example.c

Physical Nintendo DS Wi-Fi compatibility remains target/environment dependent.


19. VB6

Use TCP and ordinary JSON for the simplest integration:

{
  "type":"subscribe",
  "streams":["signals"],
  "signals":["rpm","speed","coolant_temp"],
  "mode":"on_change_heartbeat",
  "update_hz":10,
  "batch_ms":100,
  "format":"json",
  "signal_fields":["name","value"]
}

Reference:

examples/network_api/vb6_winsock_example.txt

20. Filter CAN IDs

{
  "type":"subscribe",
  "streams":["can"],
  "directions":["RX"],
  "can":{
    "ids":["0x520","0x5A0","0x5A1","0x5A2","0x5A3"]
  }
}

For high-rate filtered CAN telemetry:

{
  "type":"subscribe",
  "streams":["can"],
  "can":{"ids":["0x520"]},
  "format":"binary"
}

21. Filter BEAN Context/DID/MID

{
  "type":"subscribe",
  "streams":["bean"],
  "directions":["RX"],
  "bean":{
    "contexts":["0x53"],
    "dids":["0xFE"],
    "mids":["0x24"]
  }
}

22. Replay development without vehicle hardware

Start Replay in BEANalyzer, then subscribe normally.

Replay events are identified by:

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

This permits development of external dashboards and tools without the vehicle or BEAN hardware connected.


23. UDP low-profile subscription

One JSON datagram:

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

Renew before expiry.


24. Remote CAN TX

Only after the local user enables remote TX:

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

Do not use remote TX casually on a live vehicle bus. The API does not replace normal CAN electrical/protocol safety requirements.


25. Remote BEAN TX

Only after local remote-TX permission and physical BEAN connection:

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

26. Check health / drops

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

Watch:

network.event_queue_drops
network.client_queue_drops
network.pending_events
network.pending_responses

If drops climb, narrow filters, reduce frequency, enable batching, use compact JSON/binary, or improve the client's receive loop.


27. Diagnosing “subscribed but no updates”

Check in order:

  1. Replay/live source is actually moving.
  2. requested signal names exist in list_signals;
  3. streams includes signals;
  4. filters are not excluding the source frame;
  5. mode / deadband / rate limits are not intentionally suppressing values;
  6. batching is not simply delaying the first packet;
  7. the client keeps the TCP socket open;
  8. the receive loop handles more than one socket packet;
  9. get_status shows published/sent events;
  10. queue-drop counters are not increasing.

For Replay specifically, use a build containing the Replay Network API streaming correction. The current v1.1 branch includes it.


28. Diagnosing binary mode

After receiving the JSON subscribed acknowledgement:

if next byte == '{':
    parse one JSON line
elif next two bytes == 'B','N':
    read six-byte BN header
    read exactly payload_len bytes
else:
    framing error

Do not use a line-only reader once binary telemetry has been selected.


29. More examples

A compact set of copy/paste configurations is maintained at:

examples/network_api/subscription_examples.jsonc

Reference clients:

examples/network_api/python_compact_client.py
examples/network_api/python_binary_client.py
examples/network_api/esp32_compact_client.ino
examples/network_api/nintendo_ds_socket_example.c
examples/network_api/vb6_winsock_example.txt