Skip to main content

Auto-reconnecting Nordic UART Service (NUS) BLE logger.

Project description

NUS Logger

Auto‑reconnecting Nordic UART Service (NUS) BLE log collector for Zephyr / nRF Connect SDK devices.

PyPI · Issues · MIT License

Features

  • Zero-config CLI: discover, connect, stream logs.
  • Automatic reconnect with exponential backoff.
  • Optional UTC or local timestamps.
  • Optional raw hex dump alongside decoded text.
  • Append to logfile (external rotation friendly).
  • Works on Windows, Linux, macOS via the host Bluetooth stack (bleak).
  • Small typed library for embedding / automation.

Installation

pip install nus-logger            # core
pip install "nus-logger[color]"   # with colored status output

Requires Python 3.9+.

Upgrade in place:

pip install -U nus-logger

Quick Start (CLI)

# 1. List advertising NUS devices
nus-logger --list

# 2. Connect by (partial) name, show UTC timestamps, also log to file
nus-logger --name my-device --ts --logfile logs/session.txt

# 3. Show local timestamps and raw hex dump
nus-logger --name my-device --ts-local --raw

Module mode (equivalent):

python -m nus_logger --name my-device --ts

Press Ctrl-C to stop; the tool will attempt automatic reconnection until max retries.

Common Options

--list                 List visible devices and exit
--name SUBSTR          Match advertising name (env: NUS_NAME)
--filter-addr SUBSTR   Prefer address containing substring
--ts / --ts-local      Add UTC or local timestamps
--raw                  Show hex bytes alongside each decoded line
--logfile PATH         Append text lines to file (env: NUS_LOGFILE)
--timeout SECS         Scan/connect timeout (env: NUS_TIMEOUT)
--backoff SECS         Initial reconnect backoff (env: NUS_BACKOFF, grows to 15s)
--max-retries N        Stop after N failed reconnects (env: NUS_MAX_RETRIES)
--verbose              Dump discovered services / characteristics once

Environment variables override flags when flags are omitted.

Programmatic Use

import asyncio
from nus_logger.ble_nus import NUSClient

async def main():
	client = NUSClient(name_substring="my-device")
	await client.connect()
	try:
		async for line in client.iter_lines():  # yields decoded UTF-8 log lines
			print(line)
			if "READY" in line:
				await client.write(b"ping\n")  # optional upstream write
	finally:
		await client.disconnect()

asyncio.run(main())

See nus_logger.nus_logger:main for full CLI orchestration (reconnect logic, backoff, etc.). Higher level automation can use NUSLoggerController for managed sessions.

Typical Workflow with Zephyr / nRF Connect

  1. Enable the Nordic UART Service in your firmware (e.g. CONFIG_BT_NUS=y).
  2. Print logs normally (Zephyr logging routed to the NUS TX characteristic).
  3. Start nus-logger to capture and persist logs.
  4. Use --raw if debugging binary framing / encoding issues.

Troubleshooting

Situation Hint
No devices on Windows Toggle Bluetooth off/on or airplane mode, verify advertising.
Linux permission errors Ensure user in bluetooth group or grant CAP_NET_RAW to Python binary.
macOS permission prompt Allow Bluetooth access in System Settings > Privacy & Security > Bluetooth.
Frequent disconnects Reduce distance / interference; backoff resets after ~60s stable link.
Mixed devices with similar names Use --filter-addr to prefer a known address substring.

Development

git clone https://github.com/smnmsr/nus-logger.git
cd nus-logger
pip install -e .[dev]
pytest

Linting is intentionally minimal; contributions should keep the code small and dependency‑light.

Versioning & Compatibility

The public surface is the CLI plus the NUSClient / NUSLoggerController classes. Minor releases may add kwargs/features; removals will occur only in a major bump following semantic versioning principles.

License

MIT License © 2025 Simon M. See LICENSE file for full text.


If this saves you time, a star on GitHub helps others discover it.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nus_logger-0.0.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nus_logger-0.0.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file nus_logger-0.0.1.tar.gz.

File metadata

  • Download URL: nus_logger-0.0.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nus_logger-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f460a7219953c5fe9c13216d24a856912a3d5b5ac15d522eac21c6fe66f5d3b1
MD5 51d2830b1aca7a514feb36b3bbe26960
BLAKE2b-256 e340c1628542a6bf3fdd4a337f126ca12e52420388852f960464df39b102b579

See more details on using hashes here.

Provenance

The following attestation bundles were made for nus_logger-0.0.1.tar.gz:

Publisher: publish.yml on smnmsr/nus-logger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nus_logger-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: nus_logger-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nus_logger-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1e1cbf7fcc4e7de98b7392efde1d61328e9563cd79c7be8c3237c223b6a3545d
MD5 2c86d81ecba45d80958e6ce2b148f5fd
BLAKE2b-256 36d2b759e29d2092225812c9b154a534af1c99ea156cfe7e21d425bdc72a8f22

See more details on using hashes here.

Provenance

The following attestation bundles were made for nus_logger-0.0.1-py3-none-any.whl:

Publisher: publish.yml on smnmsr/nus-logger

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page