From 9ddb6928068fc6e83cc083e5cd7a91092b53c9f6 Mon Sep 17 00:00:00 2001 From: pelgraine <140762863+pelgraine@users.noreply.github.com> Date: Mon, 30 Mar 2026 13:11:54 +1100 Subject: [PATCH] fix mqttsubscribe --- examples/simple_repeater/cellularmqtt.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/examples/simple_repeater/cellularmqtt.cpp b/examples/simple_repeater/cellularmqtt.cpp index 576c0710..2636d91f 100644 --- a/examples/simple_repeater/cellularmqtt.cpp +++ b/examples/simple_repeater/cellularmqtt.cpp @@ -792,8 +792,20 @@ restart: goto restart; } - mqttSubscribe(_topicCmd); - mqttSubscribe(_topicOta); +// Allow MQTT session to stabilise before subscribing + vTaskDelay(pdMS_TO_TICKS(2000)); + + // Subscribe with retry — the modem sometimes misses the first prompt + for (int i = 0; i < 3; i++) { + if (mqttSubscribe(_topicCmd)) break; + Serial.printf("[Cell] Subscribe retry %d for cmd topic\n", i + 1); + vTaskDelay(pdMS_TO_TICKS(1000)); + } + for (int i = 0; i < 3; i++) { + if (mqttSubscribe(_topicOta)) break; + Serial.printf("[Cell] Subscribe retry %d for ota topic\n", i + 1); + vTaskDelay(pdMS_TO_TICKS(1000)); + } _state = CellState::CONNECTED; _reconnectDelay = MQTT_RECONNECT_MIN;