From b68581c06232d0d1e4af99088106472562208559 Mon Sep 17 00:00:00 2001 From: Ptitlouis6012 <169227848+Ptitlouis6012@users.noreply.github.com> Date: Thu, 15 Oct 2026 07:09:32 +0200 Subject: [PATCH] Bound the TCP connect to a printer that does not answer WiFiClientSecure waits thirty seconds for a host that does not answer, and the loop watchdog is thirty seconds. The MQTT socket timeout and the TLS handshake timeout set beside it bound neither: the connect has its own. So a LAN Bambu or Anycubic that was switched off froze the panel for the whole wait and then the watchdog restarted the box, which tried the same printer again - a restart every fifty seconds until the printer was turned on, with the touch dead and the account stuck orange because its exchange could never finish. net_.setTimeout() bounds the connect: four seconds for a printer on the LAN, eight for the Bambu cloud broker, which is across the internet. A printer that is off now fails in four seconds and the link logic retries as it always did. --- firmware/src/backend_anycubic.cpp | 4 ++++ firmware/src/backend_bambu.cpp | 6 ++++++ firmware/src/bambu_cloud.cpp | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/firmware/src/backend_anycubic.cpp b/firmware/src/backend_anycubic.cpp index 33f7618..ffabf8c 100644 --- a/firmware/src/backend_anycubic.cpp +++ b/firmware/src/backend_anycubic.cpp @@ -191,6 +191,10 @@ void AnycubicBackend::begin(const PrinterCfg& cfg) { // like to the person holding it. Nothing here is worth more than a few // seconds; a failed attempt is retried anyway. mqtt_.setSocketTimeout(4); + // And the TCP connect, which neither of those bounds: the client waits + // thirty seconds for a host that does not answer - as long as the loop + // watchdog - so a printer switched off restarted the box. + net_.setTimeout(4); net_.setHandshakeTimeout(5); mqtt_.setCallback([this](char*, uint8_t* p, unsigned int l) { onMqtt(p, l); }); status_ = "Anycubic: connecting..."; diff --git a/firmware/src/backend_bambu.cpp b/firmware/src/backend_bambu.cpp index 882172d..1a29631 100644 --- a/firmware/src/backend_bambu.cpp +++ b/firmware/src/backend_bambu.cpp @@ -245,6 +245,12 @@ void BambuBackend::begin(const PrinterCfg& cfg) { // like to the person holding it. Nothing here is worth more than a few // seconds; a failed attempt is retried anyway. mqtt_.setSocketTimeout(4); + // The TCP connect has its own limit, and it is not either of the two around + // it: WiFiClientSecure waits THIRTY seconds for a host that does not + // answer, which is exactly the loop watchdog. A printer that is switched + // off then froze the panel for half a minute and restarted the box, again + // and again, until somebody turned the printer on. + net_.setTimeout(4); net_.setHandshakeTimeout(5); mqtt_.setCallback([this](char*, uint8_t* p, unsigned int l) { onMqtt(p, l); }); lastTry_ = 0; diff --git a/firmware/src/bambu_cloud.cpp b/firmware/src/bambu_cloud.cpp index 3d6c7e0..a5bb666 100644 --- a/firmware/src/bambu_cloud.cpp +++ b/firmware/src/bambu_cloud.cpp @@ -53,6 +53,11 @@ void open() { // against, the same situation as a printer on the LAN; trust comes from // the account session Tiger Studio obtained. See net/tls.h. s_net->setInsecure(); + // The TCP connect is bounded on its own: the client's default is thirty + // seconds, as long as the loop watchdog, and an internet link that has gone + // silent would take the whole box down with it. Longer than a LAN printer's + // four - this is a host across the internet. + s_net->setTimeout(8); s_net->setHandshakeTimeout(5); // A full report from a four-unit X1 is about 50 KB and has to fit whole. // It lands in PSRAM - anything over 4 KB does on this build - so the size