Skip to content

MQTTManager: send NSPanels the current time - #404

Merged
tpanajott merged 4 commits into
NSPManager:develfrom
jamesmulcahy:feat/manager-epoch
Oct 20, 2026
Merged

tpanajott merged 4 commits into
NSPManager:develfrom
jamesmulcahy:feat/manager-epoch

Conversation

@jamesmulcahy

@jamesmulcahy jamesmulcahy commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Manager side of #402 (option A): the manager tells panels the current time so they can set their own clock with settimeofday(), for media player progress and the other uses listed in the discussion.

The topic

nspanel/mqttmanager_<address>/status/epoch carries Unix time in milliseconds as a decimal string, e.g. 1760724061234. It is not retained, so a panel only ever receives a time that was current when it was sent.

It is sent:

  • every minute, alongside status/time and status/date
  • whenever the manager (re)connects to MQTT
  • whenever a panel reports online, so a panel that has just booted or reconnected doesn't wait up to a minute for a clock

Panels must subscribe to it before publishing online, or they miss that reply. No protobuf changes are needed.

Changes

  • MQTT_Manager::publish_if_connected(topic, make_payload) sends over MQTT only when connected. It never buffers or retries, because a buffered time would be delivered stale after reconnecting. The payload is made after taking the client lock, so it is current when sent. It also drops messages until the backlog after reconnecting has been sent (MQTTManager: don't let new messages overtake ones buffered while disconnected #403).
  • MQTT_Manager::attach_connected_callback() is called at the end of every (re)connect.
  • The STOMP mirror code moved into _mirror_to_stomp(), shared by both publish paths. The epoch is mirrored unretained to mqtt/.../status/epoch whether or not MQTT is connected, so web UI subscribers only ever see live values.
  • New ManagerClock module (include/manager_clock/). It skips sending if the host clock reads earlier than 2025-01-01, such as on a Pi before NTP sync, and warns once until the clock is set.

🤖 Generated with Claude Code

Comment thread docker/MQTTManager/include/mqtt_manager/mqtt_manager.cpp
Comment thread docker/MQTTManager/include/mqtt_manager/mqtt_manager.cpp Outdated
Comment thread docker/MQTTManager/src/main.cpp Outdated
jamesmulcahy and others added 4 commits October 20, 2026 07:24
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
publish_time_and_date() moves out of main.cpp unchanged, as
ManagerClock::_run_clock_thread(). ManagerClock::start() attaches the
MQTT connected callback and starts the thread, so main.cpp makes one call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
STOMP is a full mirror of what is published, so the message goes to STOMP
before the connected check rather than only after a successful MQTT send.
The return value still means "sent over MQTT".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants