mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-03 03:09:59 +00:00
let the library handle the reconnect, manually do it after 5 seconds
This commit is contained in:
parent
5cec370cf5
commit
1fc5d70221
@ -5,7 +5,7 @@
|
|||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "mesh/http/WebServer.h"
|
#include "mesh/http/WebServer.h"
|
||||||
#include "mesh/wifi/WiFiServerAPI.h"
|
#include "mesh/api/WiFiServerAPI.h"
|
||||||
#include "mqtt/MQTT.h"
|
#include "mqtt/MQTT.h"
|
||||||
#include "target_specific.h"
|
#include "target_specific.h"
|
||||||
#include <ESPmDNS.h>
|
#include <ESPmDNS.h>
|
||||||
@ -55,11 +55,13 @@ static int32_t reconnectWiFi()
|
|||||||
|
|
||||||
// Make sure we clear old connection credentials
|
// Make sure we clear old connection credentials
|
||||||
WiFi.disconnect(false, true);
|
WiFi.disconnect(false, true);
|
||||||
|
|
||||||
LOG_INFO("Reconnecting to WiFi access point %s\n",wifiName);
|
LOG_INFO("Reconnecting to WiFi access point %s\n",wifiName);
|
||||||
|
|
||||||
WiFi.mode(WIFI_MODE_STA);
|
delay(5000);
|
||||||
WiFi.begin(wifiName, wifiPsw);
|
|
||||||
|
if (!WiFi.isConnected()) {
|
||||||
|
WiFi.begin(wifiName, wifiPsw);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef DISABLE_NTP
|
#ifndef DISABLE_NTP
|
||||||
@ -167,7 +169,7 @@ bool initWifi()
|
|||||||
WiFi.mode(WIFI_MODE_STA);
|
WiFi.mode(WIFI_MODE_STA);
|
||||||
WiFi.setHostname(ourHost);
|
WiFi.setHostname(ourHost);
|
||||||
WiFi.onEvent(WiFiEvent);
|
WiFi.onEvent(WiFiEvent);
|
||||||
WiFi.setAutoReconnect(false);
|
WiFi.setAutoReconnect(true);
|
||||||
WiFi.setSleep(false);
|
WiFi.setSleep(false);
|
||||||
if (config.network.address_mode == Config_NetworkConfig_AddressMode_STATIC && config.network.ipv4_config.ip != 0) {
|
if (config.network.address_mode == Config_NetworkConfig_AddressMode_STATIC && config.network.ipv4_config.ip != 0) {
|
||||||
WiFi.config(config.network.ipv4_config.ip,
|
WiFi.config(config.network.ipv4_config.ip,
|
||||||
@ -182,7 +184,7 @@ bool initWifi()
|
|||||||
|
|
||||||
WiFi.onEvent(
|
WiFi.onEvent(
|
||||||
[](WiFiEvent_t event, WiFiEventInfo_t info) {
|
[](WiFiEvent_t event, WiFiEventInfo_t info) {
|
||||||
LOG_WARN("WiFi lost connection. Reason: %s", info.wifi_sta_disconnected.reason);
|
LOG_WARN("WiFi lost connection. Reason: %d\n", info.wifi_sta_disconnected.reason);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
If we are disconnected from the AP for some reason,
|
If we are disconnected from the AP for some reason,
|
||||||
|
@ -207,14 +207,17 @@ void MQTT::reconnect()
|
|||||||
|
|
||||||
sendSubscriptions();
|
sendSubscriptions();
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR("Failed to contact MQTT server (%d/10)...\n",reconnectCount);
|
|
||||||
#if HAS_WIFI && !defined(ARCH_PORTDUINO)
|
#if HAS_WIFI && !defined(ARCH_PORTDUINO)
|
||||||
if (reconnectCount > 9) {
|
LOG_ERROR("Failed to contact MQTT server (%d/5)...\n",reconnectCount + 1);
|
||||||
|
if (reconnectCount >= 4) {
|
||||||
needReconnect = true;
|
needReconnect = true;
|
||||||
wifiReconnect->setIntervalFromNow(1000);
|
wifiReconnect->setIntervalFromNow(0);
|
||||||
|
reconnectCount = 0;
|
||||||
|
} else {
|
||||||
|
reconnectCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
reconnectCount++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -284,7 +287,6 @@ int32_t MQTT::runOnce()
|
|||||||
|
|
||||||
String topic = cryptTopic + env->channel_id + "/" + owner.id;
|
String topic = cryptTopic + env->channel_id + "/" + owner.id;
|
||||||
LOG_INFO("publish %s, %u bytes from queue\n", topic.c_str(), numBytes);
|
LOG_INFO("publish %s, %u bytes from queue\n", topic.c_str(), numBytes);
|
||||||
|
|
||||||
|
|
||||||
pubSub.publish(topic.c_str(), bytes, numBytes, false);
|
pubSub.publish(topic.c_str(), bytes, numBytes, false);
|
||||||
|
|
||||||
@ -299,7 +301,7 @@ int32_t MQTT::runOnce()
|
|||||||
}
|
}
|
||||||
mqttPool.release(env);
|
mqttPool.release(env);
|
||||||
}
|
}
|
||||||
return 20;
|
return 200;
|
||||||
} else {
|
} else {
|
||||||
return 30000;
|
return 30000;
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
#include <EthernetClient.h>
|
#include <EthernetClient.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MAX_MQTT_QUEUE 32
|
#define MAX_MQTT_QUEUE 16
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Our wrapper/singleton for sending/receiving MQTT "udp" packets. This object isolates the MQTT protocol implementation from
|
* Our wrapper/singleton for sending/receiving MQTT "udp" packets. This object isolates the MQTT protocol implementation from
|
||||||
|
Loading…
Reference in New Issue
Block a user