try to fix mqtt connect issue
This commit is contained in:
parent
4e4c9426ff
commit
bfc9c61669
1 changed files with 4 additions and 3 deletions
|
@ -48,10 +48,11 @@ void connect() {
|
||||||
|
|
||||||
if (WiFi.status() == WL_CONNECTED)
|
if (WiFi.status() == WL_CONNECTED)
|
||||||
{
|
{
|
||||||
Serial.print("\nconnecting...");
|
Serial.print("\nconnecting mqtt...");
|
||||||
timeout=0;
|
timeout=0;
|
||||||
#define CONNECT_TIMEOUT 5
|
#define CONNECT_TIMEOUT 5
|
||||||
while (!client.connect(client_id, "public", "public") && timeout<CONNECT_TIMEOUT) {
|
//while (!client.connect(client_id, "public", "public") && timeout<CONNECT_TIMEOUT) {
|
||||||
|
while (!client.connect(client_id) && timeout<CONNECT_TIMEOUT) {
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
delay(1000);
|
delay(1000);
|
||||||
timeout++;
|
timeout++;
|
||||||
|
@ -181,7 +182,7 @@ bool mqtt_loop(unsigned long loopmillis) {
|
||||||
last_client_loop=loopmillis;
|
last_client_loop=loopmillis;
|
||||||
client.loop();
|
client.loop();
|
||||||
|
|
||||||
if (client.connected()) {
|
if (!client.connected()) {
|
||||||
if (loopmillis-last_connection_try>RETRY_CONNECTION_INTERVAL) {
|
if (loopmillis-last_connection_try>RETRY_CONNECTION_INTERVAL) {
|
||||||
last_connection_try=loopmillis;
|
last_connection_try=loopmillis;
|
||||||
connect();
|
connect();
|
||||||
|
|
Loading…
Add table
Reference in a new issue