Skip to content

Commit

Permalink
Merge pull request #32 from pdxlocations/fix-reboot-mt
Browse files Browse the repository at this point in the history
Maybe fix lost communication after a node reboot or power failure
  • Loading branch information
GUVWAF authored Dec 15, 2024
2 parents edfaa9d + d2a918b commit 431a0ab
Showing 1 changed file with 13 additions and 1 deletion.
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;

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;
return;
}

Expand Down

0 comments on commit 431a0ab

Please sign in to comment.