Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maybe fix lost communication after a node reboot or power failure #32

Merged
merged 3 commits into from
Dec 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/mt_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
pb_byte_t pb_buf[PB_BUFSIZE+4];
size_t pb_size = 0; // Number of bytes currently in the buffer

// Nonce to request only my nodeinfo and skip other nodes in the db
#define SPECIAL_NONCE 69420

// Wait this many msec if there's nothing new on the channel
#define NO_NEWS_PAUSE 25

Expand Down Expand Up @@ -220,7 +223,7 @@ bool handle_mesh_packet(meshtastic_MeshPacket *meshPacket) {
return true;
}

// Parse a packet that came in, and handle it. Return true iff we were able to parse it.
// Parse a packet that came in, and handle it. Return true if we were able to parse it.
bool handle_packet(uint32_t now, size_t payload_len) {
meshtastic_FromRadio fromRadio = meshtastic_FromRadio_init_zero;

Expand All @@ -231,6 +234,11 @@ bool handle_packet(uint32_t now, size_t payload_len) {
memmove(pb_buf, pb_buf+4+payload_len, PB_BUFSIZE-4-payload_len);
pb_size -= 4 + payload_len;

// Be prepared to request a node report to re-establish flow after an MT reboot
meshtastic_ToRadio toRadio = meshtastic_ToRadio_init_default;
toRadio.which_payload_variant = meshtastic_ToRadio_want_config_id_tag;
toRadio.want_config_id = SPECIAL_NONCE;

Copy link
Member

Choose a reason for hiding this comment

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

do we want the config again? if not, use the magic 'skip config'

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it possible the node rebooted due to a config change? Maybe getting the config again could be useful?

I'm looking around but cant find a reference to skip config

Copy link
Member

Choose a reason for hiding this comment

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

I think caveman referred to the SPECIAL_NONCE. It will only skip sending NodeInfos of other nodes.

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense to only pull in your own config and not other nodes. I dug around and have determined that implementing this is outside of my current skillset.

Copy link
Member

Choose a reason for hiding this comment

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

Replacing the random want_config_id with 69420 should do it 😀

Copy link
Member Author

Choose a reason for hiding this comment

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

Ya know I'd typed that in and thought, "there's no way it's that easy" and gave up. Also gave my wife a laugh with that one.

if (!status) {
d("Decoding failed");
return false;
Expand All @@ -245,6 +253,8 @@ bool handle_packet(uint32_t now, size_t payload_len) {
return handle_config_complete_id(now, fromRadio.config_complete_id);
case meshtastic_FromRadio_packet_tag:
return handle_mesh_packet(&fromRadio.packet);
case meshtastic_FromRadio_rebooted_tag:
_mt_send_toRadio(toRadio);
default:
if (mt_debugging) {
// Rate limit
Expand Down Expand Up @@ -273,6 +283,8 @@ void mt_protocol_check_packet(uint32_t now) {

if (pb_buf[0] != MT_MAGIC_0 || pb_buf[1] != MT_MAGIC_1) {
d("Got bad magic");
memset(pb_buf, 0, PB_BUFSIZE);
pb_size = 0;
pdxlocations marked this conversation as resolved.
Show resolved Hide resolved
return;
}

Expand Down