Skip to content

Commit 431a0ab

Browse files
authored
Merge pull request #32 from pdxlocations/fix-reboot-mt
Maybe fix lost communication after a node reboot or power failure
2 parents edfaa9d + d2a918b commit 431a0ab

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/mt_protocol.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
pb_byte_t pb_buf[PB_BUFSIZE+4];
1414
size_t pb_size = 0; // Number of bytes currently in the buffer
1515

16+
// Nonce to request only my nodeinfo and skip other nodes in the db
17+
#define SPECIAL_NONCE 69420
18+
1619
// Wait this many msec if there's nothing new on the channel
1720
#define NO_NEWS_PAUSE 25
1821

@@ -220,7 +223,7 @@ bool handle_mesh_packet(meshtastic_MeshPacket *meshPacket) {
220223
return true;
221224
}
222225

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

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

237+
// Be prepared to request a node report to re-establish flow after an MT reboot
238+
meshtastic_ToRadio toRadio = meshtastic_ToRadio_init_default;
239+
toRadio.which_payload_variant = meshtastic_ToRadio_want_config_id_tag;
240+
toRadio.want_config_id = SPECIAL_NONCE;
241+
234242
if (!status) {
235243
d("Decoding failed");
236244
return false;
@@ -245,6 +253,8 @@ bool handle_packet(uint32_t now, size_t payload_len) {
245253
return handle_config_complete_id(now, fromRadio.config_complete_id);
246254
case meshtastic_FromRadio_packet_tag:
247255
return handle_mesh_packet(&fromRadio.packet);
256+
case meshtastic_FromRadio_rebooted_tag:
257+
_mt_send_toRadio(toRadio);
248258
default:
249259
if (mt_debugging) {
250260
// Rate limit
@@ -273,6 +283,8 @@ void mt_protocol_check_packet(uint32_t now) {
273283

274284
if (pb_buf[0] != MT_MAGIC_0 || pb_buf[1] != MT_MAGIC_1) {
275285
d("Got bad magic");
286+
memset(pb_buf, 0, PB_BUFSIZE);
287+
pb_size = 0;
276288
return;
277289
}
278290

0 commit comments

Comments
 (0)