Two efforts that landed together because the v2 topic work extends tables the health-telemetry effort added days earlier in the same files/functions, making them impractical to separate cleanly: Health/diagnostics telemetry (schema, Jul 13-17): - New Postgres tables: device_alert_events, device_boot_events, device_ping_samples, device_diagnostics_reports, plus a `source` column on device_logs to distinguish log origins - Query/service layer in pg_mqtt.py and database/__init__.py for inserting and listing this history, plus a "latest metrics" endpoint combining most-recent diagnostics + ping RTT per device - mqtt/router.py gains list endpoints for alert/boot/ping/diagnostics history, consumed by the upcoming Health tab MQTT v2 topic migration (Sep 21): - Heartbeat payload flattened per vesper_mqtt_topic_spec_v2.md, adding rssi/free_heap/state/ok fields - Command replies move to control/ack, device-initiated events to control/reports; mqtt/client.py subscribes to the new topic set and runs a ping_loop (wired up in main.py) for RTT sampling - mqtt/logger.py and pg_mqtt.py updated to parse and persist the new payload shape alongside the legacy fields for backwards compatibility Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
98 lines
2.4 KiB
Python
98 lines
2.4 KiB
Python
# MQTT live data — Phase 5: all functions now backed by Postgres
|
|
from database.pg_mqtt import (
|
|
init_db,
|
|
close_db,
|
|
purge_loop,
|
|
purge_old_data,
|
|
insert_log,
|
|
insert_heartbeat,
|
|
insert_command,
|
|
update_command_response,
|
|
get_logs,
|
|
get_heartbeats,
|
|
get_commands,
|
|
get_latest_heartbeats,
|
|
get_pending_command,
|
|
upsert_alert,
|
|
delete_alert,
|
|
get_alerts,
|
|
insert_alert_event,
|
|
get_latest_alert_events,
|
|
get_latest_alert_event,
|
|
get_alert_events,
|
|
insert_boot_event,
|
|
get_boot_events,
|
|
get_latest_boot_event,
|
|
insert_ping_sample,
|
|
get_ping_samples,
|
|
get_latest_ping_samples,
|
|
insert_diagnostics_report,
|
|
get_diagnostics_reports,
|
|
get_latest_diagnostics_report,
|
|
get_latest_diagnostics_reports,
|
|
insert_report,
|
|
get_reports,
|
|
delete_device_logs,
|
|
delete_device_heartbeats,
|
|
delete_device_commands,
|
|
delete_device_alert_events,
|
|
delete_device_current_alerts,
|
|
delete_device_boot_events,
|
|
delete_device_ping_samples,
|
|
delete_device_diagnostics_reports,
|
|
delete_device_reports,
|
|
partition_manager_loop,
|
|
ensure_current_partitions,
|
|
)
|
|
|
|
# SQLite connection — still used by melodies, builder, manufacturing, and crm
|
|
# modules that have not yet been cut over to Postgres.
|
|
from database.core import get_db
|
|
|
|
__all__ = [
|
|
"init_db",
|
|
"close_db",
|
|
"get_db",
|
|
"purge_loop",
|
|
"purge_old_data",
|
|
"insert_log",
|
|
"insert_heartbeat",
|
|
"insert_command",
|
|
"update_command_response",
|
|
"get_logs",
|
|
"get_heartbeats",
|
|
"get_commands",
|
|
"get_latest_heartbeats",
|
|
"get_pending_command",
|
|
"upsert_alert",
|
|
"delete_alert",
|
|
"get_alerts",
|
|
"insert_alert_event",
|
|
"get_latest_alert_events",
|
|
"get_latest_alert_event",
|
|
"get_alert_events",
|
|
"insert_boot_event",
|
|
"get_boot_events",
|
|
"get_latest_boot_event",
|
|
"insert_ping_sample",
|
|
"get_ping_samples",
|
|
"get_latest_ping_samples",
|
|
"insert_diagnostics_report",
|
|
"get_diagnostics_reports",
|
|
"get_latest_diagnostics_report",
|
|
"get_latest_diagnostics_reports",
|
|
"insert_report",
|
|
"get_reports",
|
|
"delete_device_logs",
|
|
"delete_device_heartbeats",
|
|
"delete_device_commands",
|
|
"delete_device_alert_events",
|
|
"delete_device_current_alerts",
|
|
"delete_device_boot_events",
|
|
"delete_device_ping_samples",
|
|
"delete_device_diagnostics_reports",
|
|
"delete_device_reports",
|
|
"partition_manager_loop",
|
|
"ensure_current_partitions",
|
|
]
|