8 Commits

Author SHA1 Message Date
Cobra a9d43ce4d3 Suppress BlueZ teardown race on SIGTERM in ble_alerter
When systemd sends SIGTERM, asyncio cancels the scan task before
BleakScanner.__aexit__ runs. BlueZ already stopped discovery by then,
so stop() throws 'No discovery started'. This was crashing the service
and triggering a 22-restart loop before systemd settled. Catch the
specific error string and treat it as a debug-level no-op.
2026-04-15 00:30:32 -04:00
Cobra d4f95a550c Add BLE GATT Device Name probing and WiFi+BLE arrival correlation
ble_alerter.py: probe Apple BLE devices via GATT characteristic 0x2A00
to discover device names (iPhone, Apple TV, etc). Names persist to
ble_names.json with last_seen timestamps. GATT_PROBE=1 enables active
probing; without it, Apple device last_seen timestamps still tracked.

net_alerter.py: on WiFi device arrival, read ble_names.json and log
any Apple BLE devices seen within the last 60s as correlation candidates.
Gives operator visibility into which BLE MACs co-arrived with a WiFi device.

Shared state file: /opt/net_alerter/ble_names.json
2026-04-15 00:03:35 -04:00
Cobra 6a5d1f0670 Exit cleanly when no BT adapter found instead of crash-looping
Wrap BleakScanner context manager in try-except to detect adapter
initialization errors. If 'No Bluetooth adapters found' or similar, log
warning and set shutdown event to trigger graceful exit with code 0.
Prevents systemd restart loop on hardware without BT adapter (e.g. OPi).
2026-04-14 13:29:29 -04:00
Cobra 722a632cee Revert "Add presence DB schema; fix BLE passive scan mode (bleak #1440)"
This reverts commit 2499db6147be65c76e7e202190b81855ba7b9100.
2026-04-10 15:49:03 -04:00
Cobra 0994385f7c Add presence DB schema; fix BLE passive scan mode (bleak #1440) 2026-04-10 15:49:03 -04:00
Cobra fa0e2491cf Fix ble_alerter: MAC name filter, Matrix 429 backoff, active scanner
- Reject dash/colon MAC-format device names (e.g. 45-48-39-7F-73-C7)
  from open mode — were slipping past is_generic_name()
- Add exponential backoff (1s, 2s) on Matrix 429/5xx, max 3 attempts —
  startup burst was rate-limiting and dropping alerts
- Commit active scanner flag (scanning_mode=active) that was in working
  tree but not in prior commit c0b91e9 despite the commit message
- Add 3 tests: MAC format filter, 429 retry success, 429 give-up

Fixes DevTrack #518
2026-04-10 06:44:13 -04:00
Cobra c0b91e9b0b Switch BLE scanner to active mode — bleak 0.20 passive requires or_patterns on BlueZ
Passive mode fails on Debian bookworm bleak 0.20.2 without or_patterns filter.
Active mode is functionally equivalent for building-level presence detection
and actually yields more complete advertisement data including device names.
2026-04-10 06:37:30 -04:00
Cobra 77b0cd6512 Add BLE alerter daemon (passive scan, named-device tracking, Matrix alerts) 2026-04-10 06:31:38 -04:00