apply astylerc

This commit is contained in:
technyon
2024-11-23 16:55:59 +01:00
parent a426d955a3
commit 27fa67f9b1
11 changed files with 288 additions and 171 deletions

View File

@@ -5,10 +5,10 @@
#include "MqttTopics.h"
HomeAssistantDiscovery::HomeAssistantDiscovery(NetworkDevice* device, Preferences *preferences, char* buffer, size_t bufferSize)
: _device(device),
_preferences(preferences),
_buffer(buffer),
_bufferSize(bufferSize)
: _device(device),
_preferences(preferences),
_buffer(buffer),
_bufferSize(bufferSize)
{
_discoveryTopic = _preferences->getString(preference_mqtt_hass_discovery, "");
_baseTopic = _preferences->getString(preference_mqtt_lock_path);
@@ -2905,20 +2905,20 @@ void HomeAssistantDiscovery::publishHASSConfigKeypad(char *deviceType, const cha
}
void HomeAssistantDiscovery::publishHassTopic(const String& mqttDeviceType,
const String& mqttDeviceName,
const String& uidString,
const String& uidStringPostfix,
const String& displayName,
const String& name,
const String& baseTopic,
const String& stateTopic,
const String& deviceType,
const String& deviceClass,
const String& stateClass,
const String& entityCat,
const String& commandTopic,
std::vector<std::pair<char*, char*>> additionalEntries
)
const String& mqttDeviceName,
const String& uidString,
const String& uidStringPostfix,
const String& displayName,
const String& name,
const String& baseTopic,
const String& stateTopic,
const String& deviceType,
const String& deviceClass,
const String& stateClass,
const String& entityCat,
const String& commandTopic,
std::vector<std::pair<char*, char*>> additionalEntries
)
{
if (_discoveryTopic != "")
{
@@ -3056,18 +3056,18 @@ void HomeAssistantDiscovery::removeHASSConfigTopic(char *deviceType, char *name,
}
JsonDocument HomeAssistantDiscovery::createHassJson(const String& uidString,
const String& uidStringPostfix,
const String& displayName,
const String& name,
const String& baseTopic,
const String& stateTopic,
const String& deviceType,
const String& deviceClass,
const String& stateClass,
const String& entityCat,
const String& commandTopic,
std::vector<std::pair<char*, char*>> additionalEntries
)
const String& uidStringPostfix,
const String& displayName,
const String& name,
const String& baseTopic,
const String& stateTopic,
const String& deviceType,
const String& deviceClass,
const String& stateClass,
const String& entityCat,
const String& commandTopic,
std::vector<std::pair<char*, char*>> additionalEntries
)
{
JsonDocument json;
json.clear();

View File

@@ -134,13 +134,13 @@ void NukiNetwork::setupDevice()
#ifndef NUKI_HUB_UPDATER
_device->mqttOnConnect([&](bool sessionPresent)
{
onMqttConnect(sessionPresent);
});
{
onMqttConnect(sessionPresent);
});
_device->mqttOnDisconnect([&](espMqttClientTypes::DisconnectReason reason)
{
onMqttDisconnect(reason);
});
{
onMqttDisconnect(reason);
});
_hadiscovery = new HomeAssistantDiscovery(_device, _preferences, _buffer, _bufferSize);
#endif
@@ -199,7 +199,10 @@ bool NukiNetwork::wifiConnected()
{
return true;
}
else return _device->isConnected();
else
{
return _device->isConnected();
}
}
#ifdef NUKI_HUB_UPDATER
@@ -309,29 +312,29 @@ void NukiNetwork::initialize()
{
switch (pinEntry.role)
{
case PinRole::GeneralInputPullDown:
case PinRole::GeneralInputPullUp:
if(rebGpio)
{
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_role});
publishString(_lockPath.c_str(), gpioPath, "input", false);
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_state});
publishString(_lockPath.c_str(), gpioPath, std::to_string(digitalRead(pinEntry.pin)).c_str(), false);
}
break;
case PinRole::GeneralOutput:
if(rebGpio)
{
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_role});
publishString(_lockPath.c_str(), gpioPath, "output", false);
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_state});
publishString(_lockPath.c_str(), gpioPath, "0", false);
}
case PinRole::GeneralInputPullDown:
case PinRole::GeneralInputPullUp:
if(rebGpio)
{
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_role});
publishString(_lockPath.c_str(), gpioPath, "input", false);
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_state});
subscribe(_lockPath.c_str(), gpioPath);
break;
default:
break;
publishString(_lockPath.c_str(), gpioPath, std::to_string(digitalRead(pinEntry.pin)).c_str(), false);
}
break;
case PinRole::GeneralOutput:
if(rebGpio)
{
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_role});
publishString(_lockPath.c_str(), gpioPath, "output", false);
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_state});
publishString(_lockPath.c_str(), gpioPath, "0", false);
}
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_state});
subscribe(_lockPath.c_str(), gpioPath);
break;
default:
break;
}
}
@@ -376,7 +379,8 @@ bool NukiNetwork::update()
{
_mqttConnectCounter = 0;
if(_firstDisconnected) {
if(_firstDisconnected)
{
_firstDisconnected = false;
_device->mqttDisconnect(true);
}
@@ -421,7 +425,10 @@ bool NukiNetwork::update()
delay(200);
restartEsp(RestartReason::ReconfigureWebServer);
}
else if(!_webEnabled) forceEnableWebServer = false;
else if(!_webEnabled)
{
forceEnableWebServer = false;
}
delay(2000);
}
@@ -429,7 +436,10 @@ bool NukiNetwork::update()
{
if(_networkTimeout > 0 && (ts - _lastConnectedTs > _networkTimeout * 1000) && ts > 60000)
{
if(!_webEnabled) forceEnableWebServer = true;
if(!_webEnabled)
{
forceEnableWebServer = true;
}
Log->println("Network timeout has been reached, restarting ...");
delay(200);
restartEsp(RestartReason::NetworkTimeoutWatchdog);
@@ -577,33 +587,33 @@ void NukiNetwork::onMqttDisconnect(const espMqttClientTypes::DisconnectReason &r
Log->print("MQTT disconnected. Reason: ");
switch(reason)
{
case espMqttClientTypes::DisconnectReason::USER_OK:
Log->println(F("USER_OK"));
break;
case espMqttClientTypes::DisconnectReason::MQTT_UNACCEPTABLE_PROTOCOL_VERSION:
Log->println(F("MQTT_UNACCEPTABLE_PROTOCOL_VERSION"));
break;
case espMqttClientTypes::DisconnectReason::MQTT_IDENTIFIER_REJECTED:
Log->println(F("MQTT_IDENTIFIER_REJECTED"));
break;
case espMqttClientTypes::DisconnectReason::MQTT_SERVER_UNAVAILABLE:
Log->println(F("MQTT_SERVER_UNAVAILABLE"));
break;
case espMqttClientTypes::DisconnectReason::MQTT_MALFORMED_CREDENTIALS:
Log->println(F("MQTT_MALFORMED_CREDENTIALS"));
break;
case espMqttClientTypes::DisconnectReason::MQTT_NOT_AUTHORIZED:
Log->println(F("MQTT_NOT_AUTHORIZED"));
break;
case espMqttClientTypes::DisconnectReason::TLS_BAD_FINGERPRINT:
Log->println(F("TLS_BAD_FINGERPRINT"));
break;
case espMqttClientTypes::DisconnectReason::TCP_DISCONNECTED:
Log->println(F("TCP_DISCONNECTED"));
break;
default:
Log->println(F("Unknown"));
break;
case espMqttClientTypes::DisconnectReason::USER_OK:
Log->println(F("USER_OK"));
break;
case espMqttClientTypes::DisconnectReason::MQTT_UNACCEPTABLE_PROTOCOL_VERSION:
Log->println(F("MQTT_UNACCEPTABLE_PROTOCOL_VERSION"));
break;
case espMqttClientTypes::DisconnectReason::MQTT_IDENTIFIER_REJECTED:
Log->println(F("MQTT_IDENTIFIER_REJECTED"));
break;
case espMqttClientTypes::DisconnectReason::MQTT_SERVER_UNAVAILABLE:
Log->println(F("MQTT_SERVER_UNAVAILABLE"));
break;
case espMqttClientTypes::DisconnectReason::MQTT_MALFORMED_CREDENTIALS:
Log->println(F("MQTT_MALFORMED_CREDENTIALS"));
break;
case espMqttClientTypes::DisconnectReason::MQTT_NOT_AUTHORIZED:
Log->println(F("MQTT_NOT_AUTHORIZED"));
break;
case espMqttClientTypes::DisconnectReason::TLS_BAD_FINGERPRINT:
Log->println(F("TLS_BAD_FINGERPRINT"));
break;
case espMqttClientTypes::DisconnectReason::TCP_DISCONNECTED:
Log->println(F("TCP_DISCONNECTED"));
break;
default:
Log->println(F("Unknown"));
break;
}
}
@@ -630,7 +640,8 @@ bool NukiNetwork::reconnect()
}
else
{
Log->print(F("MQTT: Connecting with user: ")); Log->println(_mqttUser);
Log->print(F("MQTT: Connecting with user: "));
Log->println(_mqttUser);
_device->mqttSetCredentials(_mqttUser, _mqttPass);
}
@@ -858,7 +869,10 @@ void NukiNetwork::onMqttDataReceivedCallback(const espMqttClientTypes::MessagePr
void NukiNetwork::onMqttDataReceived(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t& len, size_t& index, size_t& total)
{
if(_mqttConnectedTs == -1 || (millis() - _mqttConnectedTs < 2000)) return;
if(_mqttConnectedTs == -1 || (millis() - _mqttConnectedTs < 2000))
{
return;
}
parseGpioTopics(properties, topic, payload, len, index, total);

View File

@@ -142,7 +142,7 @@ void NukiNetworkLock::initialize()
{
_network->subscribe(_mqttPath, mqtt_topic_lock_log_rolling_last);
}
_network->addReconnectedCallback([&]()
{
_reconnected = true;
@@ -160,7 +160,7 @@ void NukiNetworkLock::update()
void NukiNetworkLock::onMqttDataReceived(const char* topic, byte* payload, const unsigned int length)
{
char* data = (char*)payload;
if(_network->mqttRecentlyConnected() && _network->pathEquals(_mqttPath, mqtt_topic_lock_action, topic))
{
Log->println("MQTT recently connected, ignoring lock action.");

View File

@@ -33,7 +33,7 @@ void NukiNetworkOpener::initialize()
_haEnabled = _preferences->getString(preference_mqtt_hass_discovery, "") != "";
_disableNonJSON = _preferences->getBool(preference_disable_non_json, false);
_network->initTopic(_mqttPath, mqtt_topic_lock_action, "--");
_network->subscribe(_mqttPath, mqtt_topic_lock_action);
_network->initTopic(_mqttPath, mqtt_topic_config_action, "--");
@@ -47,7 +47,7 @@ void NukiNetworkOpener::initialize()
_network->subscribe(_mqttPath, mqtt_topic_query_config);
_network->subscribe(_mqttPath, mqtt_topic_query_lockstate);
_network->subscribe(_mqttPath, mqtt_topic_query_battery);
if(_disableNonJSON)
{
_network->removeTopic(_mqttPath, mqtt_topic_keypad_command_action);
@@ -86,7 +86,7 @@ void NukiNetworkOpener::initialize()
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_id, "0");
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_name, "--");
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_code, "000000");
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_enabled, "1");
_network->initTopic(_mqttPath, mqtt_topic_keypad_command_enabled, "1");
_network->subscribe(_mqttPath, mqtt_topic_keypad_command_action);
_network->subscribe(_mqttPath, mqtt_topic_keypad_command_id);
_network->subscribe(_mqttPath, mqtt_topic_keypad_command_name);
@@ -118,9 +118,9 @@ void NukiNetworkOpener::initialize()
}
_network->addReconnectedCallback([&]()
{
_reconnected = true;
});
{
_reconnected = true;
});
}
void NukiNetworkOpener::update()
@@ -136,7 +136,7 @@ void NukiNetworkOpener::update()
void NukiNetworkOpener::onMqttDataReceived(const char* topic, byte* payload, const unsigned int length)
{
char* data = (char*)payload;
if(_network->mqttRecentlyConnected() && _network->pathEquals(_mqttPath, mqtt_topic_lock_action, topic))
{
Log->println("MQTT recently connected, ignoring opener action.");
@@ -652,7 +652,7 @@ void NukiNetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::Log
serializeJson(entry, _buffer, _bufferSize);
publishString(mqtt_topic_lock_log_rolling, _buffer, true);
publishInt(mqtt_topic_lock_log_rolling_last, log.index, true);
if(log.loggingType == NukiOpener::LoggingType::DoorbellRecognition && _lastRollingLog > 0)
{
if((log.data[0] & 3) == 0)
@@ -666,7 +666,7 @@ void NukiNetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::Log
publishRing(false);
}
}
_lastRollingLog = log.index;
}
}
@@ -675,7 +675,7 @@ void NukiNetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::Log
if(latest)
{
publishString(mqtt_topic_lock_log_latest, _buffer, true);
publishString(mqtt_topic_lock_log_latest, _buffer, true);
}
else
{

View File

@@ -2666,7 +2666,8 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
idExists = std::find(_keypadCodeIds.begin(), _keypadCodeIds.end(), codeId) != _keypadCodeIds.end();
}
if(strcmp(action, "check") == 0) {
if(strcmp(action, "check") == 0)
{
if(!_preferences->getBool(preference_keypad_check_code_enabled, false))
{
_network->publishKeypadJsonCommandResult("checkingKeypadCodesDisabled");
@@ -2720,7 +2721,8 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
while(retryCount < _nrOfRetries + 1)
{
if(strcmp(action, "delete") == 0) {
if(strcmp(action, "delete") == 0)
{
if(idExists)
{
result = _nukiOpener.deleteKeypadEntry(codeId);
@@ -2857,13 +2859,34 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
}
}
if(allowedWeekdays.indexOf("mon") >= 0) allowedWeekdaysInt += 64;
if(allowedWeekdays.indexOf("tue") >= 0) allowedWeekdaysInt += 32;
if(allowedWeekdays.indexOf("wed") >= 0) allowedWeekdaysInt += 16;
if(allowedWeekdays.indexOf("thu") >= 0) allowedWeekdaysInt += 8;
if(allowedWeekdays.indexOf("fri") >= 0) allowedWeekdaysInt += 4;
if(allowedWeekdays.indexOf("sat") >= 0) allowedWeekdaysInt += 2;
if(allowedWeekdays.indexOf("sun") >= 0) allowedWeekdaysInt += 1;
if(allowedWeekdays.indexOf("mon") >= 0)
{
allowedWeekdaysInt += 64;
}
if(allowedWeekdays.indexOf("tue") >= 0)
{
allowedWeekdaysInt += 32;
}
if(allowedWeekdays.indexOf("wed") >= 0)
{
allowedWeekdaysInt += 16;
}
if(allowedWeekdays.indexOf("thu") >= 0)
{
allowedWeekdaysInt += 8;
}
if(allowedWeekdays.indexOf("fri") >= 0)
{
allowedWeekdaysInt += 4;
}
if(allowedWeekdays.indexOf("sat") >= 0)
{
allowedWeekdaysInt += 2;
}
if(allowedWeekdays.indexOf("sun") >= 0)
{
allowedWeekdaysInt += 1;
}
}
if(strcmp(action, "add") == 0)
@@ -2938,17 +2961,32 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
for(const auto& entry : entries)
{
if (codeId != entry.codeId) continue;
else foundExisting = true;
if (codeId != entry.codeId)
{
continue;
}
else
{
foundExisting = true;
}
if(name.length() < 1)
{
memset(oldName, 0, sizeof(oldName));
memcpy(oldName, entry.name, sizeof(entry.name));
}
if(code == 12) code = entry.code;
if(enabled == 2) enabled = entry.enabled;
if(timeLimited == 2) timeLimited = entry.timeLimited;
if(code == 12)
{
code = entry.code;
}
if(enabled == 2)
{
enabled = entry.enabled;
}
if(timeLimited == 2)
{
timeLimited = entry.timeLimited;
}
if(allowedFrom.length() < 1)
{
allowedFrom = "old";
@@ -2969,7 +3007,10 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
allowedUntilAr[4] = entry.allowedUntilMin;
allowedUntilAr[5] = entry.allowedUntilSec;
}
if(allowedWeekdays.length() < 1) allowedWeekdaysInt = entry.allowedWeekdays;
if(allowedWeekdays.length() < 1)
{
allowedWeekdaysInt = entry.allowedWeekdays;
}
if(allowedFromTime.length() < 1)
{
allowedFromTime = "old";
@@ -3068,10 +3109,14 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
return;
}
if(result != Nuki::CmdResult::Success) {
if(result != Nuki::CmdResult::Success)
{
++retryCount;
}
else break;
else
{
break;
}
}
updateKeypad(false);

View File

@@ -2710,7 +2710,8 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
idExists = std::find(_keypadCodeIds.begin(), _keypadCodeIds.end(), codeId) != _keypadCodeIds.end();
}
if(strcmp(action, "check") == 0) {
if(strcmp(action, "check") == 0)
{
if(!_preferences->getBool(preference_keypad_check_code_enabled, false))
{
_network->publishKeypadJsonCommandResult("checkingKeypadCodesDisabled");
@@ -2765,7 +2766,8 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
while(retryCount < _nrOfRetries + 1)
{
if(strcmp(action, "delete") == 0) {
if(strcmp(action, "delete") == 0)
{
if(idExists)
{
result = _nukiLock.deleteKeypadEntry(codeId);
@@ -2902,13 +2904,34 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
}
}
if(allowedWeekdays.indexOf("mon") >= 0) allowedWeekdaysInt += 64;
if(allowedWeekdays.indexOf("tue") >= 0) allowedWeekdaysInt += 32;
if(allowedWeekdays.indexOf("wed") >= 0) allowedWeekdaysInt += 16;
if(allowedWeekdays.indexOf("thu") >= 0) allowedWeekdaysInt += 8;
if(allowedWeekdays.indexOf("fri") >= 0) allowedWeekdaysInt += 4;
if(allowedWeekdays.indexOf("sat") >= 0) allowedWeekdaysInt += 2;
if(allowedWeekdays.indexOf("sun") >= 0) allowedWeekdaysInt += 1;
if(allowedWeekdays.indexOf("mon") >= 0)
{
allowedWeekdaysInt += 64;
}
if(allowedWeekdays.indexOf("tue") >= 0)
{
allowedWeekdaysInt += 32;
}
if(allowedWeekdays.indexOf("wed") >= 0)
{
allowedWeekdaysInt += 16;
}
if(allowedWeekdays.indexOf("thu") >= 0)
{
allowedWeekdaysInt += 8;
}
if(allowedWeekdays.indexOf("fri") >= 0)
{
allowedWeekdaysInt += 4;
}
if(allowedWeekdays.indexOf("sat") >= 0)
{
allowedWeekdaysInt += 2;
}
if(allowedWeekdays.indexOf("sun") >= 0)
{
allowedWeekdaysInt += 1;
}
}
if(strcmp(action, "add") == 0)
@@ -2983,17 +3006,32 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
for(const auto& entry : entries)
{
if (codeId != entry.codeId) continue;
else foundExisting = true;
if (codeId != entry.codeId)
{
continue;
}
else
{
foundExisting = true;
}
if(name.length() < 1)
{
memset(oldName, 0, sizeof(oldName));
memcpy(oldName, entry.name, sizeof(entry.name));
}
if(code == 12) code = entry.code;
if(enabled == 2) enabled = entry.enabled;
if(timeLimited == 2) timeLimited = entry.timeLimited;
if(code == 12)
{
code = entry.code;
}
if(enabled == 2)
{
enabled = entry.enabled;
}
if(timeLimited == 2)
{
timeLimited = entry.timeLimited;
}
if(allowedFrom.length() < 1)
{
allowedFrom = "old";
@@ -3014,7 +3052,10 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
allowedUntilAr[4] = entry.allowedUntilMin;
allowedUntilAr[5] = entry.allowedUntilSec;
}
if(allowedWeekdays.length() < 1) allowedWeekdaysInt = entry.allowedWeekdays;
if(allowedWeekdays.length() < 1)
{
allowedWeekdaysInt = entry.allowedWeekdays;
}
if(allowedFromTime.length() < 1)
{
allowedFromTime = "old";
@@ -3113,10 +3154,14 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
return;
}
if(result != Nuki::CmdResult::Success) {
if(result != Nuki::CmdResult::Success)
{
++retryCount;
}
else break;
else
{
break;
}
}
updateKeypad(false);

View File

@@ -159,9 +159,9 @@ void WebCfgServer::initialize()
_psychicServer->on("/savewifi", HTTP_POST, [&](PsychicRequest *request)
{
if(strlen(_credUser) > 0 && strlen(_credPassword) > 0 && !request->authenticate(_credUser, _credPassword))
{
return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
}
{
return request->requestAuthentication(BASIC_AUTH, "Nuki Hub", "You must log in.");
}
String message = "";
bool connected = processWiFi(request, message);
esp_err_t res = buildConfirmHtml(request, message, 10, true);
@@ -3534,7 +3534,7 @@ esp_err_t WebCfgServer::buildNetworkConfigHtml(PsychicRequest *request)
#endif
printCheckBox(&response, "RSTDISC", "Restart on disconnect", _preferences->getBool(preference_restart_on_disconnect), "");
printCheckBox(&response, "CHECKUPDATE", "Check for Firmware Updates every 24h", _preferences->getBool(preference_check_updates), "");
printCheckBox(&response, "FINDBESTRSSI", "Find WiFi AP with strongest signal", _preferences->getBool(preference_find_best_rssi, false), "");
printCheckBox(&response, "FINDBESTRSSI", "Find WiFi AP with strongest signal", _preferences->getBool(preference_find_best_rssi, false), "");
response.print("</table>");
response.print("<h3>IP Address assignment</h3>");
response.print("<table>");

View File

@@ -355,13 +355,13 @@ void otaTask(void *pvParameter)
updateUrl = preferences->getString(preference_ota_main_url);
preferences->putString(preference_ota_main_url, "");
}
while(!network->isConnected())
{
Log->println("OTA waiting for network");
vTaskDelay(5000 / portTICK_PERIOD_MS);
}
Log->println("Starting OTA task");
esp_http_client_config_t config =
{

View File

@@ -126,7 +126,7 @@ void EthernetDevice::initialize()
void EthernetDevice::update()
{
NetworkDevice::update();
if(_checkIpTs != -1 && _checkIpTs < espMillis())
{
if(_ipConfiguration->ipAddress() != ETH.localIP())
@@ -136,7 +136,7 @@ void EthernetDevice::update()
_checkIpTs = espMillis() + 5000;
return;
}
_checkIpTs = -1;
}
}

View File

@@ -25,7 +25,8 @@ void NetworkDevice::init()
_mqttClientSecure->setCertificate(_cert);
_mqttClientSecure->setPrivateKey(_key);
}
} else
}
else
{
Log->println(F("MQTT without TLS."));
_mqttClient = new espMqttClient(espMqttClientTypes::UseInternalTask::NO);
@@ -35,9 +36,18 @@ void NetworkDevice::init()
{
MqttLoggerMode mode;
if(_preferences->getBool(preference_mqtt_log_enabled, false) && _preferences->getBool(preference_webserial_enabled, false)) mode = MqttLoggerMode::MqttAndSerialAndWeb;
else if (_preferences->getBool(preference_webserial_enabled, false)) mode = MqttLoggerMode::SerialAndWeb;
else mode = MqttLoggerMode::MqttAndSerial;
if(_preferences->getBool(preference_mqtt_log_enabled, false) && _preferences->getBool(preference_webserial_enabled, false))
{
mode = MqttLoggerMode::MqttAndSerialAndWeb;
}
else if (_preferences->getBool(preference_webserial_enabled, false))
{
mode = MqttLoggerMode::SerialAndWeb;
}
else
{
mode = MqttLoggerMode::MqttAndSerial;
}
_path = new char[200];
memset(_path, 0, sizeof(_path));

View File

@@ -95,7 +95,7 @@ void WifiDevice::openAP()
WiFi.softAPsetHostname(_hostname.c_str());
delay(500);
WiFi.softAP("NukiHub", "NukiHubESP32");
//if(MDNS.begin(_hostname.c_str())){
// MDNS.addService("http", "tcp", 80);
//}
@@ -112,7 +112,7 @@ bool WifiDevice::connect()
delay(500);
int bestConnection = -1;
if(_preferences->getBool(preference_find_best_rssi, false))
{
for (int i = 0; i < _foundNetworks; i++)
@@ -137,7 +137,7 @@ bool WifiDevice::connect()
}
}
}
if (bestConnection == -1)
{
Log->print("No network found with SSID: ");
@@ -166,24 +166,24 @@ bool WifiDevice::connect()
switch (status)
{
case WL_CONNECTED:
Log->println("WiFi connected");
break;
case WL_NO_SSID_AVAIL:
Log->println("WiFi SSID not available");
break;
case WL_CONNECT_FAILED:
Log->println("WiFi connection failed");
break;
case WL_IDLE_STATUS:
Log->println("WiFi changing status");
break;
case WL_DISCONNECTED:
Log->println("WiFi disconnected");
break;
default:
Log->println("WiFi timeout");
break;
case WL_CONNECTED:
Log->println("WiFi connected");
break;
case WL_NO_SSID_AVAIL:
Log->println("WiFi SSID not available");
break;
case WL_CONNECT_FAILED:
Log->println("WiFi connection failed");
break;
case WL_IDLE_STATUS:
Log->println("WiFi changing status");
break;
case WL_DISCONNECTED:
Log->println("WiFi disconnected");
break;
default:
Log->println("WiFi timeout");
break;
}
if (status != WL_CONNECTED)
@@ -250,7 +250,10 @@ void WifiDevice::onConnected()
void WifiDevice::onDisconnected()
{
if (!_connected) return;
if (!_connected)
{
return;
}
_connected = false;
Log->println("Wi-Fi disconnected");