Skip to content

Alert user on LCD and DFPlayer when MQTT connection is lost#510

Open
Yukti007 wants to merge 3 commits intomainfrom
task/86-krake-should-alert-user-when-wifi-goes-off-line-spi-and-usbserial-too-firmware-gpad-api-v019-does-not
Open

Alert user on LCD and DFPlayer when MQTT connection is lost#510
Yukti007 wants to merge 3 commits intomainfrom
task/86-krake-should-alert-user-when-wifi-goes-off-line-spi-and-usbserial-too-firmware-gpad-api-v019-does-not

Conversation

@Yukti007
Copy link
Copy Markdown
Collaborator

Links

What & Why

  • When the Krake loses its MQTT connection, the user previously had no indication — the LCD stayed on the last known alarm state with no warning that the data was stale.
  • On disconnect, the LCD now immediately shows "MQTT DISCONNECTED / Alarm status stale / Reconnecting..." with backlight on, and the DFPlayer plays a problem-level alert sound.
  • On reconnect, the LCD automatically restores the alarm status display.
  • Implemented by detecting the MQTT connection state transition in the main loop using client.connected() before and after client.loop(), so the alert fires once on drop and the restore fires once on recovery.

Validation / How to Verify

  • Flash the firmware and confirm normal operation — LCD shows alarm status as usual.
  • Disconnect the Krake from WiFi (or take the broker offline) and confirm the LCD switches to the "MQTT DISCONNECTED" screen and the DFPlayer plays a sound.
  • Restore WiFi/broker and confirm the LCD returns to the alarm status display.
  • Open the menu while MQTT is connected, then drop the connection — confirm the menu is not interrupted by the LCD override.

Artifacts (attach if relevant)

  • Screenshots / PDFs / STLs
  • Logs

Checklist

  • Only related changes GPAD_API.ino , GPAD_HAL.cpp and GPAD_HAL.h
  • Folder structure respected, work directory : Firmware/GPAD_API/GPAD_API
  • Validation steps written

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: abf674ac43

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread Firmware/GPAD_API/GPAD_API/GPAD_API.ino Outdated
Comment on lines +1816 to +1818
if (client.connected() && !wasConnected && !running_menu)
{
restoreAlarmLevel(&debugSerial);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore alarm LCD after reconnecting from active session

When MQTT drops from an already-connected state, wasConnected is true, so this reconnect path can show the disconnect screen and then immediately reconnect in the same iteration, but the restore check is gated on !wasConnected and therefore never runs. In that case the LCD can remain stuck on "MQTT DISCONNECTED" even though client.connected() is true, until some unrelated UI refresh happens (e.g., alarm update or menu exit). This breaks the intended automatic recovery behavior after transient disconnects.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codex review

@Yukti007
Copy link
Copy Markdown
Collaborator Author

So looking at the discussion between @RobertLRead and @ForrestErickson , there were a few directions floated — rotating the LCD to show MQTT status periodically, having the PMD send heartbeats and tracking stale messages, giving alarms an expiry time, or just reacting directly to the MQTT connection state.

The rotating LCD felt too passive — you'd only see it if you happened to be watching at the right second. The heartbeat/stale detection idea is honestly the right long-term fix but it needs the PMD side to change too, and it opens up the whole alarm management question (who owns the alarm, when is it stale, who clears it) which felt bigger than what this issue was asking for.

So I went with the MQTT state approach since it was called out as "probably easier" in the thread. Basically the Krake now checks if MQTT was connected before and after each loop — the moment it drops, LCD shows the disconnected screen and DFPlayer fires a sound, and when it comes back the alarm display restores automatically. Entirely self-contained, no PMD changes needed.

The heartbeat/stale detection is still the better solution for catching cases where WiFi is fine but messages just stop coming — happy to open a follow-up issue for that if that makes sense. Open to any thoughts on the approach here.

@Yukti007 Yukti007 requested a review from nk25719 April 29, 2026 22:16
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 236519141f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1810 to +1813
if (wasConnected && !running_menu)
{
showMqttStatusLCD(false);
playAlarmLevel(problem);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Show disconnect warning after menu closes

When MQTT drops while running_menu is true, this guard skips showMqttStatusLCD(false) on the first disconnect iteration; on subsequent iterations wasConnected is already false, so the warning can never be shown after the user exits the menu. In that scenario the LCD returns to normal alarm text (restoreAlarmLevel) even though the data is stale, and it stays that way until reconnection succeeds, which defeats the disconnect-alert behavior this change introduces.

Useful? React with 👍 / 👎.

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.

KRAKE Should Alert User when WiFi goes Off Line, SPI and USB/Serial Too, Firmware GPAD-API V0.19 Does Not.

1 participant