feat: Termux sensor dashboard (Issue #574) #578

Merged
sl-jetson merged 1 commits from sl-android/issue-574-sensor-dashboard into main 2026-03-14 12:13:52 -04:00
Collaborator

Summary

  • phone/sensor_dashboard.py: publishes Android phone sensors to SaltyBot MQTT broker from Termux
Sensor Topic Rate Source
IMU (accel + gyro) saltybot/phone/imu 5 Hz termux-sensor -s accelerometer/gyroscope -n 1
GPS saltybot/phone/gps 1 Hz termux-location -p gps -r once (→ network fallback)
Battery saltybot/phone/battery 1 Hz termux-battery-status

JSON payloads:

{"ts":1710000000.0,"accel":{"x":0.12,"y":-0.05,"z":9.81},"gyro":{"x":0.01,"y":0.0,"z":0.0}}
{"ts":1710000000.0,"lat":45.123,"lon":-73.456,"alt_m":12.3,"accuracy_m":3.5,"speed_ms":0.0,"bearing_deg":0.0,"provider":"gps"}
{"ts":1710000000.0,"pct":87,"charging":true,"temp_c":28.5,"health":"GOOD","plugged":"AC"}

MQTT: paho-mqtt with loop_start() + on_connect/on_disconnect callbacks — automatic reconnect with exponential back-off (2 s → 60 s max), no message loss on transient disconnects

Threading: one SensorPoller daemon thread per sensor; rate enforced by wall-clock elapsed time accounting for termux-api call latency

Status: 30 s log line with per-poller publish/error counts + MQTT state

Flags: --broker, --port, --imu-hz, --gps-hz, --bat-hz, --qos, --no-imu, --no-gps, --no-battery, --debug

Test plan

  • python3 -m py_compile phone/sensor_dashboard.py — syntax clean
  • On Termux: pip install paho-mqtt then python3 phone/sensor_dashboard.py --broker <IP> --debug
  • mosquitto_sub -h <IP> -t 'saltybot/phone/#' -v — see all three topics publishing
  • IMU: verify ~5 msg/s on saltybot/phone/imu with accel.z ≈ 9.8
  • GPS: verify lat/lon populated outdoors; accuracy_m reasonable
  • Battery: pct matches phone status bar; charging flips when plugged/unplugged
  • Kill broker and restart — verify auto-reconnect within 60 s
  • --no-gps — only imu + battery topics appear

🤖 Generated with Claude Code

## Summary - `phone/sensor_dashboard.py`: publishes Android phone sensors to SaltyBot MQTT broker from Termux | Sensor | Topic | Rate | Source | |--------|-------|------|--------| | IMU (accel + gyro) | `saltybot/phone/imu` | 5 Hz | `termux-sensor -s accelerometer/gyroscope -n 1` | | GPS | `saltybot/phone/gps` | 1 Hz | `termux-location -p gps -r once` (→ network fallback) | | Battery | `saltybot/phone/battery` | 1 Hz | `termux-battery-status` | **JSON payloads:** ```json {"ts":1710000000.0,"accel":{"x":0.12,"y":-0.05,"z":9.81},"gyro":{"x":0.01,"y":0.0,"z":0.0}} {"ts":1710000000.0,"lat":45.123,"lon":-73.456,"alt_m":12.3,"accuracy_m":3.5,"speed_ms":0.0,"bearing_deg":0.0,"provider":"gps"} {"ts":1710000000.0,"pct":87,"charging":true,"temp_c":28.5,"health":"GOOD","plugged":"AC"} ``` **MQTT:** paho-mqtt with `loop_start()` + `on_connect`/`on_disconnect` callbacks — automatic reconnect with exponential back-off (2 s → 60 s max), no message loss on transient disconnects **Threading:** one `SensorPoller` daemon thread per sensor; rate enforced by wall-clock elapsed time accounting for termux-api call latency **Status:** 30 s log line with per-poller publish/error counts + MQTT state **Flags:** `--broker`, `--port`, `--imu-hz`, `--gps-hz`, `--bat-hz`, `--qos`, `--no-imu`, `--no-gps`, `--no-battery`, `--debug` ## Test plan - [ ] `python3 -m py_compile phone/sensor_dashboard.py` — syntax clean - [ ] On Termux: `pip install paho-mqtt` then `python3 phone/sensor_dashboard.py --broker <IP> --debug` - [ ] `mosquitto_sub -h <IP> -t 'saltybot/phone/#' -v` — see all three topics publishing - [ ] IMU: verify ~5 msg/s on `saltybot/phone/imu` with `accel.z ≈ 9.8` - [ ] GPS: verify lat/lon populated outdoors; `accuracy_m` reasonable - [ ] Battery: `pct` matches phone status bar; `charging` flips when plugged/unplugged - [ ] Kill broker and restart — verify auto-reconnect within 60 s - [ ] `--no-gps` — only imu + battery topics appear 🤖 Generated with [Claude Code](https://claude.com/claude-code)
sl-jetson added 1 commit 2026-03-14 11:53:23 -04:00
Add phone/sensor_dashboard.py — publishes phone sensors to SaltyBot MQTT:

- IMU  → saltybot/phone/imu     @ 5 Hz  (accelerometer + gyroscope via
  termux-sensor -s <name> -n 1)
- GPS  → saltybot/phone/gps     @ 1 Hz  (lat/lon/alt/accuracy/speed/bearing
  via termux-location; GPS→network fallback on cold start)
- Battery → saltybot/phone/battery @ 1 Hz (pct/charging/temp/health/plugged
  via termux-battery-status)
- paho-mqtt with loop_start() + on_connect/on_disconnect callbacks for
  automatic reconnect (exponential back-off, max 60 s)
- Each sensor runs in its own daemon thread (SensorPoller); rate enforced
  by wall-clock sleep accounting for read latency
- 30 s status log: per-poller publish/error counts + MQTT state
- Flags: --broker, --port, --imu-hz, --gps-hz, --bat-hz, --qos,
  --no-imu, --no-gps, --no-battery, --debug

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
sl-jetson merged commit b2f01b42f3 into main 2026-03-14 12:13:52 -04:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: seb/saltylab-firmware#578
No description provided.