@electrik said in Unblocking loop when DHCP fails: MQTT_SOCKET_TIMEOUT Thanks for your suggestion. Unfortunately it was not enough, but I manipulated in ethernet library and right now I have enough CPU time in my main loop (reading 16 buttons state and control 15 GPIO outputs). Here is what I changed so far. I'm not sure about it long time stability, but it works on my desk: diff --git a/.pio/libdeps/megaatmega2560/Ethernet/src/Ethernet.h b/.pio/libdeps/megaatmega2560/Ethernet/src/Ethernet.h index 376e6c5..9d5e6b4 100644 --- a/.pio/libdeps/megaatmega2560/Ethernet/src/Ethernet.h +++ b/.pio/libdeps/megaatmega2560/Ethernet/src/Ethernet.h @@ -213,8 +213,8 @@ public: class EthernetClient : public Client { public: - EthernetClient() : sockindex(MAX_SOCK_NUM), _timeout(1000) { } - EthernetClient(uint8_t s) : sockindex(s), _timeout(1000) { } + EthernetClient() : sockindex(MAX_SOCK_NUM), _timeout(5) { } + EthernetClient(uint8_t s) : sockindex(s), _timeout(5) { } uint8_t status(); virtual int connect(IPAddress ip, uint16_t port); diff --git a/.pio/libdeps/megaatmega2560/MySensors/core/MyGatewayTransportMQTTClient.cpp b/.pio/libdeps/megaatmega2560/MySensors/core/MyGatewayTransportMQTTClient.cpp index 12cfd67..754ae03 100644 --- a/.pio/libdeps/megaatmega2560/MySensors/core/MyGatewayTransportMQTTClient.cpp +++ b/.pio/libdeps/megaatmega2560/MySensors/core/MyGatewayTransportMQTTClient.cpp @@ -155,7 +155,7 @@ bool reconnectMQTT(void) return true; } - delay(1000); + delay(1); GATEWAY_DEBUG(PSTR("!GWT:RMQ:FAIL\n")); return false; } @@ -190,7 +190,7 @@ bool gatewayTransportConnect(void) Ethernet.localIP()[0], Ethernet.localIP()[1], Ethernet.localIP()[2], Ethernet.localIP()[3]); // give the Ethernet interface a second to initialize - delay(1000); + delay(10); #endif return true; }