Firmware F-070 adds a fuller `crash` object (backtrace, backtrace_corrupted, elf_sha256) and a new `pre_crash` snapshot (uptime, heap stats, optional abort_msg) to boot_report and to telemetry.get_boot_history entries. - Migration c9d0e1f2a3b4: device_boot_events gains crash / pre_crash JSONB, stored verbatim so later additive fields need no migration. The legacy crash_* columns are still filled; old rows and old firmware are unchanged. JSON is bound as CAST(CAST(:x AS TEXT) AS JSONB): a bare JSONB cast makes asyncpg JSON-encode the already-encoded string a second time. - boot_report ingestion passes both objects through. - telemetry.get_boot_history replies (control/ack) are merged into boot history whoever sent the command: an entry matches an existing row on boot_count + reset_reason + time within 30 min (boot_count alone is not unique - the counter gets reset), and only fills crash/pre_crash the row lacks; unmatched entries are boots we never saw live and are inserted at the device's timestamp; entries without ts are skipped. - GET /api/mqtt/crash-groups: fault boots grouped by abort_msg with hex addresses stripped, else task + exception cause, else reset reason. When abort_msg is present, pc/exc_cause describe abort() itself and are ignored for grouping. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
102 lines
2.5 KiB
Python
102 lines
2.5 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,
|
|
merge_device_boot_history,
|
|
get_crash_events,
|
|
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",
|
|
"merge_device_boot_history",
|
|
"get_crash_events",
|
|
"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",
|
|
]
|