Skip to main content

Crate subscriber

Crate subscriber 

Source
Expand description

Diagnostic subscriber that writes live NATS LabJack samples to CSV files.

The streamer publishes each channel’s scans as FlatBuffer sampler::Scan messages on NATS, and the archiver normally turns them into Parquet. This binary is for inspecting that live stream without running the archiver. It makes a plain (non-JetStream) core NATS subscription to the live subject wildcard from subjects::live_labjack_stream_subject, decodes each scan, and appends one CSV file per asset and channel. It only sees messages published while it is running.

Each CSV file is named labjack_<asset>_<channel>.csv (for example labjack_001_ch03.csv) and has the header sequence,timestamp,raw_value. The asset is taken from the subject for legacy subjects and from ASSET_NUMBER otherwise. Every sample becomes one row: the scan’s sequence number, the sample time as RFC 3339 UTC, and the value as published.

Β§Configuration

  • NATS_SUBJECT - Subject root. Default: avenabox.
  • ASSET_NUMBER - Asset number used in CSV file names for structured subjects, and as the source when neither SOURCE_ID nor LABJACK_NAME is set. Unparseable values fall back to the default. Default: 1.
  • SITE_ID - Site ID for the structured subject layout.
  • BOX_ID - Box ID for the structured subject layout.
  • LABJACK_NAME - LabJack name, used as the source when SOURCE_ID is unset.
  • SOURCE_TYPE - Read and passed on, but does not affect the subject.
  • SOURCE_ID - Source ID for the structured subject layout.
  • OUTPUT_DIR - Directory for the CSV files, created if missing. Default: outputs.
  • NATS_SERVERS - Comma-separated NATS server URLs. Default: nats://127.0.0.1:4222.
  • NATS_CREDS_FILE - NATS credentials file. Default: apt.creds.

With the defaults the subscription is the legacy wildcard avenabox.*.data.*, which matches every asset; each file is named after the asset in its subject. Setting any of SITE_ID, BOX_ID or SOURCE_ID, or NATS_SUBJECT=avenars, switches to <root>.<site>.<box>.<source>.live.*.

ModulesΒ§

nats_config πŸ”’
Shared NATS server-list and JetStream context helpers.
sample_data_generated πŸ”’
subjects πŸ”’
NATS subject builders for LabJack live data and archive exports.

FunctionsΒ§

asset_for_subject πŸ”’
Finds the asset number a message belongs to.
csv_file_name πŸ”’
Builds the CSV file name for one asset and channel.
extract_channel_token πŸ”’
Extracts the final subject token, which is expected to be the channel name.
main πŸ”’
Starts the live NATS subscriber and appends decoded samples to CSV.
open_csv_for_channel πŸ”’
Opens or creates the per-channel CSV file and writes its header if needed.
timestamp_unix_ns_to_rfc3339 πŸ”’
Converts a Unix nanosecond timestamp into RFC 3339 text in UTC.