pyhubblenetwork 0.14.0__tar.gz → 0.15.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. pyhubblenetwork-0.15.0/PKG-INFO +642 -0
  2. pyhubblenetwork-0.15.0/README.md +619 -0
  3. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/pyproject.toml +1 -1
  4. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/src/hubblenetwork/ble.py +23 -7
  5. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/src/hubblenetwork/cli.py +693 -524
  6. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/src/hubblenetwork/cloud.py +136 -6
  7. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/src/hubblenetwork/crypto.py +80 -89
  8. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/src/hubblenetwork/detect.py +1 -38
  9. pyhubblenetwork-0.15.0/src/hubblenetwork/device.py +79 -0
  10. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/src/hubblenetwork/errors.py +30 -0
  11. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/src/hubblenetwork/org.py +134 -16
  12. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/src/hubblenetwork/packets.py +4 -0
  13. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/src/hubblenetwork/sat.py +7 -2
  14. pyhubblenetwork-0.15.0/src/hubblenetwork/validate.py +1096 -0
  15. pyhubblenetwork-0.15.0/tests/fake_packets.py +92 -0
  16. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/test_aes_eax.py +13 -2
  17. pyhubblenetwork-0.15.0/tests/test_ble_validate.py +977 -0
  18. pyhubblenetwork-0.15.0/tests/test_cli_ble_decode.py +286 -0
  19. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/test_cli_help_and_errors.py +12 -4
  20. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/test_cli_scan_display.py +12 -33
  21. pyhubblenetwork-0.15.0/tests/test_cloud_decode.py +360 -0
  22. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/test_counter_eid.py +1 -24
  23. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/test_detect.py +0 -99
  24. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/test_sat.py +6 -3
  25. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/test_terminal_compat.py +4 -4
  26. pyhubblenetwork-0.14.0/PKG-INFO +0 -641
  27. pyhubblenetwork-0.14.0/README.md +0 -618
  28. pyhubblenetwork-0.14.0/src/hubblenetwork/device.py +0 -41
  29. pyhubblenetwork-0.14.0/tests/test_ble_validate.py +0 -217
  30. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/.gitignore +0 -0
  31. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/LICENSE +0 -0
  32. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/plugins/pyhubblenetwork/skills/hubble-ready-test/README.md +0 -0
  33. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/src/hubblenetwork/__init__.py +0 -0
  34. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/src/hubblenetwork/ready.py +0 -0
  35. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/src/hubblenetwork/termcaps.py +0 -0
  36. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/__init__.py +0 -0
  37. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/conftest.py +0 -0
  38. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/test_cli_ctr_autodetect.py +0 -0
  39. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/test_cli_doctor.py +0 -0
  40. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/test_cli_org_display.py +0 -0
  41. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/test_cli_payload.py +0 -0
  42. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/test_cloud_integration.py +0 -0
  43. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/test_metrics.py +0 -0
  44. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/test_org_delete_device.py +0 -0
  45. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/test_register_device_cloud.py +0 -0
  46. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/test_register_device_validation.py +0 -0
  47. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/test_sat_decrypt.py +0 -0
  48. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/test_sat_integration.py +0 -0
  49. {pyhubblenetwork-0.14.0 → pyhubblenetwork-0.15.0}/tests/test_unencrypted.py +0 -0
