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.
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
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
- Enable the Nordic UART Service in your firmware (e.g.
CONFIG_BT_NUS=y). - Print logs normally (Zephyr logging routed to the NUS TX characteristic).
- Start
nus-loggerto capture and persist logs. - Use
--rawif 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nus_logger-0.0.2.tar.gz.
File metadata
- Download URL: nus_logger-0.0.2.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
865ef1d158f4e9e12255c22ac1c38c7ceaaf591babd72af4a85ee7f587773f5a
|
|
| MD5 |
34c9a5d22f76078d2149ee16e0524b42
|
|
| BLAKE2b-256 |
a6baf7173a4f05105eb5f2d589ef3e5a46e4e6dc97853e3a46f927104f9bd715
|
Provenance
The following attestation bundles were made for nus_logger-0.0.2.tar.gz:
Publisher:
publish.yml on smnmsr/nus-logger
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nus_logger-0.0.2.tar.gz -
Subject digest:
865ef1d158f4e9e12255c22ac1c38c7ceaaf591babd72af4a85ee7f587773f5a - Sigstore transparency entry: 469691895
- Sigstore integration time:
-
Permalink:
smnmsr/nus-logger@09932222cd8eab8b3d7e8d010cf5d586135fdec8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/smnmsr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@09932222cd8eab8b3d7e8d010cf5d586135fdec8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file nus_logger-0.0.2-py3-none-any.whl.
File metadata
- Download URL: nus_logger-0.0.2-py3-none-any.whl
- Upload date:
- Size: 17.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66db35103d06fe8263dccb55aae347c660f837eb32d596e516b4211989e4546e
|
|
| MD5 |
a86378df9bc7dc6bac63851094932a9e
|
|
| BLAKE2b-256 |
10f384f4c1215f60f4d155564de6a0922fce90d4f538a35881638a2444f3ddef
|
Provenance
The following attestation bundles were made for nus_logger-0.0.2-py3-none-any.whl:
Publisher:
publish.yml on smnmsr/nus-logger
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nus_logger-0.0.2-py3-none-any.whl -
Subject digest:
66db35103d06fe8263dccb55aae347c660f837eb32d596e516b4211989e4546e - Sigstore transparency entry: 469691904
- Sigstore integration time:
-
Permalink:
smnmsr/nus-logger@09932222cd8eab8b3d7e8d010cf5d586135fdec8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/smnmsr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@09932222cd8eab8b3d7e8d010cf5d586135fdec8 -
Trigger Event:
push
-
Statement type: