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