@@ -0,0 +1,642 @@
1
+ Metadata-Version: 2.5
2
+ Name: pyhubblenetwork
3
+ Version: 0.15.0
4
+ Summary: Hubble SDK host-side tools
5
+ Author-email: Paul Buckley <paul@hubble.com>
6
+ License-Expression: Apache-2.0
7
+ License-File: LICENSE
8
+ Classifier: Operating System :: OS Independent
9
+ Classifier: Programming Language :: Python :: 3
10
+ Requires-Python: >=3.10
11
+ Requires-Dist: bleak
12
+ Requires-Dist: click<9,>=8.2
13
+ Requires-Dist: docker>=7.0
14
+ Requires-Dist: httpx>=0.27
15
+ Requires-Dist: pycryptodome
16
+ Requires-Dist: questionary>=2.0.0
17
+ Requires-Dist: tabulate>=0.9.0
18
+ Provides-Extra: dev
19
+ Requires-Dist: pytest-cov; extra == 'dev'
20
+ Requires-Dist: pytest>=7; extra == 'dev'
21
+ Requires-Dist: ruff==0.16.2; extra == 'dev'
22
+ Description-Content-Type: text/markdown
23
+
24
+ # pyhubblenetwork
25
+
26
+ [![PyPI](https://img.shields.io/pypi/v/pyhubblenetwork.svg)](https://pypi.org/project/pyhubblenetwork)
27
+ [![Python](https://img.shields.io/pypi/pyversions/pyhubblenetwork.svg)](https://pypi.org/project/pyhubblenetwork)
28
+ [![License](https://img.shields.io/github/license/HubbleNetwork/pyhubblenetwork)](LICENSE)
29
+
30
+ **`hubblenetwork` is the command-line tool for Hubble Network IoT devices.** Watch
31
+ nearby devices report over Bluetooth, pick their satellite uplink off the air with an
32
+ SDR, decrypt payloads locally with a device key, and manage your fleet in the Hubble
33
+ Cloud — no embedded firmware knowledge required. Everything it does is also available
34
+ as an importable [Python SDK](#using-it-as-a-python-library).
35
+
36
+ Links: [PyPI](https://pypi.org/project/pyhubblenetwork/) ·
37
+ [Hubble docs](https://docs.hubble.com/docs/intro) ·
38
+ [Embedded SDK](https://github.com/HubbleNetwork/sdk)
39
+
40
+
41
+ ## Install
42
+
43
+ ```bash
44
+ pip install pyhubblenetwork
45
+
46
+ # or, for CLI-only use, into its own environment:
47
+ pipx install pyhubblenetwork
48
+ ```
49
+
50
+
51
+ ## Check your setup with `doctor`
52
+
53
+ ```bash
54
+ export HUBBLE_ORG_ID=<your org id>
55
+ export HUBBLE_API_TOKEN=<your api token>
56
+ hubblenetwork doctor
57
+ ```
58
+
59
+ `doctor` checks credentials, Bluetooth, Docker and the cached satellite receiver
60
+ image, and names the fix for anything broken:
61
+
62
+ ```
63
+ ✗ Credentials not set
64
+ Set both, or pass --org-id/--token:
65
+ export HUBBLE_ORG_ID=<your org id>
66
+ export HUBBLE_API_TOKEN=<your api token>
67
+ ✓ Bluetooth usage description present
68
+ ✗ Docker Docker is not available
69
+ Only `sat` commands need Docker.
70
+
71
+ Not ready. · 1 ok · 2 failed
72
+ ```
73
+
74
+ It exits 1 when something needed is broken, so a script can gate on it. A skipped
75
+ check is not a failure: it means the check does not apply on this platform, or could
76
+ not be answered without doing real work (pulling the satellite receiver image, say).
77
+
78
+
79
+ ## What do you want to do?
80
+
81
+ | Goal | Command |
82
+ |------|---------|
83
+ | Check my setup is working | [`doctor`](#check-your-setup-with-doctor) |
84
+ | Watch nearby devices report | [`ble scan`](#watch-nearby-devices-report) |
85
+ | Prove one device works end to end | [`ble validate`](#prove-one-device-works-end-to-end) |
86
+ | See which of my devices are nearby, no key needed | [`ble decode`](#decrypt-nearby-packets-in-the-cloud) |
87
+ | See what's registered to my org | [`org list-devices`](#work-with-your-fleet-in-the-cloud) |
88
+ | Read a device's history from the cloud | [`org get-packets <id>`](#work-with-your-fleet-in-the-cloud) |
89
+ | Register a new device and get its key | [`org register-device`](#work-with-your-fleet-in-the-cloud) |
90
+ | Hear a device's satellite uplink | [`sat scan`](#receive-a-devices-satellite-uplink) |
91
+ | Capture raw RF for offline analysis | [`sat record`](#one-shot-capture-record--signal-report) |
92
+
93
+ Reference: [Reading the output](#reading-the-output) ·
94
+ [Configuration](#configuration) ·
95
+ [Requirements](#requirements) ·
96
+ [Python library](#using-it-as-a-python-library) ·
97
+ [Troubleshooting](#troubleshooting)
98
+
99
+ Commands live in groups — **`org`** (your devices in the Hubble Cloud), **`ble`**
100
+ (nearby devices over Bluetooth), **`sat`** (satellite packets via PlutoSDR) and
101
+ **`metrics`** (fleet counts) — so it is usually `hubblenetwork <group> <command>`. The
102
+ two setup commands, `doctor` and `validate-credentials`, sit at the top level.
103
+
104
+ `hubblenetwork --help` lists everything; every command takes `--help` for its own
105
+ options. You don't have to remember which group a command is in: type one at the wrong
106
+ level and the CLI searches the whole tree and points you at it (`Did you mean:
107
+ hubblenetwork org list-devices`). Missing arguments say how to find the value, unknown
108
+ options list what the command accepts, and missing credentials name the environment
109
+ variables and the flags.
110
+
111
+
112
+ ## Watch nearby devices report
113
+
114
+ `ble scan` listens for Hubble beacon advertisements (UUID 0xFCA6) and prints one line
115
+ per packet as it arrives. No credentials needed — this is purely local. It runs until
116
+ Ctrl+C unless you bound it.
117
+
118
+ ```bash
119
+ hubblenetwork ble scan
120
+ ```
121
+
122
+ | Flag | Takes | Description |
123
+ |------|-------|-------------|
124
+ | `-t`, `--timeout` | seconds | Stop after this long. Default: no timeout. |
125
+ | `-n`, `--count` | N | Stop after N packets. |
126
+ | `-k`, `--key` | hex or base64, 16 or 32 bytes | Decrypt payloads locally with this device key. |
127
+ | `--show-failed-decryption` | — | Also show packets the key can't decrypt, with a `✓`/`✗` mark per row. Off by default, so they are hidden. |
128
+ | `--counter-mode` | `UNIX_TIME` or `DEVICE_UPTIME` | EID counter source for AES-CTR packets. Omit it to auto-detect — see below. |
129
+ | `-d`, `--days` | N | Days to search when decrypting AES-CTR packets in `UNIX_TIME` mode. Default: 2. |
130
+ | `-e`, `--period-exponent` | 0-15 | EID rotation period for AES-EAX packets; period = 2ⁿ seconds. Matches `rot_exp` in the device config. Omit it to auto-detect — see below. |
131
+ | `--network-id` | 34-bit ID | Show only this network. Unencrypted protocol only. |
132
+ | `--ingest` | — | Relay decrypted packets to the Hubble Cloud. Without `--key` nothing is ingested. Needs credentials. |
133
+ | `--org-id` | ID | Organization ID for `--ingest`. Env: `HUBBLE_ORG_ID`. |
134
+ | `--token` | token | API token for `--ingest`. Env: `HUBBLE_API_TOKEN`. |
135
+ | `-o`, `--format` | `tabular` or `json` | Output format. Default: `tabular`. |
136
+ | `--payload-format` | `auto`, `base64`, `hex`, `string` | How to render payloads — see [Payload format](#payload-format). |
137
+ | `--debug` | — | Add the `EPOCH`, `TAG` and `SALT` forensic columns. |
138
+
139
+ With `--key` and neither `--counter-mode` nor `--period-exponent` given, the
140
+ decryption strategy is worked out from the packets themselves, so you don't have to
141
+ know how the device was provisioned. The first packet that decrypts prints what it
142
+ found, once, on stderr — `[INFO] Detected: AES-256-CTR,
143
+ counter_source=DEVICE_UPTIME`. Passing either flag pins that half of the detection and
144
+ skips its sweep.
145
+
146
+ `--counter-mode DEVICE_UPTIME` requires `--key` and cannot be combined with `--days`,
147
+ which only means something for the day-based `UNIX_TIME` counter; both are rejected
148
+ with a usage error rather than quietly ignored. `sat scan` behaves the same way.
149
+
150
+
151
+ ## Decrypt nearby packets in the cloud
152
+
153
+ `ble decode` scans like `ble scan`, but sends each encrypted advertisement (AES-CTR
154
+ and AES-EAX) to the Hubble Cloud to be decrypted with the keys registered to your
155
+ organization. You don't need a device key, and each row says which device sent it.
156
+ Packets from devices outside your org stay undecrypted and are hidden unless you ask
157
+ for them. The cloud also stores what it decrypts, as any gateway would.
158
+
159
+ ```bash
160
+ hubblenetwork ble decode --timeout 30
161
+ ```
162
+
163
+ | Flag | Takes | Description |
164
+ |------|-------|-------------|
165
+ | `-t`, `--timeout` | seconds | Stop after this long. Default: no timeout. |
166
+ | `--show-failed` | — | Also show packets the cloud couldn't decrypt, with a `✓`/`✗` mark per row. |
167
+ | `-o`, `--format` | `tabular` or `json` | Output format. Default: `tabular`. |
168
+ | `--payload-format` | `auto`, `base64`, `hex`, `string` | How to render payloads — see [Payload format](#payload-format). |
169
+ | `--org-id` | ID | Organization ID. Env: `HUBBLE_ORG_ID`. |
170
+ | `--token` | token | API token, with the `read-packets` scope. Env: `HUBBLE_API_TOKEN`. |
171
+
172
+ Packets go up in batches of at most 25, sent whenever a batch fills or two seconds
173
+ pass, so rows appear as you go rather than at the end. A device repeats each
174
+ advertisement, and each distinct one is sent once.
175
+
176
+
177
+ ## Prove one device works end to end
178
+
179
+ `ble validate` is the quickest way to answer "is my device working?", and when it
180
+ isn't, why. It cross-checks how a device is registered, what it is actually
181
+ broadcasting, what the cloud makes of it, and what its firmware was built to do,
182
+ then names the disagreement: a key registered `UNIX_TIME` but flashed
183
+ `DEVICE_UPTIME`, a 32-byte AES-256 key in a build that only reads 16 bytes, a Unix
184
+ clock that is days behind, a key registered to another device, or a key that
185
+ matches nothing in range.
186
+
187
+ ```bash
188
+ hubblenetwork ble validate --key <key> # Checks local decryption and the device clock; no credentials
189
+ hubblenetwork ble validate --device-id <id> # No key: checks the registration, and that the cloud decodes the device
190
+ hubblenetwork ble validate --key <key> --device-id <id> # Both, and which side is wrong when they disagree
191
+ hubblenetwork ble validate --key <key> --device-id <id> --firmware app.<elf/bin/hex/ihex> # Also inspects the firmware for its key setup
192
+ ```
193
+
194
+ | Option | Description |
195
+ |--------|-------------|
196
+ | `--key`, `-k` | Device key, used to find its packets and test how they are encrypted. Accepts hex or base64, 16- or 32-byte. |
197
+ | `--device-id`, `-d` | Device UUID (needs credentials), used to test the registration and that the cloud decodes the device. |
198
+ | `--firmware`, `-f` | (Optional) The image you flashed (`.elf`/`.bin`/`.hex`/`.ihex`), or its build or project directory. Attempts to read the key size, key bytes, and counter source from the build output. |
199
+ | `--org-id` | Organization ID (defaults to the `HUBBLE_ORG_ID` env var). |
200
+ | `--token` | API token (defaults to the `HUBBLE_API_TOKEN` env var). With the `read-packets` scope it can decode packets heard now. |
201
+ | `--timeout`, `-t` | BLE scan timeout in seconds (default: 30). |
202
+
203
+ Pass `--key`, `--device-id`, or both. The key is tried against both key sizes, both
204
+ counter modes, a year of clock skew and every AES-EAX period, so it finds this key's
205
+ device among everything in range. With `--device-id`, packets heard are sent to the
206
+ cloud, as [`ble decode`](#decrypt-nearby-packets-in-the-cloud) does, and the backend
207
+ check passes if one comes back as this device. That works with no gateway nearby, and
208
+ the cloud stores what it decodes, as a gateway's upload would be. Without `--key`,
209
+ everything heard is sent and the cloud picks the device out; with it, only this key's
210
+ packets are, so a key registered to another device is named. A token without the
211
+ `read-packets` scope falls back to whether the backend decoded a packet from the
212
+ device in the last 10 minutes. The scan stops as soon as the device is found. It
213
+ exits 1 if any check fails, like `doctor`.
214
+
215
+ This is the **terrestrial** path only — the device advertising over Bluetooth, a
216
+ gateway relaying it, and the cloud decoding it. It says nothing about
217
+ whether the device is reaching the satellite network; for that, hear the uplink
218
+ yourself with [`sat scan`](#receive-a-devices-satellite-uplink).
219
+
220
+ Each failing check prints how to fix it. A failed scan is often just a slow
221
+ advertising interval meeting OS-level BLE scan optimizations — running it again
222
+ usually resolves it.
223
+
224
+
225
+ ## Work with your fleet in the cloud
226
+
227
+ The `org` group talks to the Hubble Cloud, so it needs credentials.
228
+
229
+ ```bash
230
+ hubblenetwork org info # which org and environment am I on?
231
+ hubblenetwork org list-devices # everything registered
232
+ hubblenetwork org list-devices -n 20
233
+ hubblenetwork org list-devices -f json # machine-readable
234
+
235
+ hubblenetwork org get-packets <id> # last 7 days by default
236
+ hubblenetwork org get-packets <id> --days 30 --format csv
237
+ hubblenetwork org get-packets <id> -n 50 --debug
238
+
239
+ hubblenetwork org register-device # returns the new device's key
240
+ hubblenetwork org set-device-name <id> <name>
241
+ hubblenetwork org delete-device <id>
242
+ ```
243
+
244
+ In tabular output, `list-devices` and `get-packets` stream rows as pages arrive, so
245
+ the first rows appear in about a second rather than after the whole window downloads.
246
+ A busy device can hold tens of thousands of packets; Ctrl+C stops early and still
247
+ prints a summary, `--limit`/`-n` caps the run, and it always says how it stopped.
248
+
249
+ `-o json` and `-o csv` keep their byte-for-byte output, so they buffer the whole
250
+ result and print no summary. For `get-packets`, `--limit` then trims after the
251
+ download rather than stopping it — `-n 50 -o json` still fetches the full window. Use
252
+ tabular output when you want the run itself bounded.
253
+
254
+ `register-device` takes `--encryption`, `--counter-source`, and — for AES-128-EAX on
255
+ `DEVICE_UPTIME` — either `--period-seconds` or `--period-exponent` (period = 2ⁿ
256
+ seconds; the cloud accepts 10-15, default 15 ≈ 9h). The two period flags are mutually
257
+ exclusive.
258
+
259
+
260
+ ## Receive a device's satellite uplink
261
+
262
+ The `sat` group listens, on the ground, to the transmissions a device sends up to the
263
+ satellite network. Nothing is received *from* a satellite: a PlutoSDR beside you picks
264
+ the uplink out of the air, confirming the device is transmitting on the satellite path
265
+ at all.
266
+
267
+ **Needs Docker running and an ADALM-PLUTO plugged in over USB.** `hubblenetwork doctor`
268
+ checks the Docker half.
269
+
270
+ ```bash
271
+ # Stream packets until Ctrl+C
272
+ hubblenetwork sat scan
273
+
274
+ # Bounded runs
275
+ hubblenetwork sat scan --timeout 30
276
+ hubblenetwork sat scan -n 5
277
+ hubblenetwork sat scan -o json --timeout 60 -n 20
278
+
279
+ # Decrypt payloads locally with a device key
280
+ hubblenetwork sat scan --key "a562a2f7e4c62bed52ab09633878f62b"
281
+ hubblenetwork sat scan --key "<key>" --counter-mode DEVICE_UPTIME
282
+ hubblenetwork sat scan --key "<key>" --show-failed-decryption
283
+
284
+ # No hardware to hand? Stream fake packets
285
+ hubblenetwork sat mock-scan
286
+ ```
287
+
288
+ Decryption uses the same AES-CTR scheme as BLE, with the counter source auto-detected
289
+ and announced unless `--counter-mode` is given. `--days` (default 2) controls how many
290
+ days around each packet's timestamp are searched in `UNIX_TIME` mode, and packets the
291
+ key cannot decrypt are hidden unless `--show-failed-decryption` is given.
292
+
293
+ `sat scan` handles the Docker container
294
+ ([`ghcr.io/hubblenetwork/sdr-docker`](https://ghcr.io/hubblenetwork/sdr-docker)) for
295
+ you: it verifies Docker, pulls the latest image (only changed layers are downloaded
296
+ when a copy is already cached), starts the container privileged so it can reach USB,
297
+ waits for the receiver API and the SDR, polls the container's HTTP API and deduplicates
298
+ by device ID and sequence number, then stops and removes the container on exit.
299
+
300
+ ### One-shot capture (`record` / `signal-report`)
301
+
302
+ Two commands record for a fixed duration, save a single file, and exit. Both accept
303
+ `--output PATH` (default: an auto-generated timestamped name), `--mock` (simulated
304
+ receiver — no PlutoSDR required), `--pluto-uri`, and `--debug`.
305
+
306
+ ```bash
307
+ # Capture 10 s of raw IQ samples to a .npy file
308
+ hubblenetwork sat record 10
309
+ hubblenetwork sat record 10 --output capture.npy
310
+
311
+ # Record 10 s and save an RF signal-diagnostic report to a .txt file
312
+ hubblenetwork sat signal-report 10
313
+ hubblenetwork sat signal-report 10 --output report.txt --mock
314
+ ```
315
+
316
+ - **`record`** captures the raw radio signal only — no decoding. Output is a NumPy
317
+ `.npy` file of IQ samples.
318
+ - **`signal-report`** records IQ, then re-analyzes it offline into a plain-text
319
+ **link-health diagnostic**: per-symbol timing/drift, channel-hopping validation,
320
+ amplitude/SNR, chipset metrics. It holds no decoded payloads — for those, use
321
+ `sat scan --key`.
322
+
323
+
324
+ ## Reading the output
325
+
326
+ ### Payload format
327
+
328
+ Commands that print packet data (`ble scan`, `ble decode`, `sat scan`, `org get-packets`)
329
+ take `--payload-format`:
330
+
331
+ * `auto` — printable ASCII shows as text, anything else as uppercase hex
332
+ * `base64` — encode payloads as base64
333
+ * `hex` — display payloads as hexadecimal
334
+ * `string` — decode payloads as UTF-8 (falls back to `<invalid UTF-8>`)
335
+
336
+ All four work with every output format, but the **default** differs: tabular output
337
+ defaults to `auto`, so a decrypted payload reads as `T=21.4` rather than `VD0yMS40`,
338
+ while JSON and CSV default to `base64` so the machine contract stays stable. An
339
+ explicit `--payload-format` always wins.
340
+
341
+ ### Scan layout
342
+
343
+ `ble scan` and `sat scan` print one line per packet with a signal bar, and close with
344
+ a summary:
345
+
346
+ ```
347
+ TIME RSSI V EID CTR/SEQ PAYLOAD
348
+ ─────────────────────────────────────────────────────────────────────────────
349
+ ✓ 00:06:40 -62 ███▏ 0 9c4e2ab7 20693 T=21.4,B=87
350
+ ✓ 00:06:43 -66 ██▉ 0 9c4e2ab7 20693 T=21.4,B=87
351
+ ✗ 00:06:49 -74 ██▏ 0 51d7be04 302 D307912C66BA4018E5
352
+ ─────────────────────────────────────────────────────────────────────────────
353
+
354
+ 3 packets · 2 decrypted, 1 failed · RSSI -62 to -74 dBm · 12s
355
+ ```
356
+
357
+ The bar's length is signal magnitude, so you can watch it shrink as you walk away from
358
+ a device. The `✓`/`✗` mark only appears with `--show-failed-decryption`, and it carries
359
+ the state on its own, so the output still reads correctly without colour.
360
+
361
+ `V` is the protocol version, and it decides what the two columns after it hold:
362
+
363
+ * **`0`, AES-CTR** — a 4-byte EID, and a `CTR/SEQ` showing the day counter once a
364
+ packet decrypts (`20693` above) or the advertisement's own sequence number when it
365
+ doesn't (`302`).
366
+ * **`1`, unencrypted** — no EID at all, so a `NET_ID` column takes that space.
367
+ * **`2`, AES-EAX** — an 8-byte EID, and a `CTR/SEQ` that stays `-`: its only
368
+ counter-shaped value is a random per-message nonce salt, which has its own `SALT`
369
+ column under `--debug`.
370
+
371
+ Packet rows go to **stdout** and everything else — the scanning notice, detection
372
+ lines, the summary — goes to **stderr**, so `hubblenetwork ble scan > packets.txt`
373
+ captures data only. The same split applies to `org list-devices` and
374
+ `org get-packets`.
375
+
376
+ Pass `--debug` for the forensic columns: `EPOCH`, `TAG` and `SALT` on `ble scan`,
377
+ `RS_CORR`, `SYM_MS` and `GAP_MS` on `sat scan`, `EPOCH`, `CTR` and `SEQ` on
378
+ `org get-packets`.
379
+
380
+ ### Terminals that can't do box-drawing
381
+
382
+ Not every terminal can render `─` and `█`: a legacy code page raises
383
+ `UnicodeEncodeError`, and a CJK configuration renders them double-width, which shears
384
+ every column. Pass `--ascii` (or set `HUBBLE_ASCII=1`) for a pure-ASCII rendering with
385
+ identical column widths — every substitution is the same display width as the glyph it
386
+ replaces. Only the bar's precision changes: ASCII has no sub-cell fill, so the eight
387
+ partial blocks collapse to one `=` tier and two nearby readings can land on the same
388
+ bar. The exact dBm is in the column beside it.
389
+
390
+ The encoding case is detected automatically, so you only need the flag for the
391
+ double-width one; `--no-ascii` forces the Unicode rendering back.
392
+
393
+ Colour is a separate axis: `--no-color`, a non-empty `NO_COLOR`, or a non-TTY stdout
394
+ all disable it, and `FORCE_COLOR` keeps it on where a pipe would otherwise strip it
395
+ (useful in CI). Both flags work on any command, before or after the subcommand.
396
+
397
+
398
+ ## Configuration
399
+
400
+ Two environment variables carry your credentials:
401
+
402
+ ```bash
403
+ export HUBBLE_ORG_ID=org_123 # your organization id
404
+ export HUBBLE_API_TOKEN=sk_XXXX # passed through as a bearer token
405
+ ```
406
+
407
+ Four more change how the CLI behaves, and none of them are required:
408
+
409
+ | Variable | Effect |
410
+ |----------|--------|
411
+ | `HUBBLE_ASCII` | `1`/`true`/`yes`/`on` forces the ASCII rendering; `0`/`false`/`no`/`off` forces Unicode. Same as `--ascii`/`--no-ascii`, which win over it. |
412
+ | `NO_COLOR` | Any non-empty value disables colour, per [no-color.org](https://no-color.org). |
413
+ | `FORCE_COLOR` | Any non-empty value keeps colour on where a pipe would otherwise strip it. |
414
+ | `SDR_DOCKER_IMAGE` | Overrides the satellite receiver image. Default: `ghcr.io/hubblenetwork/sdr-docker:latest`. |
415
+
416
+ Every command that needs credentials also takes `--org-id` and `--token`, and `--help`
417
+ names the environment variable for each. On the `org` and `metrics` groups those flags
418
+ belong to the group, so they go before the subcommand:
419
+
420
+ ```bash
421
+ hubblenetwork org --org-id <id> --token <token> list-devices
422
+ ```
423
+
424
+ Check whichever route you used with `hubblenetwork validate-credentials` or
425
+ `hubblenetwork doctor`. **The SDK does not read the environment** — see below.
426
+
427
+
428
+ ## Requirements
429
+
430
+ - Python **3.10+** (3.11/3.12 recommended)
431
+ - **Bluetooth**, for the `ble` group:
432
+ - **macOS**: CoreBluetooth. Run from a real terminal app and grant it Bluetooth
433
+ access when prompted. macOS kills any process whose executable has no
434
+ `NSBluetoothAlwaysUsageDescription` in an Info.plist, and a bare Python binary
435
+ has none — see [Troubleshooting](#troubleshooting) if you hit a crash rather
436
+ than a permission prompt.
437
+ - **Linux**: BlueZ required; the user must have permission to access the BLE
438
+ adapter (often the `bluetooth` group).
439
+ - **Windows**: a compatible BLE stack/adapter.
440
+ - **Docker and a PlutoSDR**, for the `sat` group:
441
+ [Docker Desktop](https://www.docker.com/get-started/) (macOS/Windows) or Docker
442
+ Engine (Linux) installed and running, and an Analog Devices ADALM-PLUTO connected
443
+ over USB. `sat mock-scan`, `sat record --mock` and `sat signal-report --mock` need
444
+ Docker but no SDR.
445
+
446
+ `hubblenetwork doctor` reports on all of this.
447
+
448
+
449
+ ## Using it as a Python library
450
+
451
+ Import from the package top-level for a stable surface:
452
+
453
+ ```python
454
+ from hubblenetwork import (
455
+ ble, cloud, sat,
456
+ Organization, Device, Credentials, Environment,
457
+ EncryptedPacket, UnencryptedPacket, AesEaxPacket, UnknownPacket,
458
+ DecryptedPacket, SatellitePacket, Location,
459
+ decrypt, decrypt_eax, decrypt_satellite,
460
+ UNIX_TIME, DEVICE_UPTIME,
461
+ InvalidCredentialsError,
462
+ )
463
+ ```
464
+
465
+ **Unlike the CLI, the SDK does not read the environment.** `Organization()` requires
466
+ its credentials explicitly:
467
+
468
+ ```python
469
+ import os
470
+ from hubblenetwork import Organization
471
+
472
+ org = Organization(
473
+ org_id=os.environ["HUBBLE_ORG_ID"],
474
+ api_token=os.environ["HUBBLE_API_TOKEN"],
475
+ )
476
+
477
+ new_dev = org.register_device() # returns a Device, with its key
478
+ for d in org.iter_devices(): # streams as pages arrive
479
+ print(d.id, d.name)
480
+ for pkt in org.iter_packets(new_dev): # ditto; both take on_page(page, total)
481
+ print(pkt.rssi, pkt.payload)
482
+ ```
483
+
484
+ The iterators yield as each API page arrives instead of accumulating, so you can start
485
+ processing immediately on a device with tens of thousands of packets.
486
+ `list_devices()` and `retrieve_packets()` are `list()` wrappers over them.
487
+
488
+ `ble.scan()` returns a mixed list — the unencrypted protocol and AES-EAX have their
489
+ own packet types — so filter to `EncryptedPacket` before handing anything to
490
+ `decrypt()`, which only understands AES-CTR. It returns `None` rather than raising on
491
+ a packet it can't handle, so an unfiltered loop looks like a wrong key:
492
+
493
+ ```python
494
+ from hubblenetwork import ble, decrypt, decrypt_eax, AesEaxPacket, EncryptedPacket
495
+
496
+ key = bytes.fromhex("a562a2f7e4c62bed52ab09633878f62b")
497
+
498
+ for pkt in ble.scan(timeout=5.0):
499
+ if isinstance(pkt, EncryptedPacket): # AES-CTR
500
+ decrypted = decrypt(key, pkt) # UNIX_TIME by default
501
+ # decrypted = decrypt(key, pkt, counter_mode="DEVICE_UPTIME")
502
+ elif isinstance(pkt, AesEaxPacket):
503
+ decrypted = decrypt_eax(key, pkt, period_exponent=0)
504
+ else:
505
+ continue # nothing to decrypt
506
+ if decrypted:
507
+ print(decrypted.payload) # a DecryptedPacket
508
+ ```
509
+
510
+ Or let the cloud decrypt, with no key at all. `org.decode_packets()` takes any number
511
+ of `EncryptedPacket` / `AesEaxPacket`, sends them in batches of 25, and returns one
512
+ entry per input, in order: a `DecryptedPacket` carrying `device_id` and
513
+ `device_name`, or `None` where the cloud couldn't decrypt it for your org. Any other
514
+ packet type raises `ValueError`, so filter first. The API key needs the
515
+ `read-packets` scope; the cloud stores what it decodes; and packets heard more than
516
+ 72 hours ago are not sent (they come back `None`):
517
+
518
+ ```python
519
+ from hubblenetwork import ble, AesEaxPacket, EncryptedPacket
520
+
521
+ pkts = [p for p in ble.scan(timeout=10.0) if isinstance(p, (EncryptedPacket, AesEaxPacket))]
522
+ for pkt, result in zip(pkts, org.decode_packets(pkts)):
523
+ if result:
524
+ print(result.device_name or result.device_id, result.payload)
525
+ ```
526
+
527
+ `counter_mode` accepts `"UNIX_TIME"` (default, UTC day-based) or `"DEVICE_UPTIME"`
528
+ (counter values 0–127, fixed pool size of 128). The BLE functions have sync and async
529
+ variants — `ble.scan()` / `ble.scan_async()`. The CLI's auto-detection is available
530
+ too, in `hubblenetwork.detect`: `CtrCounterModeDetector` / `EaxExponentDetector` are
531
+ the per-scan objects that own the sweep and its cache.
532
+
533
+ Satellite, which manages the Docker container for you:
534
+
535
+ ```python
536
+ from hubblenetwork import sat, SatellitePacket, decrypt_satellite
537
+
538
+ key = bytes.fromhex("a562a2f7e4c62bed52ab09633878f62b")
539
+
540
+ for pkt in sat.scan(timeout=60.0, poll_interval=2.0):
541
+ print(pkt.device_id, pkt.seq_num, pkt.rssi_dB, pkt.payload.hex())
542
+ if pkt.auth_tag is not None:
543
+ plaintext: bytes | None = decrypt_satellite(
544
+ key, seq_no=pkt.seq_num, auth_tag=pkt.auth_tag,
545
+ encrypted_payload=pkt.payload, timestamp=pkt.timestamp,
546
+ counter_mode="UNIX_TIME",
547
+ )
548
+
549
+ packets: list[SatellitePacket] = sat.fetch_packets() # current buffer, no lifecycle
550
+ iq_bytes: bytes = sat.record(10.0) # raw IQ (.npy file body)
551
+ report: str = sat.signal_report(10.0) # plain-text RF diagnostic
552
+ ```
553
+
554
+ The return types differ: `decrypt()` and `decrypt_eax()` hand back a
555
+ `DecryptedPacket`, while `decrypt_satellite()` hands back plaintext `bytes` directly,
556
+ because a satellite packet's metadata never left the `SatellitePacket` you already
557
+ have. Both return `None` on failure.
558
+
559
+ `SatellitePacket` fields: `device_id`, `seq_num`, `device_type`, `timestamp`,
560
+ `rssi_dB`, `channel_num`, `freq_offset_hz`, `payload` (bytes), `auth_tag` (bytes or
561
+ `None`), plus four optional receiver diagnostics that back the `--debug` columns —
562
+ `pdu_n_corr` and `header_n_corr` (Reed-Solomon corrections, `RS_CORR`), `sym_mean_ms`
563
+ (`SYM_MS`) and `gap_mean_ms` (`GAP_MS`).
564
+
565
+ The two satellite exceptions live in `hubblenetwork.errors` rather than the top-level
566
+ surface. `sat.scan()` raises `DockerError` when Docker is missing, not running, or the
567
+ container fails to start, and `SatelliteError` when the container starts but the
568
+ receiver API or the SDR never comes up. Both descend from `HubbleError`, alongside the
569
+ backend, network, validation, BLE and decryption errors in the same module.
570
+
571
+ ```python
572
+ from hubblenetwork.errors import DockerError, SatelliteError
573
+ ```
574
+
575
+
576
+ ## Troubleshooting
577
+
578
+ * **macOS: `ble scan` crashes instead of prompting for Bluetooth** (`Termination
579
+ Reason: Namespace TCC`, missing `NSBluetoothAlwaysUsageDescription`) — macOS refuses
580
+ CoreBluetooth to any executable without that key in an Info.plist, and Homebrew's
581
+ `python3` has no Info.plist at all. Run from a real terminal app (Terminal, iTerm)
582
+ rather than an embedded IDE shell, and grant it Bluetooth under System Settings →
583
+ Privacy & Security → Bluetooth. If it still aborts, run the CLI through a small app
584
+ bundle carrying the key — copy and amend
585
+ `$(brew --prefix)/Frameworks/Python.framework/Versions/<ver>/Resources/Python.app`.
586
+ * **`ble scan` finds nothing**: verify BLE permissions and adapter state, and try a
587
+ longer `--timeout`. A second attempt often succeeds.
588
+ * **Auth errors**: run `hubblenetwork doctor`. `validate-credentials` reports which
589
+ environment accepted them and exits 1 if neither did, so it is safe in a script.
590
+ * **Import errors**: ensure you installed into the Python you're running
591
+ (`python -m pip …`). Prefer `pipx` for CLI-only usage.
592
+ * **`DockerError: Docker is not available`**: the Docker daemon is not running. Start
593
+ Docker Desktop (macOS/Windows) or `sudo systemctl start docker` (Linux).
594
+ * **`DockerError: The 'docker' Python package is required`**: run `pip install docker`
595
+ (it ships with `pyhubblenetwork` but may be missing in some environments).
596
+ * **`SatelliteError: No PlutoSDR detected`**: the container started but the SDR never
597
+ connected. Ensure the ADALM-PLUTO is plugged in before running `sat scan`, and that
598
+ no other process is using it.
599
+ * **`sat scan` hangs pulling the image**: the first run fetches
600
+ `ghcr.io/hubblenetwork/sdr-docker:latest`, which may take a minute on a slow
601
+ connection. Later runs use the cached image.
602
+
603
+
604
+ ## Development & tests
605
+
606
+ ```bash
607
+ python3 -m venv .venv && source .venv/bin/activate
608
+ pip install -e '.[dev]'
609
+
610
+ ruff check src
611
+ pytest
612
+ ```
613
+
614
+
615
+ ## Telemetry
616
+
617
+ **There is none.** The CLI makes no network call except the ones a command explicitly
618
+ needs: the Hubble Cloud API for the commands that use credentials (`org`, `metrics`,
619
+ `doctor`, `validate-credentials`, `ble validate`, `ble decode` and
620
+ `ble scan --ingest`); `localhost`
621
+ for the satellite receiver container; and Docker pulling that container image from
622
+ `ghcr.io` on first `sat` use. Nothing is reported anywhere about how you use it.
623
+
624
+ If that ever changes, it would have to be opt-in and off by default; carry nothing
625
+ sensitive (no tokens, org or device IDs, keys, payloads, coordinates, hostnames or
626
+ paths — command name, exit status and version is the ceiling); list every field sent
627
+ in this file; be killable by both a flag and an environment variable; never sit on a
628
+ command's critical path; and be covered by a test asserting the payload holds no
629
+ credential and no device identifier.
630
+
631
+
632
+ ## Releases & versioning
633
+
634
+ Follows **SemVer**. Pushing a `vX.Y.Z` tag triggers a GitHub Actions workflow that
635
+ runs tests, builds the package, creates a GitHub Release, and publishes to PyPI via
636
+ [Trusted Publishing](https://docs.pypi.org/trusted-publishers/) — no API tokens are
637
+ stored in the repo. The `pypi` environment requires manual approval in the
638
+ [Actions UI](https://github.com/HubbleNetwork/pyhubblenetwork/actions).
639
+
640
+ To cut a release, use the `/release` skill: it bumps `pyproject.toml`, generates
641
+ notes into `release-notes.md` from the conventional-commit log, commits, tags, and
642
+ pushes.