|
Politician 1.0.0
WiFi Auditing Library for ESP32
|
Passive RSSI-based motion and presence detector. More...
#include <PoliticianSense.h>
Public Member Functions | |
| PoliticianSense () | |
| void | begin (Politician &engine, const uint8_t *anchorBssid=nullptr) |
| Attaches the sensor to a Politician engine. | |
| bool | beginBySSID (Politician &engine, const char *ssid) |
| Looks up an AP by SSID in the engine cache and anchors to its BSSID. | |
| void | setSenseCallback (SenseCb cb) |
| Sets the state-change callback. | |
| void | setPacketLogger (Politician::PacketCb cb) |
| Registers a pass-through raw-packet callback. | |
| void | setThreshold (float dBm2) |
| Sets the variance threshold (dBm²) that triggers SENSE_MOTION. | |
| void | setWindowSize (uint8_t n) |
| Sets the sliding window size in samples (clamped to [4, POLITICIAN_SENSE_MAX_WINDOW]). | |
| void | setDebounce (uint32_t ms) |
| Sets the debounce hold-time (ms). | |
| void | setStaleTimeout (uint32_t ms) |
| Sets the stale-data timeout (ms). | |
| void | tick () |
| Main worker — call from loop() alongside engine.tick(). | |
| float | getVariance () const |
| float | getMeanRssi () const |
| SenseEvent | getState () const |
| uint32_t | getTotalSamples () const |
| bool | hasAnchor () const |
| const uint8_t * | getAnchor () const |
| void | reset () |
| Clears the sample window and resets state without detaching from the engine. | |
| void | end () |
| Detaches from the engine and clears its packet logger. | |
| ~PoliticianSense () | |
Static Public Attributes | |
| static constexpr uint8_t | DEFAULT_WINDOW = 32 |
| Sliding window (samples). | |
| static constexpr float | DEFAULT_THRESHOLD = 6.0f |
| Variance threshold (dBm²). | |
| static constexpr uint32_t | DEFAULT_DEBOUNCE = 2000 |
| Motion hold-time (ms). | |
| static constexpr uint32_t | DEFAULT_STALE_MS = 10000 |
| Max gap before ignoring stale data (ms). | |
Passive RSSI-based motion and presence detector.
Hooks into a Politician engine via the packet logger callback and tracks RSSI variance from a fixed anchor AP over a configurable sliding window. Fires a SenseCb whenever the space transitions between quiet and active.
Definition at line 105 of file PoliticianSense.h.
|
inline |
Definition at line 113 of file PoliticianSense.h.
|
inline |
Definition at line 408 of file PoliticianSense.h.
|
inline |
Attaches the sensor to a Politician engine.
| engine | The running Politician instance. |
| anchorBssid | 6-byte BSSID of the anchor AP, or nullptr to sample every AP. |
Installs an internal packet logger on the engine. If you also need raw frame access, call sense.setPacketLogger() before begin() to chain a pass-through callback. Setting it after begin() is a data race — the engine worker task may be concurrently reading _userPacketCb.
The engine must already be initialized (begin() called) before calling this. For continuous sensing, lock the engine to the anchor's channel: engine.lockChannel(anchorChannel);
cfg.capture_filter must include LOG_FILTER_BEACONS before engine.begin() is called. Beacons are the primary RSSI source and PoliticianSense will collect no samples without them. Set it in Config: Definition at line 158 of file PoliticianSense.h.
References engine, and politician::Politician::setPacketLogger().
|
inline |
Looks up an AP by SSID in the engine cache and anchors to its BSSID.
| engine | The running Politician instance. |
| ssid | Exact SSID string to match. |
When multiple BSSIDs share the same SSID the strongest signal is chosen.
Definition at line 197 of file PoliticianSense.h.
References engine, and politician::ApRecord::ssid.
|
inline |
Detaches from the engine and clears its packet logger.
Sets _active = false first so any _onPacket() invocation already in flight on the engine worker task will bail out immediately without touching members. Then clears the engine's packet logger slot so no further calls are dispatched.
if (!_active) guard before end() writes the flag, it may still access members after end() returns. This window is narrow but real on a multi-core ESP32.Safe usage pattern when destroying from a different core/task:
Calling end() from the same task/core as the engine worker (e.g. in loop()) is always safe with no delay required.
Definition at line 397 of file PoliticianSense.h.
|
inline |
Definition at line 367 of file PoliticianSense.h.
|
inline |
Definition at line 350 of file PoliticianSense.h.
|
inline |
Definition at line 353 of file PoliticianSense.h.
|
inline |
Definition at line 356 of file PoliticianSense.h.
|
inline |
Definition at line 347 of file PoliticianSense.h.
|
inline |
Definition at line 364 of file PoliticianSense.h.
|
inline |
Clears the sample window and resets state without detaching from the engine.
Useful when the environment changes (furniture moved, AP relocated, etc.).
Definition at line 373 of file PoliticianSense.h.
|
inline |
Sets the debounce hold-time (ms).
MOTION state is held for this long after the last variance spike before returning to STILL, preventing rapid flickering during intermittent movement. Default: 2000 ms
Definition at line 266 of file PoliticianSense.h.
|
inline |
Registers a pass-through raw-packet callback.
Called on every frame after PoliticianSense has processed it, so you can use raw packet access alongside sensing.
Definition at line 234 of file PoliticianSense.h.
|
inline |
Sets the state-change callback.
Fired once when the space transitions STILL→MOTION or MOTION→STILL. Do not call engine.tick() or blocking operations from inside the callback.
Definition at line 224 of file PoliticianSense.h.
|
inline |
Sets the stale-data timeout (ms).
If no new RSSI samples arrive for this duration, tick() skips processing to avoid acting on stale window data (e.g., when hopping away from the anchor). Default: 10000 ms
Definition at line 274 of file PoliticianSense.h.
|
inline |
Sets the variance threshold (dBm²) that triggers SENSE_MOTION.
Lower values = more sensitive; higher values = less false positives. Useful range: 3.0–15.0. Default: 6.0
Definition at line 243 of file PoliticianSense.h.
|
inline |
Sets the sliding window size in samples (clamped to [4, POLITICIAN_SENSE_MAX_WINDOW]).
At ~10 beacons/sec on a locked channel, 32 samples ≈ 3 seconds of history. Smaller = faster response; larger = smoother, fewer false triggers. Default: 32
Definition at line 250 of file PoliticianSense.h.
References POLITICIAN_SENSE_MAX_WINDOW.
|
inline |
Main worker — call from loop() alongside engine.tick().
Computes variance from the current window snapshot and fires the SenseCb if a STILL↔MOTION transition is detected.
Definition at line 283 of file PoliticianSense.h.
References millis(), POLITICIAN_SENSE_MAX_WINDOW, politician::SENSE_MOTION, and politician::SENSE_STILL.
|
staticconstexpr |
Motion hold-time (ms).
Definition at line 110 of file PoliticianSense.h.
|
staticconstexpr |
Max gap before ignoring stale data (ms).
Definition at line 111 of file PoliticianSense.h.
|
staticconstexpr |
Variance threshold (dBm²).
Definition at line 109 of file PoliticianSense.h.
|
staticconstexpr |
Sliding window (samples).
Definition at line 108 of file PoliticianSense.h.