mirror of https://github.com/arendst/Tasmota.git
parent
9ee8461f3d
commit
6fac233821
|
@ -740,6 +740,11 @@ bool WifiHostByName(const char* aHostname, IPAddress& aResult) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool WifiDnsPresent(const char* aHostname) {
|
||||
IPAddress aResult;
|
||||
return WifiHostByName(aHostname, aResult);
|
||||
}
|
||||
|
||||
void WifiPollNtp() {
|
||||
static uint8_t ntp_sync_minute = 0;
|
||||
static uint32_t ntp_run_time = 0;
|
||||
|
|
|
@ -1038,6 +1038,19 @@ void MqttReconnect(void) {
|
|||
|
||||
AddLog(LOG_LEVEL_INFO, PSTR(D_LOG_MQTT D_ATTEMPTING_CONNECTION));
|
||||
|
||||
if (MqttClient.connected()) { MqttClient.disconnect(); }
|
||||
|
||||
MqttSetClientTimeout();
|
||||
|
||||
MqttClient.setCallback(MqttDataHandler);
|
||||
|
||||
// Keep using hostname to solve rc -4 issues
|
||||
if (!WifiDnsPresent(SettingsText(SET_MQTT_HOST))) {
|
||||
MqttDisconnected(-5); // MQTT_DNS_DISCONNECTED
|
||||
return;
|
||||
}
|
||||
MqttClient.setServer(SettingsText(SET_MQTT_HOST), Settings->mqtt_port);
|
||||
|
||||
if (2 == Mqtt.initial_connection_state) { // Executed once just after power on and wifi is connected
|
||||
Mqtt.initial_connection_state = 1;
|
||||
}
|
||||
|
@ -1051,10 +1064,6 @@ void MqttReconnect(void) {
|
|||
mqtt_pwd = SettingsText(SET_MQTT_PWD);
|
||||
}
|
||||
|
||||
if (MqttClient.connected()) { MqttClient.disconnect(); }
|
||||
MqttSetClientTimeout();
|
||||
MqttClient.setCallback(MqttDataHandler);
|
||||
|
||||
#ifdef USE_MQTT_TLS
|
||||
uint32_t mqtt_connect_time = millis();
|
||||
if (Mqtt.mqtt_tls) {
|
||||
|
@ -1099,17 +1108,8 @@ void MqttReconnect(void) {
|
|||
allow_all_fingerprints |= learn_fingerprint2;
|
||||
tlsClient->setPubKeyFingerprint(Settings->mqtt_fingerprint[0], Settings->mqtt_fingerprint[1], allow_all_fingerprints);
|
||||
}
|
||||
|
||||
MqttClient.setServer(SettingsText(SET_MQTT_HOST), Settings->mqtt_port);
|
||||
#else // No USE_MQTT_TLS
|
||||
MqttClient.setClient(EspClient);
|
||||
|
||||
IPAddress mqtt_host_ip;
|
||||
if (!WifiHostByName(SettingsText(SET_MQTT_HOST), mqtt_host_ip)) {
|
||||
MqttDisconnected(-5); // MQTT_DNS_DISCONNECTED
|
||||
return;
|
||||
}
|
||||
MqttClient.setServer(mqtt_host_ip, Settings->mqtt_port);
|
||||
#endif // USE_MQTT_TLS
|
||||
|
||||
char stopic[TOPSZ];
|
||||
|
|
|
@ -105,8 +105,11 @@ String TelegramConnectToTelegram(const String &command) {
|
|||
|
||||
if (!TelegramInit()) { return ""; }
|
||||
|
||||
String host = F("api.telegram.org");
|
||||
String response = "";
|
||||
String host = F("api.telegram.org");
|
||||
if (!WifiDnsPresent(host.c_str())) {
|
||||
return response;
|
||||
}
|
||||
uint32_t tls_connect_time = millis();
|
||||
if (telegramClient->connect(host.c_str(), 443)) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue