Closed warshaa closed 3 years ago
The remote is closing the connection. Try modifying the keep-alive in PubSubClient (setKeepAlive(uint16_t keepAlive)
). The default is 15s.
I set the keep alive 600 seconds , still same thing
Make the keep-alive shorter, not longer. You want to ping the server more often to keep the connection open, not less often.
Hi Sara ,thanks for your reply.
I have tried different keepalive values but it seems that the connection will close in less than one minute if the keep alive is higher than 1 minute. as you mentioned decreasing the keep alive would solve the problem. However with less than 1 minute keep alive the problem is the device would consume more power and data which are very limited in my situation, moreover the broker charges me on each packet transferred between the client and the broker including ping for keep alive.
problem solved !
the keep alive time has nothing wrong , the problem was in my setup function code which cause the tinyGsm client close the tcp connection every 1000ms.
thanks ,,
Hi ,
I'm using the esp32 with sim868 to connect mqtt broker.
it connects to the broker and works normally however it keep disconnecting randomly every few seconds it connects back .
main loop :
here is serial output with the debug enabled