Skip to content

Conversation

@HarukiToreda
Copy link
Contributor

@HarukiToreda HarukiToreda commented Jan 12, 2026

This PR adds message autosaving to the node.

Previously, messages were only saved to flash when the user manually shut down or restarted the device using the UI. If the node lost power or the reset button was pressed, all messages stored in RAM were lost.

With this change, messages are automatically saved to flash every 2 hours. The 2 hour interval was chosen to reduce flash wear, especially on nRF52 based devices where flash has a limited write lifespan. There is a manual overwrite to this interval that can be applied to other nodes like esp32 ex. -DMESSAGE_AUTOSAVE_INTERVAL_SEC=3600

Behavior

  • The autosave timer does not start on boot
  • The timer starts when the first new message is received
  • All messages received since the last save are marked as unsaved
  • When the 2 hour interval is reached, unsaved messages are written to flash
  • The autosave cadence continues automatically until reboot
  • If no new messages are received during an interval, the save is skipped and no flash write occurs
  • Deleting messages will also skip saving

This ensures messages survive unexpected power loss while keeping flash writes to a minimum.

@HarukiToreda HarukiToreda self-assigned this Jan 12, 2026
@HarukiToreda HarukiToreda added enhancement New feature or request baseui Issues directly related to BaseUI labels Jan 12, 2026
@HarukiToreda HarukiToreda requested a review from Xaositek January 12, 2026 06:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements autosave functionality for messages stored in device RAM. Previously, messages were only persisted to flash during manual shutdown/restart, resulting in data loss during unexpected power failures or reset button usage. The new feature automatically saves unsaved messages to flash at a configurable interval (intended to be 12 hours by default), with special logic to avoid unnecessary flash writes when no new messages have been received.

Changes:

  • Added autosave timer mechanism that triggers periodic saves of unsaved messages
  • Integrated autosave tick call into the main event loop
  • Refactored message menu to consolidate delete operations into a submenu
  • Added state tracking for unsaved messages and automatic persistence

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/main.cpp Added MessageStore.h include and messageStoreAutosaveTick() call in main loop
src/graphics/draw/MenuHandler.cpp Refactored message response menu to use DeleteMenu enum and removed duplicate delete logic
src/MessageStore.h Added messageStoreAutosaveTick() function declaration with appropriate guards
src/MessageStore.cpp Implemented core autosave logic including interval calculation, state tracking, and integration with add/save/load operations

@thebentern thebentern merged commit 3a0f352 into develop Jan 13, 2026
65 checks passed
vicliu624 pushed a commit to vicliu624/firmware that referenced this pull request Jan 13, 2026
* Autosave Messages

* fix

* Add logging, code cleanup, and add save on delete.

* We already save as part of delete messages, no need to do it again

* fix spelling errors

* Updating comment

---------

Co-authored-by: Jason P <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

baseui Issues directly related to BaseUI enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants