add astylerc and apply code formatting
This commit is contained in:
25
src/Gpio.cpp
25
src/Gpio.cpp
@@ -12,7 +12,7 @@
|
|||||||
Gpio* Gpio::_inst = nullptr;
|
Gpio* Gpio::_inst = nullptr;
|
||||||
|
|
||||||
Gpio::Gpio(Preferences* preferences)
|
Gpio::Gpio(Preferences* preferences)
|
||||||
: _preferences(preferences)
|
: _preferences(preferences)
|
||||||
{
|
{
|
||||||
_inst = this;
|
_inst = this;
|
||||||
loadPinConfiguration();
|
loadPinConfiguration();
|
||||||
@@ -221,7 +221,10 @@ void Gpio::loadPinConfiguration()
|
|||||||
|
|
||||||
if(std::find(disabledPins.begin(), disabledPins.end(), entry.pin) == disabledPins.end())
|
if(std::find(disabledPins.begin(), disabledPins.end(), entry.pin) == disabledPins.end())
|
||||||
{
|
{
|
||||||
if(entry.role == PinRole::Ethernet) entry.role = PinRole::Disabled;
|
if(entry.role == PinRole::Ethernet)
|
||||||
|
{
|
||||||
|
entry.role = PinRole::Disabled;
|
||||||
|
}
|
||||||
entry.role = (PinRole) serialized[(i * 2 + 1)];
|
entry.role = (PinRole) serialized[(i * 2 + 1)];
|
||||||
Log->println("Not found in Ethernet disabled pins");
|
Log->println("Not found in Ethernet disabled pins");
|
||||||
Log->print(F("Role: "));
|
Log->print(F("Role: "));
|
||||||
@@ -234,7 +237,10 @@ void Gpio::loadPinConfiguration()
|
|||||||
Log->print(F("Role: "));
|
Log->print(F("Role: "));
|
||||||
Log->println(getRoleDescription(entry.role));
|
Log->println(getRoleDescription(entry.role));
|
||||||
}
|
}
|
||||||
if(entry.role != PinRole::Disabled) _pinConfiguration.push_back(entry);
|
if(entry.role != PinRole::Disabled)
|
||||||
|
{
|
||||||
|
_pinConfiguration.push_back(entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,7 +301,7 @@ const std::vector<int> Gpio::getDisabledPins() const
|
|||||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_mdc, -1));
|
disabledPins.push_back(_preferences->getInt(preference_network_custom_mdc, -1));
|
||||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_mdio, -1));
|
disabledPins.push_back(_preferences->getInt(preference_network_custom_mdio, -1));
|
||||||
break;
|
break;
|
||||||
#if defined(CONFIG_IDF_TARGET_ESP32)
|
#if defined(CONFIG_IDF_TARGET_ESP32)
|
||||||
case 4:
|
case 4:
|
||||||
disabledPins.push_back(12);
|
disabledPins.push_back(12);
|
||||||
disabledPins.push_back(ETH_RESET_PIN_LAN8720);
|
disabledPins.push_back(ETH_RESET_PIN_LAN8720);
|
||||||
@@ -320,14 +326,18 @@ const std::vector<int> Gpio::getDisabledPins() const
|
|||||||
disabledPins.push_back(ETH_PHY_MDC_LAN8720);
|
disabledPins.push_back(ETH_PHY_MDC_LAN8720);
|
||||||
disabledPins.push_back(ETH_PHY_MDIO_LAN8720);
|
disabledPins.push_back(ETH_PHY_MDIO_LAN8720);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log->print(F("GPIO Ethernet disabled pins:"));
|
Log->print(F("GPIO Ethernet disabled pins:"));
|
||||||
for_each_n(disabledPins.begin(), disabledPins.size(),
|
for_each_n(disabledPins.begin(), disabledPins.size(),
|
||||||
[](int x) { Log->print(" "); Log->print(x); });
|
[](int x)
|
||||||
|
{
|
||||||
|
Log->print(" ");
|
||||||
|
Log->print(x);
|
||||||
|
});
|
||||||
Log->println();
|
Log->println();
|
||||||
return disabledPins;
|
return disabledPins;
|
||||||
}
|
}
|
||||||
@@ -486,7 +496,8 @@ GpioAction Gpio::getGpioAction(const PinRole &role) const
|
|||||||
case PinRole::OutputHighRtoOrCmActive:
|
case PinRole::OutputHighRtoOrCmActive:
|
||||||
default:
|
default:
|
||||||
return GpioAction::None;
|
return GpioAction::None;
|
||||||
}}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Gpio::getConfigurationText(String& text, const std::vector<PinEntry>& pinConfiguration, const String& linebreak) const
|
void Gpio::getConfigurationText(String& text, const std::vector<PinEntry>& pinConfiguration, const String& linebreak) const
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include "PreferencesKeys.h"
|
#include "PreferencesKeys.h"
|
||||||
|
|
||||||
NukiDeviceId::NukiDeviceId(Preferences* preferences, const std::string& preferencesId)
|
NukiDeviceId::NukiDeviceId(Preferences* preferences, const std::string& preferencesId)
|
||||||
: _preferences(preferences),
|
: _preferences(preferences),
|
||||||
_preferencesId(preferencesId)
|
_preferencesId(preferencesId)
|
||||||
{
|
{
|
||||||
_deviceId = _preferences->getUInt(_preferencesId.c_str(), 0);
|
_deviceId = _preferences->getUInt(_preferencesId.c_str(), 0);
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -15,7 +15,7 @@ extern const uint8_t x509_crt_imported_bundle_bin_start[] asm("_binary_x509_crt_
|
|||||||
extern const uint8_t x509_crt_imported_bundle_bin_end[] asm("_binary_x509_crt_bundle_end");
|
extern const uint8_t x509_crt_imported_bundle_bin_end[] asm("_binary_x509_crt_bundle_end");
|
||||||
|
|
||||||
NukiNetworkLock::NukiNetworkLock(NukiNetwork* network, NukiOfficial* nukiOfficial, Preferences* preferences, char* buffer, size_t bufferSize)
|
NukiNetworkLock::NukiNetworkLock(NukiNetwork* network, NukiOfficial* nukiOfficial, Preferences* preferences, char* buffer, size_t bufferSize)
|
||||||
: _network(network),
|
: _network(network),
|
||||||
_nukiOfficial(nukiOfficial),
|
_nukiOfficial(nukiOfficial),
|
||||||
_preferences(preferences),
|
_preferences(preferences),
|
||||||
_buffer(buffer),
|
_buffer(buffer),
|
||||||
@@ -201,21 +201,26 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
|||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
|
|
||||||
NetworkClientSecure *client = new NetworkClientSecure;
|
NetworkClientSecure *client = new NetworkClientSecure;
|
||||||
if (client) {
|
if (client)
|
||||||
|
{
|
||||||
client->setCACertBundle(x509_crt_imported_bundle_bin_start, x509_crt_imported_bundle_bin_end - x509_crt_imported_bundle_bin_start);
|
client->setCACertBundle(x509_crt_imported_bundle_bin_start, x509_crt_imported_bundle_bin_end - x509_crt_imported_bundle_bin_start);
|
||||||
{
|
{
|
||||||
HTTPClient https;
|
HTTPClient https;
|
||||||
https.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
|
https.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
|
||||||
https.useHTTP10(true);
|
https.useHTTP10(true);
|
||||||
|
|
||||||
if (https.begin(*client, GITHUB_OTA_MANIFEST_URL)) {
|
if (https.begin(*client, GITHUB_OTA_MANIFEST_URL))
|
||||||
|
{
|
||||||
int httpResponseCode = https.GET();
|
int httpResponseCode = https.GET();
|
||||||
|
|
||||||
if (httpResponseCode == HTTP_CODE_OK || httpResponseCode == HTTP_CODE_MOVED_PERMANENTLY)
|
if (httpResponseCode == HTTP_CODE_OK || httpResponseCode == HTTP_CODE_MOVED_PERMANENTLY)
|
||||||
{
|
{
|
||||||
DeserializationError jsonError = deserializeJson(doc, https.getStream());
|
DeserializationError jsonError = deserializeJson(doc, https.getStream());
|
||||||
|
|
||||||
if (!jsonError) { otaManifestSuccess = true; }
|
if (!jsonError)
|
||||||
|
{
|
||||||
|
otaManifestSuccess = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
https.end();
|
https.end();
|
||||||
@@ -296,18 +301,27 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
|||||||
else if(comparePrefixedPath(topic, mqtt_topic_webserver_action))
|
else if(comparePrefixedPath(topic, mqtt_topic_webserver_action))
|
||||||
{
|
{
|
||||||
if(strcmp(data, "") == 0 ||
|
if(strcmp(data, "") == 0 ||
|
||||||
strcmp(data, "--") == 0) return;
|
strcmp(data, "--") == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(strcmp(data, "1") == 0)
|
if(strcmp(data, "1") == 0)
|
||||||
{
|
{
|
||||||
if(_preferences->getBool(preference_webserver_enabled, true) || forceEnableWebServer) return;
|
if(_preferences->getBool(preference_webserver_enabled, true) || forceEnableWebServer)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
Log->println(F("Webserver enabled, restarting."));
|
Log->println(F("Webserver enabled, restarting."));
|
||||||
_preferences->putBool(preference_webserver_enabled, true);
|
_preferences->putBool(preference_webserver_enabled, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (strcmp(data, "0") == 0)
|
else if (strcmp(data, "0") == 0)
|
||||||
{
|
{
|
||||||
if(!_preferences->getBool(preference_webserver_enabled, true) && !forceEnableWebServer) return;
|
if(!_preferences->getBool(preference_webserver_enabled, true) && !forceEnableWebServer)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
Log->println(F("Webserver disabled, restarting."));
|
Log->println(F("Webserver disabled, restarting."));
|
||||||
_preferences->putBool(preference_webserver_enabled, false);
|
_preferences->putBool(preference_webserver_enabled, false);
|
||||||
}
|
}
|
||||||
@@ -320,9 +334,15 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
|||||||
else if(comparePrefixedPath(topic, mqtt_topic_lock_log_rolling_last))
|
else if(comparePrefixedPath(topic, mqtt_topic_lock_log_rolling_last))
|
||||||
{
|
{
|
||||||
if(strcmp(data, "") == 0 ||
|
if(strcmp(data, "") == 0 ||
|
||||||
strcmp(data, "--") == 0) return;
|
strcmp(data, "--") == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(atoi(data) > 0 && atoi(data) > _lastRollingLog) _lastRollingLog = atoi(data);
|
if(atoi(data) > 0 && atoi(data) > _lastRollingLog)
|
||||||
|
{
|
||||||
|
_lastRollingLog = atoi(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_nukiOfficial->getOffEnabled())
|
if(_nukiOfficial->getOffEnabled())
|
||||||
@@ -346,7 +366,10 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
|||||||
strcmp(data, "ack") == 0 ||
|
strcmp(data, "ack") == 0 ||
|
||||||
strcmp(data, "unknown_action") == 0 ||
|
strcmp(data, "unknown_action") == 0 ||
|
||||||
strcmp(data, "denied") == 0 ||
|
strcmp(data, "denied") == 0 ||
|
||||||
strcmp(data, "error") == 0) return;
|
strcmp(data, "error") == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Log->print(F("Lock action received: "));
|
Log->print(F("Lock action received: "));
|
||||||
Log->println(data);
|
Log->println(data);
|
||||||
@@ -379,7 +402,10 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
|||||||
{
|
{
|
||||||
if(_keypadCommandReceivedReceivedCallback != nullptr)
|
if(_keypadCommandReceivedReceivedCallback != nullptr)
|
||||||
{
|
{
|
||||||
if(strcmp(data, "--") == 0) return;
|
if(strcmp(data, "--") == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_keypadCommandReceivedReceivedCallback(data, _keypadCommandId, _keypadCommandName, _keypadCommandCode, _keypadCommandEnabled);
|
_keypadCommandReceivedReceivedCallback(data, _keypadCommandId, _keypadCommandName, _keypadCommandCode, _keypadCommandEnabled);
|
||||||
|
|
||||||
@@ -439,7 +465,10 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
|||||||
|
|
||||||
if(comparePrefixedPath(topic, mqtt_topic_config_action))
|
if(comparePrefixedPath(topic, mqtt_topic_config_action))
|
||||||
{
|
{
|
||||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(_configUpdateReceivedCallback != NULL)
|
if(_configUpdateReceivedCallback != NULL)
|
||||||
{
|
{
|
||||||
@@ -451,7 +480,10 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
|||||||
|
|
||||||
if(comparePrefixedPath(topic, mqtt_topic_keypad_json_action))
|
if(comparePrefixedPath(topic, mqtt_topic_keypad_json_action))
|
||||||
{
|
{
|
||||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(_keypadJsonCommandReceivedReceivedCallback != NULL)
|
if(_keypadJsonCommandReceivedReceivedCallback != NULL)
|
||||||
{
|
{
|
||||||
@@ -463,7 +495,10 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
|||||||
|
|
||||||
if(comparePrefixedPath(topic, mqtt_topic_timecontrol_action))
|
if(comparePrefixedPath(topic, mqtt_topic_timecontrol_action))
|
||||||
{
|
{
|
||||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(_timeControlCommandReceivedReceivedCallback != NULL)
|
if(_timeControlCommandReceivedReceivedCallback != NULL)
|
||||||
{
|
{
|
||||||
@@ -475,7 +510,10 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
|||||||
|
|
||||||
if(comparePrefixedPath(topic, mqtt_topic_auth_action))
|
if(comparePrefixedPath(topic, mqtt_topic_auth_action))
|
||||||
{
|
{
|
||||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(_authCommandReceivedReceivedCallback != NULL)
|
if(_authCommandReceivedReceivedCallback != NULL)
|
||||||
{
|
{
|
||||||
@@ -686,7 +724,10 @@ void NukiNetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntr
|
|||||||
{
|
{
|
||||||
int sizeName = sizeof(log.name);
|
int sizeName = sizeof(log.name);
|
||||||
memcpy(authName, log.name, sizeName);
|
memcpy(authName, log.name, sizeName);
|
||||||
if(authName[sizeName - 1] != '\0') authName[sizeName] = '\0';
|
if(authName[sizeName - 1] != '\0')
|
||||||
|
{
|
||||||
|
authName[sizeName] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
if(log.index > authIndex)
|
if(log.index > authIndex)
|
||||||
{
|
{
|
||||||
@@ -764,8 +805,14 @@ void NukiNetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntr
|
|||||||
|
|
||||||
memset(str, 0, sizeof(str));
|
memset(str, 0, sizeof(str));
|
||||||
|
|
||||||
if(log.data[2] == 9) entry["completionStatus"] = "notAuthorized";
|
if(log.data[2] == 9)
|
||||||
else if (log.data[2] == 224) entry["completionStatus"] = "invalidCode";
|
{
|
||||||
|
entry["completionStatus"] = "notAuthorized";
|
||||||
|
}
|
||||||
|
else if (log.data[2] == 224)
|
||||||
|
{
|
||||||
|
entry["completionStatus"] = "invalidCode";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[2], str);
|
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[2], str);
|
||||||
@@ -804,8 +851,14 @@ void NukiNetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntr
|
|||||||
|
|
||||||
serializeJson(json, _buffer, _bufferSize);
|
serializeJson(json, _buffer, _bufferSize);
|
||||||
|
|
||||||
if(latest) publishString(mqtt_topic_lock_log_latest, _buffer, true);
|
if(latest)
|
||||||
else publishString(mqtt_topic_lock_log, _buffer, true);
|
{
|
||||||
|
publishString(mqtt_topic_lock_log_latest, _buffer, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
publishString(mqtt_topic_lock_log, _buffer, true);
|
||||||
|
}
|
||||||
|
|
||||||
if(authIndex > 0)
|
if(authIndex > 0)
|
||||||
{
|
{
|
||||||
@@ -1013,7 +1066,10 @@ void NukiNetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entr
|
|||||||
|
|
||||||
jsonEntry["codeId"] = entry.codeId;
|
jsonEntry["codeId"] = entry.codeId;
|
||||||
|
|
||||||
if(publishCode) jsonEntry["code"] = entry.code;
|
if(publishCode)
|
||||||
|
{
|
||||||
|
jsonEntry["code"] = entry.code;
|
||||||
|
}
|
||||||
jsonEntry["enabled"] = entry.enabled;
|
jsonEntry["enabled"] = entry.enabled;
|
||||||
jsonEntry["name"] = entry.name;
|
jsonEntry["name"] = entry.name;
|
||||||
char createdDT[20];
|
char createdDT[20];
|
||||||
@@ -1034,7 +1090,8 @@ void NukiNetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entr
|
|||||||
uint8_t allowedWeekdaysInt = entry.allowedWeekdays;
|
uint8_t allowedWeekdaysInt = entry.allowedWeekdays;
|
||||||
JsonArray weekdays = jsonEntry["allowedWeekdays"].to<JsonArray>();
|
JsonArray weekdays = jsonEntry["allowedWeekdays"].to<JsonArray>();
|
||||||
|
|
||||||
while(allowedWeekdaysInt > 0) {
|
while(allowedWeekdaysInt > 0)
|
||||||
|
{
|
||||||
if(allowedWeekdaysInt >= 64)
|
if(allowedWeekdaysInt >= 64)
|
||||||
{
|
{
|
||||||
weekdays.add("mon");
|
weekdays.add("mon");
|
||||||
@@ -1123,12 +1180,14 @@ void NukiNetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entr
|
|||||||
"",
|
"",
|
||||||
"diagnostic",
|
"diagnostic",
|
||||||
String("~") + mqtt_topic_keypad_json_action,
|
String("~") + mqtt_topic_keypad_json_action,
|
||||||
{ { (char*)"json_attr_t", (char*)basePathPrefixChr },
|
{
|
||||||
|
{ (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||||
{ (char*)"stat_on", (char*)"1" },
|
{ (char*)"stat_on", (char*)"1" },
|
||||||
{ (char*)"stat_off", (char*)"0" }});
|
{ (char*)"stat_off", (char*)"0" }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
++index;
|
++index;
|
||||||
@@ -1202,7 +1261,10 @@ void NukiNetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entr
|
|||||||
|
|
||||||
void NukiNetworkLock::publishKeypadEntry(const String topic, NukiLock::KeypadEntry entry)
|
void NukiNetworkLock::publishKeypadEntry(const String topic, NukiLock::KeypadEntry entry)
|
||||||
{
|
{
|
||||||
if(_disableNonJSON) return;
|
if(_disableNonJSON)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
char codeName[sizeof(entry.name) + 1];
|
char codeName[sizeof(entry.name) + 1];
|
||||||
memset(codeName, 0, sizeof(codeName));
|
memset(codeName, 0, sizeof(codeName));
|
||||||
@@ -1245,7 +1307,8 @@ void NukiNetworkLock::publishTimeControl(const std::list<NukiLock::TimeControlEn
|
|||||||
uint8_t weekdaysInt = entry.weekdays;
|
uint8_t weekdaysInt = entry.weekdays;
|
||||||
JsonArray weekdays = jsonEntry["weekdays"].to<JsonArray>();
|
JsonArray weekdays = jsonEntry["weekdays"].to<JsonArray>();
|
||||||
|
|
||||||
while(weekdaysInt > 0) {
|
while(weekdaysInt > 0)
|
||||||
|
{
|
||||||
if(weekdaysInt >= 64)
|
if(weekdaysInt >= 64)
|
||||||
{
|
{
|
||||||
weekdays.add("mon");
|
weekdays.add("mon");
|
||||||
@@ -1331,12 +1394,14 @@ void NukiNetworkLock::publishTimeControl(const std::list<NukiLock::TimeControlEn
|
|||||||
"",
|
"",
|
||||||
"diagnostic",
|
"diagnostic",
|
||||||
String("~") + mqtt_topic_timecontrol_action,
|
String("~") + mqtt_topic_timecontrol_action,
|
||||||
{ { (char*)"json_attr_t", (char*)basePathPrefixChr },
|
{
|
||||||
|
{ (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||||
{ (char*)"stat_on", (char*)"1" },
|
{ (char*)"stat_on", (char*)"1" },
|
||||||
{ (char*)"stat_off", (char*)"0" }});
|
{ (char*)"stat_off", (char*)"0" }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
++index;
|
++index;
|
||||||
@@ -1393,7 +1458,8 @@ void NukiNetworkLock::publishAuth(const std::list<NukiLock::AuthorizationEntry>&
|
|||||||
uint8_t allowedWeekdaysInt = entry.allowedWeekdays;
|
uint8_t allowedWeekdaysInt = entry.allowedWeekdays;
|
||||||
JsonArray weekdays = jsonEntry["allowedWeekdays"].to<JsonArray>();
|
JsonArray weekdays = jsonEntry["allowedWeekdays"].to<JsonArray>();
|
||||||
|
|
||||||
while(allowedWeekdaysInt > 0) {
|
while(allowedWeekdaysInt > 0)
|
||||||
|
{
|
||||||
if(allowedWeekdaysInt >= 64)
|
if(allowedWeekdaysInt >= 64)
|
||||||
{
|
{
|
||||||
weekdays.add("mon");
|
weekdays.add("mon");
|
||||||
@@ -1478,12 +1544,14 @@ void NukiNetworkLock::publishAuth(const std::list<NukiLock::AuthorizationEntry>&
|
|||||||
"",
|
"",
|
||||||
"diagnostic",
|
"diagnostic",
|
||||||
String("~") + mqtt_topic_auth_action,
|
String("~") + mqtt_topic_auth_action,
|
||||||
{ { (char*)"json_attr_t", (char*)basePathPrefixChr },
|
{
|
||||||
|
{ (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||||
{ (char*)"stat_on", (char*)"1" },
|
{ (char*)"stat_on", (char*)"1" },
|
||||||
{ (char*)"stat_off", (char*)"0" }});
|
{ (char*)"stat_off", (char*)"0" }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
++index;
|
++index;
|
||||||
@@ -1510,7 +1578,10 @@ void NukiNetworkLock::publishConfigCommandResult(const char* result)
|
|||||||
|
|
||||||
void NukiNetworkLock::publishKeypadCommandResult(const char* result)
|
void NukiNetworkLock::publishKeypadCommandResult(const char* result)
|
||||||
{
|
{
|
||||||
if(_disableNonJSON) return;
|
if(_disableNonJSON)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
publishString(mqtt_topic_keypad_command_result, result, true);
|
publishString(mqtt_topic_keypad_command_result, result, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1551,7 +1622,10 @@ void NukiNetworkLock::setConfigUpdateReceivedCallback(void (*configUpdateReceive
|
|||||||
|
|
||||||
void NukiNetworkLock::setKeypadCommandReceivedCallback(void (*keypadCommandReceivedReceivedCallback)(const char* command, const uint& id, const String& name, const String& code, const int& enabled))
|
void NukiNetworkLock::setKeypadCommandReceivedCallback(void (*keypadCommandReceivedReceivedCallback)(const char* command, const uint& id, const String& name, const String& code, const int& enabled))
|
||||||
{
|
{
|
||||||
if(_disableNonJSON) return;
|
if(_disableNonJSON)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
_keypadCommandReceivedReceivedCallback = keypadCommandReceivedReceivedCallback;
|
_keypadCommandReceivedReceivedCallback = keypadCommandReceivedReceivedCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1618,9 +1692,9 @@ void NukiNetworkLock::publishHASSConfig(char *deviceType, const char *baseTopic,
|
|||||||
_network->removeHASSConfigTopic((char*)"binary_sensor", (char*)"door_sensor", uidString);
|
_network->removeHASSConfigTopic((char*)"binary_sensor", (char*)"door_sensor", uidString);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
||||||
_network->publishHASSWifiRssiConfig(deviceType, baseTopic, name, uidString);
|
_network->publishHASSWifiRssiConfig(deviceType, baseTopic, name, uidString);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(publishAuthData)
|
if(publishAuthData)
|
||||||
{
|
{
|
||||||
@@ -1719,8 +1793,10 @@ uint8_t NukiNetworkLock::queryCommands()
|
|||||||
return qc;
|
return qc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NukiNetworkLock::buttonPressActionToString(const NukiLock::ButtonPressAction btnPressAction, char* str) {
|
void NukiNetworkLock::buttonPressActionToString(const NukiLock::ButtonPressAction btnPressAction, char* str)
|
||||||
switch (btnPressAction) {
|
{
|
||||||
|
switch (btnPressAction)
|
||||||
|
{
|
||||||
case NukiLock::ButtonPressAction::NoAction:
|
case NukiLock::ButtonPressAction::NoAction:
|
||||||
strcpy(str, "No Action");
|
strcpy(str, "No Action");
|
||||||
break;
|
break;
|
||||||
@@ -1748,8 +1824,10 @@ void NukiNetworkLock::buttonPressActionToString(const NukiLock::ButtonPressActio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NukiNetworkLock::homeKitStatusToString(const int hkstatus, char* str) {
|
void NukiNetworkLock::homeKitStatusToString(const int hkstatus, char* str)
|
||||||
switch (hkstatus) {
|
{
|
||||||
|
switch (hkstatus)
|
||||||
|
{
|
||||||
case 0:
|
case 0:
|
||||||
strcpy(str, "Not Available");
|
strcpy(str, "Not Available");
|
||||||
break;
|
break;
|
||||||
@@ -1768,8 +1846,10 @@ void NukiNetworkLock::homeKitStatusToString(const int hkstatus, char* str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NukiNetworkLock::fobActionToString(const int fobact, char* str) {
|
void NukiNetworkLock::fobActionToString(const int fobact, char* str)
|
||||||
switch (fobact) {
|
{
|
||||||
|
switch (fobact)
|
||||||
|
{
|
||||||
case 0:
|
case 0:
|
||||||
strcpy(str, "No Action");
|
strcpy(str, "No Action");
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -149,9 +149,15 @@ void NukiNetworkOpener::onMqttDataReceived(char* topic, int topic_len, char* dat
|
|||||||
if(comparePrefixedPath(topic, mqtt_topic_lock_log_rolling_last))
|
if(comparePrefixedPath(topic, mqtt_topic_lock_log_rolling_last))
|
||||||
{
|
{
|
||||||
if(strcmp(data, "") == 0 ||
|
if(strcmp(data, "") == 0 ||
|
||||||
strcmp(data, "--") == 0) return;
|
strcmp(data, "--") == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(atoi(data) > 0 && atoi(data) > _lastRollingLog) _lastRollingLog = atoi(data);
|
if(atoi(data) > 0 && atoi(data) > _lastRollingLog)
|
||||||
|
{
|
||||||
|
_lastRollingLog = atoi(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(comparePrefixedPath(topic, mqtt_topic_lock_action))
|
if(comparePrefixedPath(topic, mqtt_topic_lock_action))
|
||||||
@@ -161,7 +167,10 @@ void NukiNetworkOpener::onMqttDataReceived(char* topic, int topic_len, char* dat
|
|||||||
strcmp(data, "ack") == 0 ||
|
strcmp(data, "ack") == 0 ||
|
||||||
strcmp(data, "unknown_action") == 0 ||
|
strcmp(data, "unknown_action") == 0 ||
|
||||||
strcmp(data, "denied") == 0 ||
|
strcmp(data, "denied") == 0 ||
|
||||||
strcmp(data, "error") == 0) return;
|
strcmp(data, "error") == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Log->print(F("Opener action received: "));
|
Log->print(F("Opener action received: "));
|
||||||
Log->println(data);
|
Log->println(data);
|
||||||
@@ -194,7 +203,10 @@ void NukiNetworkOpener::onMqttDataReceived(char* topic, int topic_len, char* dat
|
|||||||
{
|
{
|
||||||
if(_keypadCommandReceivedReceivedCallback != nullptr)
|
if(_keypadCommandReceivedReceivedCallback != nullptr)
|
||||||
{
|
{
|
||||||
if(strcmp(data, "--") == 0) return;
|
if(strcmp(data, "--") == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_keypadCommandReceivedReceivedCallback(data, _keypadCommandId, _keypadCommandName, _keypadCommandCode, _keypadCommandEnabled);
|
_keypadCommandReceivedReceivedCallback(data, _keypadCommandId, _keypadCommandName, _keypadCommandCode, _keypadCommandEnabled);
|
||||||
|
|
||||||
@@ -254,7 +266,10 @@ void NukiNetworkOpener::onMqttDataReceived(char* topic, int topic_len, char* dat
|
|||||||
|
|
||||||
if(comparePrefixedPath(topic, mqtt_topic_config_action))
|
if(comparePrefixedPath(topic, mqtt_topic_config_action))
|
||||||
{
|
{
|
||||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(_configUpdateReceivedCallback != NULL)
|
if(_configUpdateReceivedCallback != NULL)
|
||||||
{
|
{
|
||||||
@@ -266,7 +281,10 @@ void NukiNetworkOpener::onMqttDataReceived(char* topic, int topic_len, char* dat
|
|||||||
|
|
||||||
if(comparePrefixedPath(topic, mqtt_topic_keypad_json_action))
|
if(comparePrefixedPath(topic, mqtt_topic_keypad_json_action))
|
||||||
{
|
{
|
||||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(_keypadJsonCommandReceivedReceivedCallback != NULL)
|
if(_keypadJsonCommandReceivedReceivedCallback != NULL)
|
||||||
{
|
{
|
||||||
@@ -278,7 +296,10 @@ void NukiNetworkOpener::onMqttDataReceived(char* topic, int topic_len, char* dat
|
|||||||
|
|
||||||
if(comparePrefixedPath(topic, mqtt_topic_timecontrol_action))
|
if(comparePrefixedPath(topic, mqtt_topic_timecontrol_action))
|
||||||
{
|
{
|
||||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(_timeControlCommandReceivedReceivedCallback != NULL)
|
if(_timeControlCommandReceivedReceivedCallback != NULL)
|
||||||
{
|
{
|
||||||
@@ -290,7 +311,10 @@ void NukiNetworkOpener::onMqttDataReceived(char* topic, int topic_len, char* dat
|
|||||||
|
|
||||||
if(comparePrefixedPath(topic, mqtt_topic_auth_action))
|
if(comparePrefixedPath(topic, mqtt_topic_auth_action))
|
||||||
{
|
{
|
||||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(_authCommandReceivedReceivedCallback != NULL)
|
if(_authCommandReceivedReceivedCallback != NULL)
|
||||||
{
|
{
|
||||||
@@ -329,7 +353,9 @@ void NukiNetworkOpener::publishKeyTurnerState(const NukiOpener::OpenerState& key
|
|||||||
{
|
{
|
||||||
publishString(mqtt_topic_lock_continuous_mode, "on", true);
|
publishString(mqtt_topic_lock_continuous_mode, "on", true);
|
||||||
json["continuous_mode"] = 1;
|
json["continuous_mode"] = 1;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
publishString(mqtt_topic_lock_continuous_mode, "off", true);
|
publishString(mqtt_topic_lock_continuous_mode, "off", true);
|
||||||
json["continuous_mode"] = 0;
|
json["continuous_mode"] = 0;
|
||||||
}
|
}
|
||||||
@@ -472,7 +498,10 @@ void NukiNetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::Log
|
|||||||
{
|
{
|
||||||
int sizeName = sizeof(log.name);
|
int sizeName = sizeof(log.name);
|
||||||
memcpy(authName, log.name, sizeName);
|
memcpy(authName, log.name, sizeName);
|
||||||
if(authName[sizeName - 1] != '\0') authName[sizeName] = '\0';
|
if(authName[sizeName - 1] != '\0')
|
||||||
|
{
|
||||||
|
authName[sizeName] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
if(log.index > authIndex)
|
if(log.index > authIndex)
|
||||||
{
|
{
|
||||||
@@ -550,8 +579,14 @@ void NukiNetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::Log
|
|||||||
|
|
||||||
memset(str, 0, sizeof(str));
|
memset(str, 0, sizeof(str));
|
||||||
|
|
||||||
if(log.data[2] == 9) entry["completionStatus"] = "notAuthorized";
|
if(log.data[2] == 9)
|
||||||
else if (log.data[2] == 224) entry["completionStatus"] = "invalidCode";
|
{
|
||||||
|
entry["completionStatus"] = "notAuthorized";
|
||||||
|
}
|
||||||
|
else if (log.data[2] == 224)
|
||||||
|
{
|
||||||
|
entry["completionStatus"] = "invalidCode";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NukiOpener::completionStatusToString((NukiOpener::CompletionStatus)log.data[2], str);
|
NukiOpener::completionStatusToString((NukiOpener::CompletionStatus)log.data[2], str);
|
||||||
@@ -602,7 +637,8 @@ void NukiNetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::Log
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
entry["source"] = "Unknown";
|
entry["source"] = "Unknown";
|
||||||
break; }
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
entry["geofence"] = log.data[2] == 1 ? "active" : "inactive";
|
entry["geofence"] = log.data[2] == 1 ? "active" : "inactive";
|
||||||
entry["doorbellSuppression"] = log.data[3] == 1 ? "active" : "inactive";
|
entry["doorbellSuppression"] = log.data[3] == 1 ? "active" : "inactive";
|
||||||
@@ -625,8 +661,14 @@ void NukiNetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::Log
|
|||||||
|
|
||||||
serializeJson(json, _buffer, _bufferSize);
|
serializeJson(json, _buffer, _bufferSize);
|
||||||
|
|
||||||
if(latest) publishString(mqtt_topic_lock_log_latest, _buffer, true);
|
if(latest)
|
||||||
else publishString(mqtt_topic_lock_log, _buffer, true);
|
{
|
||||||
|
publishString(mqtt_topic_lock_log_latest, _buffer, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
publishString(mqtt_topic_lock_log, _buffer, true);
|
||||||
|
}
|
||||||
|
|
||||||
if(authIndex > 0)
|
if(authIndex > 0)
|
||||||
{
|
{
|
||||||
@@ -858,7 +900,10 @@ void NukiNetworkOpener::publishKeypad(const std::list<NukiLock::KeypadEntry>& en
|
|||||||
|
|
||||||
jsonEntry["codeId"] = entry.codeId;
|
jsonEntry["codeId"] = entry.codeId;
|
||||||
|
|
||||||
if(publishCode) jsonEntry["code"] = entry.code;
|
if(publishCode)
|
||||||
|
{
|
||||||
|
jsonEntry["code"] = entry.code;
|
||||||
|
}
|
||||||
jsonEntry["enabled"] = entry.enabled;
|
jsonEntry["enabled"] = entry.enabled;
|
||||||
jsonEntry["name"] = entry.name;
|
jsonEntry["name"] = entry.name;
|
||||||
char createdDT[20];
|
char createdDT[20];
|
||||||
@@ -879,7 +924,8 @@ void NukiNetworkOpener::publishKeypad(const std::list<NukiLock::KeypadEntry>& en
|
|||||||
uint8_t allowedWeekdaysInt = entry.allowedWeekdays;
|
uint8_t allowedWeekdaysInt = entry.allowedWeekdays;
|
||||||
JsonArray weekdays = jsonEntry["allowedWeekdays"].to<JsonArray>();
|
JsonArray weekdays = jsonEntry["allowedWeekdays"].to<JsonArray>();
|
||||||
|
|
||||||
while(allowedWeekdaysInt > 0) {
|
while(allowedWeekdaysInt > 0)
|
||||||
|
{
|
||||||
if(allowedWeekdaysInt >= 64)
|
if(allowedWeekdaysInt >= 64)
|
||||||
{
|
{
|
||||||
weekdays.add("mon");
|
weekdays.add("mon");
|
||||||
@@ -968,12 +1014,14 @@ void NukiNetworkOpener::publishKeypad(const std::list<NukiLock::KeypadEntry>& en
|
|||||||
"",
|
"",
|
||||||
"diagnostic",
|
"diagnostic",
|
||||||
String("~") + mqtt_topic_keypad_json_action,
|
String("~") + mqtt_topic_keypad_json_action,
|
||||||
{ { (char*)"json_attr_t", (char*)basePathPrefixChr },
|
{
|
||||||
|
{ (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||||
{ (char*)"stat_on", (char*)"1" },
|
{ (char*)"stat_on", (char*)"1" },
|
||||||
{ (char*)"stat_off", (char*)"0" }});
|
{ (char*)"stat_off", (char*)"0" }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
++index;
|
++index;
|
||||||
@@ -1062,7 +1110,8 @@ void NukiNetworkOpener::publishTimeControl(const std::list<NukiOpener::TimeContr
|
|||||||
uint8_t weekdaysInt = entry.weekdays;
|
uint8_t weekdaysInt = entry.weekdays;
|
||||||
JsonArray weekdays = jsonEntry["weekdays"].to<JsonArray>();
|
JsonArray weekdays = jsonEntry["weekdays"].to<JsonArray>();
|
||||||
|
|
||||||
while(weekdaysInt > 0) {
|
while(weekdaysInt > 0)
|
||||||
|
{
|
||||||
if(weekdaysInt >= 64)
|
if(weekdaysInt >= 64)
|
||||||
{
|
{
|
||||||
weekdays.add("mon");
|
weekdays.add("mon");
|
||||||
@@ -1146,12 +1195,14 @@ void NukiNetworkOpener::publishTimeControl(const std::list<NukiOpener::TimeContr
|
|||||||
"",
|
"",
|
||||||
"diagnostic",
|
"diagnostic",
|
||||||
String("~") + mqtt_topic_timecontrol_action,
|
String("~") + mqtt_topic_timecontrol_action,
|
||||||
{ { (char*)"json_attr_t", (char*)basePathPrefixChr },
|
{
|
||||||
|
{ (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||||
{ (char*)"stat_on", (char*)"1" },
|
{ (char*)"stat_on", (char*)"1" },
|
||||||
{ (char*)"stat_off", (char*)"0" }});
|
{ (char*)"stat_off", (char*)"0" }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
++index;
|
++index;
|
||||||
@@ -1208,7 +1259,8 @@ void NukiNetworkOpener::publishAuth(const std::list<NukiOpener::AuthorizationEnt
|
|||||||
uint8_t allowedWeekdaysInt = entry.allowedWeekdays;
|
uint8_t allowedWeekdaysInt = entry.allowedWeekdays;
|
||||||
JsonArray weekdays = jsonEntry["allowedWeekdays"].to<JsonArray>();
|
JsonArray weekdays = jsonEntry["allowedWeekdays"].to<JsonArray>();
|
||||||
|
|
||||||
while(allowedWeekdaysInt > 0) {
|
while(allowedWeekdaysInt > 0)
|
||||||
|
{
|
||||||
if(allowedWeekdaysInt >= 64)
|
if(allowedWeekdaysInt >= 64)
|
||||||
{
|
{
|
||||||
weekdays.add("mon");
|
weekdays.add("mon");
|
||||||
@@ -1293,12 +1345,14 @@ void NukiNetworkOpener::publishAuth(const std::list<NukiOpener::AuthorizationEnt
|
|||||||
"",
|
"",
|
||||||
"diagnostic",
|
"diagnostic",
|
||||||
String("~") + mqtt_topic_auth_action,
|
String("~") + mqtt_topic_auth_action,
|
||||||
{ { (char*)"json_attr_t", (char*)basePathPrefixChr },
|
{
|
||||||
|
{ (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||||
{ (char*)"stat_on", (char*)"1" },
|
{ (char*)"stat_on", (char*)"1" },
|
||||||
{ (char*)"stat_off", (char*)"0" }});
|
{ (char*)"stat_off", (char*)"0" }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
++index;
|
++index;
|
||||||
@@ -1325,7 +1379,10 @@ void NukiNetworkOpener::publishConfigCommandResult(const char* result)
|
|||||||
|
|
||||||
void NukiNetworkOpener::publishKeypadCommandResult(const char* result)
|
void NukiNetworkOpener::publishKeypadCommandResult(const char* result)
|
||||||
{
|
{
|
||||||
if(_disableNonJSON) return;
|
if(_disableNonJSON)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
publishString(mqtt_topic_keypad_command_result, result, true);
|
publishString(mqtt_topic_keypad_command_result, result, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1361,7 +1418,10 @@ void NukiNetworkOpener::setConfigUpdateReceivedCallback(void (*configUpdateRecei
|
|||||||
|
|
||||||
void NukiNetworkOpener::setKeypadCommandReceivedCallback(void (*keypadCommandReceivedReceivedCallback)(const char* command, const uint& id, const String& name, const String& code, const int& enabled))
|
void NukiNetworkOpener::setKeypadCommandReceivedCallback(void (*keypadCommandReceivedReceivedCallback)(const char* command, const uint& id, const String& name, const String& code, const int& enabled))
|
||||||
{
|
{
|
||||||
if(_disableNonJSON) return;
|
if(_disableNonJSON)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
_keypadCommandReceivedReceivedCallback = keypadCommandReceivedReceivedCallback;
|
_keypadCommandReceivedReceivedCallback = keypadCommandReceivedReceivedCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1423,7 +1483,10 @@ void NukiNetworkOpener::publishString(const char* topic, const char* value, bool
|
|||||||
|
|
||||||
void NukiNetworkOpener::publishKeypadEntry(const String topic, NukiLock::KeypadEntry entry)
|
void NukiNetworkOpener::publishKeypadEntry(const String topic, NukiLock::KeypadEntry entry)
|
||||||
{
|
{
|
||||||
if(_disableNonJSON) return;
|
if(_disableNonJSON)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
char codeName[sizeof(entry.name) + 1];
|
char codeName[sizeof(entry.name) + 1];
|
||||||
memset(codeName, 0, sizeof(codeName));
|
memset(codeName, 0, sizeof(codeName));
|
||||||
@@ -1505,8 +1568,10 @@ uint8_t NukiNetworkOpener::queryCommands()
|
|||||||
return qc;
|
return qc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NukiNetworkOpener::buttonPressActionToString(const NukiOpener::ButtonPressAction btnPressAction, char* str) {
|
void NukiNetworkOpener::buttonPressActionToString(const NukiOpener::ButtonPressAction btnPressAction, char* str)
|
||||||
switch (btnPressAction) {
|
{
|
||||||
|
switch (btnPressAction)
|
||||||
|
{
|
||||||
case NukiOpener::ButtonPressAction::NoAction:
|
case NukiOpener::ButtonPressAction::NoAction:
|
||||||
strcpy(str, "No Action");
|
strcpy(str, "No Action");
|
||||||
break;
|
break;
|
||||||
@@ -1537,8 +1602,10 @@ void NukiNetworkOpener::buttonPressActionToString(const NukiOpener::ButtonPressA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NukiNetworkOpener::fobActionToString(const int fobact, char* str) {
|
void NukiNetworkOpener::fobActionToString(const int fobact, char* str)
|
||||||
switch (fobact) {
|
{
|
||||||
|
switch (fobact)
|
||||||
|
{
|
||||||
case 0:
|
case 0:
|
||||||
strcpy(str, "No Action");
|
strcpy(str, "No Action");
|
||||||
break;
|
break;
|
||||||
@@ -1563,8 +1630,10 @@ void NukiNetworkOpener::fobActionToString(const int fobact, char* str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NukiNetworkOpener::capabilitiesToString(const int capabilities, char* str) {
|
void NukiNetworkOpener::capabilitiesToString(const int capabilities, char* str)
|
||||||
switch (capabilities) {
|
{
|
||||||
|
switch (capabilities)
|
||||||
|
{
|
||||||
case 0:
|
case 0:
|
||||||
strcpy(str, "Door opener");
|
strcpy(str, "Door opener");
|
||||||
break;
|
break;
|
||||||
@@ -1580,8 +1649,10 @@ void NukiNetworkOpener::capabilitiesToString(const int capabilities, char* str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NukiNetworkOpener::operatingModeToString(const int opmode, char* str) {
|
void NukiNetworkOpener::operatingModeToString(const int opmode, char* str)
|
||||||
switch (opmode) {
|
{
|
||||||
|
switch (opmode)
|
||||||
|
{
|
||||||
case 0:
|
case 0:
|
||||||
strcpy(str, "Generic door opener");
|
strcpy(str, "Generic door opener");
|
||||||
break;
|
break;
|
||||||
@@ -1636,8 +1707,10 @@ void NukiNetworkOpener::operatingModeToString(const int opmode, char* str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NukiNetworkOpener::doorbellSuppressionToString(const int dbsupr, char* str) {
|
void NukiNetworkOpener::doorbellSuppressionToString(const int dbsupr, char* str)
|
||||||
switch (dbsupr) {
|
{
|
||||||
|
switch (dbsupr)
|
||||||
|
{
|
||||||
case 0:
|
case 0:
|
||||||
strcpy(str, "Off");
|
strcpy(str, "Off");
|
||||||
break;
|
break;
|
||||||
@@ -1668,8 +1741,10 @@ void NukiNetworkOpener::doorbellSuppressionToString(const int dbsupr, char* str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NukiNetworkOpener::soundToString(const int sound, char* str) {
|
void NukiNetworkOpener::soundToString(const int sound, char* str)
|
||||||
switch (sound) {
|
{
|
||||||
|
switch (sound)
|
||||||
|
{
|
||||||
case 0:
|
case 0:
|
||||||
strcpy(str, "No Sound");
|
strcpy(str, "No Sound");
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -136,7 +136,10 @@ void NukiOfficial::onOfficialUpdateReceived(const char *topic, const char *value
|
|||||||
Log->print(F("Battery critical: "));
|
Log->print(F("Battery critical: "));
|
||||||
Log->println(offCritical);
|
Log->println(offCritical);
|
||||||
|
|
||||||
if(!_disableNonJSON) _publisher->publishBool(mqtt_topic_battery_critical, offCritical, true);
|
if(!_disableNonJSON)
|
||||||
|
{
|
||||||
|
_publisher->publishBool(mqtt_topic_battery_critical, offCritical, true);
|
||||||
|
}
|
||||||
publishBatteryJson = true;
|
publishBatteryJson = true;
|
||||||
}
|
}
|
||||||
else if(strcmp(topic, mqtt_topic_official_batteryCharging) == 0)
|
else if(strcmp(topic, mqtt_topic_official_batteryCharging) == 0)
|
||||||
@@ -146,7 +149,10 @@ void NukiOfficial::onOfficialUpdateReceived(const char *topic, const char *value
|
|||||||
Log->print(F("Battery charging: "));
|
Log->print(F("Battery charging: "));
|
||||||
Log->println(offCharging);
|
Log->println(offCharging);
|
||||||
|
|
||||||
if(!_disableNonJSON) _publisher->publishBool(mqtt_topic_battery_charging, offCharging, true);
|
if(!_disableNonJSON)
|
||||||
|
{
|
||||||
|
_publisher->publishBool(mqtt_topic_battery_charging, offCharging, true);
|
||||||
|
}
|
||||||
publishBatteryJson = true;
|
publishBatteryJson = true;
|
||||||
}
|
}
|
||||||
else if(strcmp(topic, mqtt_topic_official_batteryChargeState) == 0)
|
else if(strcmp(topic, mqtt_topic_official_batteryChargeState) == 0)
|
||||||
@@ -156,19 +162,28 @@ void NukiOfficial::onOfficialUpdateReceived(const char *topic, const char *value
|
|||||||
Log->print(F("Battery level: "));
|
Log->print(F("Battery level: "));
|
||||||
Log->println(offChargeState);
|
Log->println(offChargeState);
|
||||||
|
|
||||||
if(!_disableNonJSON) _publisher->publishInt(mqtt_topic_battery_level, offChargeState, true);
|
if(!_disableNonJSON)
|
||||||
|
{
|
||||||
|
_publisher->publishInt(mqtt_topic_battery_level, offChargeState, true);
|
||||||
|
}
|
||||||
publishBatteryJson = true;
|
publishBatteryJson = true;
|
||||||
}
|
}
|
||||||
else if(strcmp(topic, mqtt_topic_official_keypadBatteryCritical) == 0)
|
else if(strcmp(topic, mqtt_topic_official_keypadBatteryCritical) == 0)
|
||||||
{
|
{
|
||||||
offKeypadCritical = (strcmp(value, "true") == 0 ? 1 : 0);
|
offKeypadCritical = (strcmp(value, "true") == 0 ? 1 : 0);
|
||||||
if(!_disableNonJSON) _publisher->publishBool(mqtt_topic_battery_keypad_critical, offKeypadCritical, true);
|
if(!_disableNonJSON)
|
||||||
|
{
|
||||||
|
_publisher->publishBool(mqtt_topic_battery_keypad_critical, offKeypadCritical, true);
|
||||||
|
}
|
||||||
publishBatteryJson = true;
|
publishBatteryJson = true;
|
||||||
}
|
}
|
||||||
else if(strcmp(topic, mqtt_topic_official_doorsensorBatteryCritical) == 0)
|
else if(strcmp(topic, mqtt_topic_official_doorsensorBatteryCritical) == 0)
|
||||||
{
|
{
|
||||||
offDoorsensorCritical = (strcmp(value, "true") == 0 ? 1 : 0);
|
offDoorsensorCritical = (strcmp(value, "true") == 0 ? 1 : 0);
|
||||||
if(!_disableNonJSON) _publisher->publishBool(mqtt_topic_battery_doorsensor_critical, offDoorsensorCritical, true);
|
if(!_disableNonJSON)
|
||||||
|
{
|
||||||
|
_publisher->publishBool(mqtt_topic_battery_doorsensor_critical, offDoorsensorCritical, true);
|
||||||
|
}
|
||||||
publishBatteryJson = true;
|
publishBatteryJson = true;
|
||||||
}
|
}
|
||||||
else if(strcmp(topic, mqtt_topic_official_commandResponse) == 0)
|
else if(strcmp(topic, mqtt_topic_official_commandResponse) == 0)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
|
|
||||||
NukiPublisher::NukiPublisher(NukiNetwork *network, const char* mqttPath)
|
NukiPublisher::NukiPublisher(NukiNetwork *network, const char* mqttPath)
|
||||||
: _network(network),
|
: _network(network),
|
||||||
_mqttPath(mqttPath)
|
_mqttPath(mqttPath)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
1640
src/NukiWrapper.cpp
1640
src/NukiWrapper.cpp
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
120
src/main.cpp
120
src/main.cpp
@@ -87,21 +87,25 @@ void ets_putc_handler(char c)
|
|||||||
static size_t buf_pos = 0;
|
static size_t buf_pos = 0;
|
||||||
buf[buf_pos] = c;
|
buf[buf_pos] = c;
|
||||||
buf_pos++;
|
buf_pos++;
|
||||||
if (c == '\n' || buf_pos == sizeof(buf)) {
|
if (c == '\n' || buf_pos == sizeof(buf))
|
||||||
|
{
|
||||||
write_fn(NULL, buf, buf_pos);
|
write_fn(NULL, buf, buf_pos);
|
||||||
buf_pos = 0;
|
buf_pos = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int _log_vprintf(const char *fmt, va_list args) {
|
int _log_vprintf(const char *fmt, va_list args)
|
||||||
|
{
|
||||||
int ret = vsnprintf(log_print_buffer, sizeof(log_print_buffer), fmt, args);
|
int ret = vsnprintf(log_print_buffer, sizeof(log_print_buffer), fmt, args);
|
||||||
if (ret >= 0){
|
if (ret >= 0)
|
||||||
|
{
|
||||||
Log->write((uint8_t *)log_print_buffer, (size_t)ret);
|
Log->write((uint8_t *)log_print_buffer, (size_t)ret);
|
||||||
}
|
}
|
||||||
return 0; //return vprintf(fmt, args);
|
return 0; //return vprintf(fmt, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setReroute(){
|
void setReroute()
|
||||||
|
{
|
||||||
esp_log_set_vprintf(_log_vprintf);
|
esp_log_set_vprintf(_log_vprintf);
|
||||||
if(preferences->getBool(preference_mqtt_log_enabled))
|
if(preferences->getBool(preference_mqtt_log_enabled))
|
||||||
{
|
{
|
||||||
@@ -152,7 +156,10 @@ void networkTask(void *pvParameters)
|
|||||||
setReroute();
|
setReroute();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if(connected && openerEnabled) networkOpener->update();
|
if(connected && openerEnabled)
|
||||||
|
{
|
||||||
|
networkOpener->update();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if((esp_timer_get_time() / 1000) - networkLoopTs > 120000)
|
if((esp_timer_get_time() / 1000) - networkLoopTs > 120000)
|
||||||
@@ -263,14 +270,24 @@ uint8_t checkPartition()
|
|||||||
Log->print(F("Partition subtype: "));
|
Log->print(F("Partition subtype: "));
|
||||||
Log->println(running_partition->subtype);
|
Log->println(running_partition->subtype);
|
||||||
|
|
||||||
if(running_partition->size == 1966080) return 0; //OLD PARTITION TABLE
|
if(running_partition->size == 1966080)
|
||||||
else if(running_partition->subtype == ESP_PARTITION_SUBTYPE_APP_OTA_0) return 1; //NEW PARTITION TABLE, RUNNING MAIN APP
|
{
|
||||||
else return 2; //NEW PARTITION TABLE, RUNNING UPDATER APP
|
return 0; //OLD PARTITION TABLE
|
||||||
|
}
|
||||||
|
else if(running_partition->subtype == ESP_PARTITION_SUBTYPE_APP_OTA_0)
|
||||||
|
{
|
||||||
|
return 1; //NEW PARTITION TABLE, RUNNING MAIN APP
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 2; //NEW PARTITION TABLE, RUNNING UPDATER APP
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t _http_event_handler(esp_http_client_event_t *evt)
|
esp_err_t _http_event_handler(esp_http_client_event_t *evt)
|
||||||
{
|
{
|
||||||
switch (evt->event_id) {
|
switch (evt->event_id)
|
||||||
|
{
|
||||||
case HTTP_EVENT_ERROR:
|
case HTTP_EVENT_ERROR:
|
||||||
Log->println("HTTP_EVENT_ERROR");
|
Log->println("HTTP_EVENT_ERROR");
|
||||||
break;
|
break;
|
||||||
@@ -315,14 +332,16 @@ void otaTask(void *pvParameter)
|
|||||||
preferences->putString(preference_ota_main_url, "");
|
preferences->putString(preference_ota_main_url, "");
|
||||||
}
|
}
|
||||||
Log->println("Starting OTA task");
|
Log->println("Starting OTA task");
|
||||||
esp_http_client_config_t config = {
|
esp_http_client_config_t config =
|
||||||
|
{
|
||||||
.url = updateUrl.c_str(),
|
.url = updateUrl.c_str(),
|
||||||
.event_handler = _http_event_handler,
|
.event_handler = _http_event_handler,
|
||||||
.crt_bundle_attach = esp_crt_bundle_attach,
|
.crt_bundle_attach = esp_crt_bundle_attach,
|
||||||
.keep_alive_enable = true,
|
.keep_alive_enable = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
esp_https_ota_config_t ota_config = {
|
esp_https_ota_config_t ota_config =
|
||||||
|
{
|
||||||
.http_config = &config,
|
.http_config = &config,
|
||||||
};
|
};
|
||||||
Log->print(F("Attempting to download update from "));
|
Log->print(F("Attempting to download update from "));
|
||||||
@@ -334,19 +353,23 @@ void otaTask(void *pvParameter)
|
|||||||
while (retryCount <= retryMax)
|
while (retryCount <= retryMax)
|
||||||
{
|
{
|
||||||
esp_err_t ret = esp_https_ota(&ota_config);
|
esp_err_t ret = esp_https_ota(&ota_config);
|
||||||
if (ret == ESP_OK) {
|
if (ret == ESP_OK)
|
||||||
|
{
|
||||||
Log->println("OTA Succeeded, Rebooting...");
|
Log->println("OTA Succeeded, Rebooting...");
|
||||||
esp_ota_set_boot_partition(esp_ota_get_next_update_partition(NULL));
|
esp_ota_set_boot_partition(esp_ota_get_next_update_partition(NULL));
|
||||||
restartEsp(RestartReason::OTACompleted);
|
restartEsp(RestartReason::OTACompleted);
|
||||||
break;
|
break;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Log->println("Firmware upgrade failed, retrying in 5 seconds");
|
Log->println("Firmware upgrade failed, retrying in 5 seconds");
|
||||||
retryCount++;
|
retryCount++;
|
||||||
esp_task_wdt_reset();
|
esp_task_wdt_reset();
|
||||||
delay(5000);
|
delay(5000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
while (1) {
|
while (1)
|
||||||
|
{
|
||||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -359,7 +382,8 @@ void otaTask(void *pvParameter)
|
|||||||
void setupTasks(bool ota)
|
void setupTasks(bool ota)
|
||||||
{
|
{
|
||||||
// configMAX_PRIORITIES is 25
|
// configMAX_PRIORITIES is 25
|
||||||
esp_task_wdt_config_t twdt_config = {
|
esp_task_wdt_config_t twdt_config =
|
||||||
|
{
|
||||||
.timeout_ms = 300000,
|
.timeout_ms = 300000,
|
||||||
.idle_core_mask = 0,
|
.idle_core_mask = 0,
|
||||||
.trigger_panic = true,
|
.trigger_panic = true,
|
||||||
@@ -375,13 +399,13 @@ void setupTasks(bool ota)
|
|||||||
{
|
{
|
||||||
xTaskCreatePinnedToCore(networkTask, "ntw", preferences->getInt(preference_task_size_network, NETWORK_TASK_SIZE), NULL, 3, &networkTaskHandle, 1);
|
xTaskCreatePinnedToCore(networkTask, "ntw", preferences->getInt(preference_task_size_network, NETWORK_TASK_SIZE), NULL, 3, &networkTaskHandle, 1);
|
||||||
esp_task_wdt_add(networkTaskHandle);
|
esp_task_wdt_add(networkTaskHandle);
|
||||||
#ifndef NUKI_HUB_UPDATER
|
#ifndef NUKI_HUB_UPDATER
|
||||||
if(!network->isApOpen())
|
if(!network->isApOpen())
|
||||||
{
|
{
|
||||||
xTaskCreatePinnedToCore(nukiTask, "nuki", preferences->getInt(preference_task_size_nuki, NUKI_TASK_SIZE), NULL, 2, &nukiTaskHandle, 0);
|
xTaskCreatePinnedToCore(nukiTask, "nuki", preferences->getInt(preference_task_size_nuki, NUKI_TASK_SIZE), NULL, 2, &nukiTaskHandle, 0);
|
||||||
esp_task_wdt_add(nukiTaskHandle);
|
esp_task_wdt_add(nukiTaskHandle);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,13 +416,13 @@ void setup()
|
|||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Log = &Serial;
|
Log = &Serial;
|
||||||
|
|
||||||
#ifndef NUKI_HUB_UPDATER
|
#ifndef NUKI_HUB_UPDATER
|
||||||
stdout = funopen(NULL, NULL, &write_fn, NULL, NULL);
|
stdout = funopen(NULL, NULL, &write_fn, NULL, NULL);
|
||||||
static char linebuf[1024];
|
static char linebuf[1024];
|
||||||
setvbuf(stdout, linebuf, _IOLBF, sizeof(linebuf));
|
setvbuf(stdout, linebuf, _IOLBF, sizeof(linebuf));
|
||||||
esp_rom_install_channel_putc(1, &ets_putc_handler);
|
esp_rom_install_channel_putc(1, &ets_putc_handler);
|
||||||
//ets_install_putc1(&ets_putc_handler);
|
//ets_install_putc1(&ets_putc_handler);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
preferences = new Preferences();
|
preferences = new Preferences();
|
||||||
preferences->begin("nukihub", false);
|
preferences->begin("nukihub", false);
|
||||||
@@ -408,24 +432,36 @@ void setup()
|
|||||||
|
|
||||||
initializeRestartReason();
|
initializeRestartReason();
|
||||||
|
|
||||||
if((partitionType==1 && preferences->getString(preference_ota_updater_url, "").length() > 0) || (partitionType==2 && preferences->getString(preference_ota_main_url, "").length() > 0)) doOta = true;
|
if((partitionType==1 && preferences->getString(preference_ota_updater_url, "").length() > 0) || (partitionType==2 && preferences->getString(preference_ota_main_url, "").length() > 0))
|
||||||
|
{
|
||||||
|
doOta = true;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef NUKI_HUB_UPDATER
|
#ifndef NUKI_HUB_UPDATER
|
||||||
if(preferences->getBool(preference_enable_bootloop_reset, false))
|
if(preferences->getBool(preference_enable_bootloop_reset, false))
|
||||||
{
|
{
|
||||||
bootloopDetection();
|
bootloopDetection();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NUKI_HUB_UPDATER
|
#ifdef NUKI_HUB_UPDATER
|
||||||
Log->print(F("Nuki Hub OTA version "));
|
Log->print(F("Nuki Hub OTA version "));
|
||||||
Log->println(NUKI_HUB_VERSION);
|
Log->println(NUKI_HUB_VERSION);
|
||||||
Log->print(F("Nuki Hub OTA build "));
|
Log->print(F("Nuki Hub OTA build "));
|
||||||
Log->println();
|
Log->println();
|
||||||
|
|
||||||
if(preferences->getString(preference_updater_version, "") != NUKI_HUB_VERSION) preferences->putString(preference_updater_version, NUKI_HUB_VERSION);
|
if(preferences->getString(preference_updater_version, "") != NUKI_HUB_VERSION)
|
||||||
if(preferences->getString(preference_updater_build, "") != NUKI_HUB_BUILD) preferences->putString(preference_updater_build, NUKI_HUB_BUILD);
|
{
|
||||||
if(preferences->getString(preference_updater_date, "") != NUKI_HUB_DATE) preferences->putString(preference_updater_date, NUKI_HUB_DATE);
|
preferences->putString(preference_updater_version, NUKI_HUB_VERSION);
|
||||||
|
}
|
||||||
|
if(preferences->getString(preference_updater_build, "") != NUKI_HUB_BUILD)
|
||||||
|
{
|
||||||
|
preferences->putString(preference_updater_build, NUKI_HUB_BUILD);
|
||||||
|
}
|
||||||
|
if(preferences->getString(preference_updater_date, "") != NUKI_HUB_DATE)
|
||||||
|
{
|
||||||
|
preferences->putString(preference_updater_date, NUKI_HUB_DATE);
|
||||||
|
}
|
||||||
|
|
||||||
network = new NukiNetwork(preferences);
|
network = new NukiNetwork(preferences);
|
||||||
network->initialize();
|
network->initialize();
|
||||||
@@ -436,9 +472,12 @@ void setup()
|
|||||||
webCfgServer = new WebCfgServer(network, preferences, network->networkDeviceType() == NetworkDeviceType::WiFi, partitionType, psychicServer);
|
webCfgServer = new WebCfgServer(network, preferences, network->networkDeviceType() == NetworkDeviceType::WiFi, partitionType, psychicServer);
|
||||||
webCfgServer->initialize();
|
webCfgServer->initialize();
|
||||||
psychicServer->listen(80);
|
psychicServer->listen(80);
|
||||||
psychicServer->onNotFound([](PsychicRequest* request) { return request->redirect("/"); });
|
psychicServer->onNotFound([](PsychicRequest* request)
|
||||||
|
{
|
||||||
|
return request->redirect("/");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
Log->print(F("Nuki Hub version "));
|
Log->print(F("Nuki Hub version "));
|
||||||
Log->println(NUKI_HUB_VERSION);
|
Log->println(NUKI_HUB_VERSION);
|
||||||
Log->print(F("Nuki Hub build "));
|
Log->print(F("Nuki Hub build "));
|
||||||
@@ -522,10 +561,13 @@ void setup()
|
|||||||
{
|
{
|
||||||
webCfgServer = new WebCfgServer(nuki, nukiOpener, network, gpio, preferences, network->networkDeviceType() == NetworkDeviceType::WiFi, partitionType, psychicServer);
|
webCfgServer = new WebCfgServer(nuki, nukiOpener, network, gpio, preferences, network->networkDeviceType() == NetworkDeviceType::WiFi, partitionType, psychicServer);
|
||||||
webCfgServer->initialize();
|
webCfgServer->initialize();
|
||||||
psychicServer->onNotFound([](PsychicRequest* request) { return request->redirect("/"); });
|
psychicServer->onNotFound([](PsychicRequest* request)
|
||||||
|
{
|
||||||
|
return request->redirect("/");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
#ifdef DEBUG_NUKIHUB
|
#ifdef DEBUG_NUKIHUB
|
||||||
else psychicServer->onNotFound([](PsychicRequest* request) { return request->redirect("/webserial"); });
|
else psychicServer->onNotFound([](PsychicRequest* request) { return request->redirect("/webserial"); });
|
||||||
|
|
||||||
if(preferences->getBool(preference_webserial_enabled, false))
|
if(preferences->getBool(preference_webserial_enabled, false))
|
||||||
@@ -534,21 +576,27 @@ void setup()
|
|||||||
WebSerial.begin(asyncServer);
|
WebSerial.begin(asyncServer);
|
||||||
WebSerial.setBuffer(1024);
|
WebSerial.setBuffer(1024);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(doOta) setupTasks(true);
|
if(doOta)
|
||||||
else setupTasks(false);
|
{
|
||||||
|
setupTasks(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setupTasks(false);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_NUKIHUB
|
#ifdef DEBUG_NUKIHUB
|
||||||
Log->print("Task Name\tStatus\tPrio\tHWM\tTask\tAffinity\n");
|
Log->print("Task Name\tStatus\tPrio\tHWM\tTask\tAffinity\n");
|
||||||
char stats_buffer[1024];
|
char stats_buffer[1024];
|
||||||
vTaskList(stats_buffer);
|
vTaskList(stats_buffer);
|
||||||
Log->println(stats_buffer);
|
Log->println(stats_buffer);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ RTC_NOINIT_ATTR bool criticalEthFailure;
|
|||||||
extern char WiFi_fallbackDetect[14];
|
extern char WiFi_fallbackDetect[14];
|
||||||
|
|
||||||
EthernetDevice::EthernetDevice(const String& hostname, Preferences* preferences, const IPConfiguration* ipConfiguration, const std::string& deviceName, uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_type_t ethtype, eth_clock_mode_t clock_mode)
|
EthernetDevice::EthernetDevice(const String& hostname, Preferences* preferences, const IPConfiguration* ipConfiguration, const std::string& deviceName, uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_type_t ethtype, eth_clock_mode_t clock_mode)
|
||||||
: NetworkDevice(hostname, ipConfiguration),
|
: NetworkDevice(hostname, ipConfiguration),
|
||||||
_deviceName(deviceName),
|
_deviceName(deviceName),
|
||||||
_phy_addr(phy_addr),
|
_phy_addr(phy_addr),
|
||||||
_power(power),
|
_power(power),
|
||||||
@@ -78,7 +78,7 @@ void EthernetDevice::initialize()
|
|||||||
_hardwareInitialized = ETH.begin(_type, _phy_addr, _cs, _irq, _rst, SPI);
|
_hardwareInitialized = ETH.begin(_type, _phy_addr, _cs, _irq, _rst, SPI);
|
||||||
criticalEthFailure = false;
|
criticalEthFailure = false;
|
||||||
}
|
}
|
||||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log->println(F("Use RMII"));
|
Log->println(F("Use RMII"));
|
||||||
@@ -90,7 +90,7 @@ void EthernetDevice::initialize()
|
|||||||
_checkIpTs = (esp_timer_get_time() / 1000) + 2000;
|
_checkIpTs = (esp_timer_get_time() / 1000) + 2000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(_hardwareInitialized)
|
if(_hardwareInitialized)
|
||||||
{
|
{
|
||||||
@@ -138,7 +138,8 @@ void EthernetDevice::update()
|
|||||||
|
|
||||||
void EthernetDevice::onNetworkEvent(arduino_event_id_t event, arduino_event_info_t info)
|
void EthernetDevice::onNetworkEvent(arduino_event_id_t event, arduino_event_info_t info)
|
||||||
{
|
{
|
||||||
switch (event) {
|
switch (event)
|
||||||
|
{
|
||||||
case ARDUINO_EVENT_ETH_START:
|
case ARDUINO_EVENT_ETH_START:
|
||||||
Log->println("ETH Started");
|
Log->println("ETH Started");
|
||||||
ETH.setHostname(_hostname.c_str());
|
ETH.setHostname(_hostname.c_str());
|
||||||
@@ -212,7 +213,10 @@ bool EthernetDevice::isApOpen()
|
|||||||
|
|
||||||
void EthernetDevice::onDisconnected()
|
void EthernetDevice::onDisconnected()
|
||||||
{
|
{
|
||||||
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000)) restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000))
|
||||||
|
{
|
||||||
|
restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t EthernetDevice::signalStrength()
|
int8_t EthernetDevice::signalStrength()
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "../Logger.h"
|
#include "../Logger.h"
|
||||||
|
|
||||||
IPConfiguration::IPConfiguration(Preferences *preferences)
|
IPConfiguration::IPConfiguration(Preferences *preferences)
|
||||||
: _preferences(preferences)
|
: _preferences(preferences)
|
||||||
{
|
{
|
||||||
if(!dhcpEnabled() && _preferences->getString(preference_ip_address, "").length() <= 0)
|
if(!dhcpEnabled() && _preferences->getString(preference_ip_address, "").length() <= 0)
|
||||||
{
|
{
|
||||||
@@ -23,10 +23,14 @@ IPConfiguration::IPConfiguration(Preferences *preferences)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Log->print(F("IP address: ")); Log->print(ipAddress());
|
Log->print(F("IP address: "));
|
||||||
Log->print(F(", Subnet: ")); Log->print(subnet());
|
Log->print(ipAddress());
|
||||||
Log->print(F(", Gateway: ")); Log->print(defaultGateway());
|
Log->print(F(", Subnet: "));
|
||||||
Log->print(F(", DNS: ")); Log->println(dnsServer());
|
Log->print(subnet());
|
||||||
|
Log->print(F(", Gateway: "));
|
||||||
|
Log->print(defaultGateway());
|
||||||
|
Log->print(F(", DNS: "));
|
||||||
|
Log->println(dnsServer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include "../RestartReason.h"
|
#include "../RestartReason.h"
|
||||||
|
|
||||||
WifiDevice::WifiDevice(const String& hostname, Preferences* preferences, const IPConfiguration* ipConfiguration)
|
WifiDevice::WifiDevice(const String& hostname, Preferences* preferences, const IPConfiguration* ipConfiguration)
|
||||||
: NetworkDevice(hostname, ipConfiguration),
|
: NetworkDevice(hostname, ipConfiguration),
|
||||||
_preferences(preferences)
|
_preferences(preferences)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -78,11 +78,13 @@ void WifiDevice::initialize()
|
|||||||
_preferences->putBool(preference_wifi_converted, true);
|
_preferences->putBool(preference_wifi_converted, true);
|
||||||
|
|
||||||
wifi_config_t wifi_cfg;
|
wifi_config_t wifi_cfg;
|
||||||
if(esp_wifi_get_config(WIFI_IF_STA, &wifi_cfg) != ESP_OK) {
|
if(esp_wifi_get_config(WIFI_IF_STA, &wifi_cfg) != ESP_OK)
|
||||||
|
{
|
||||||
Log->println("Failed to get Wi-Fi configuration in RAM");
|
Log->println("Failed to get Wi-Fi configuration in RAM");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (esp_wifi_set_storage(WIFI_STORAGE_FLASH) != ESP_OK) {
|
if (esp_wifi_set_storage(WIFI_STORAGE_FLASH) != ESP_OK)
|
||||||
|
{
|
||||||
Log->println("Failed to set storage Wi-Fi");
|
Log->println("Failed to set storage Wi-Fi");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +109,8 @@ void WifiDevice::initialize()
|
|||||||
memset(wifi_cfg.sta.ssid, 0, sizeof(wifi_cfg.sta.ssid));
|
memset(wifi_cfg.sta.ssid, 0, sizeof(wifi_cfg.sta.ssid));
|
||||||
memset(wifi_cfg.sta.password, 0, sizeof(wifi_cfg.sta.password));
|
memset(wifi_cfg.sta.password, 0, sizeof(wifi_cfg.sta.password));
|
||||||
|
|
||||||
if (esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg) != ESP_OK) {
|
if (esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg) != ESP_OK)
|
||||||
|
{
|
||||||
Log->println("Failed to clear NVS Wi-Fi configuration");
|
Log->println("Failed to clear NVS Wi-Fi configuration");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +235,10 @@ bool WifiDevice::connect()
|
|||||||
{
|
{
|
||||||
Log->print("No network found with SSID: ");
|
Log->print("No network found with SSID: ");
|
||||||
Log->println(ssid);
|
Log->println(ssid);
|
||||||
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000)) restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000))
|
||||||
|
{
|
||||||
|
restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||||
|
}
|
||||||
_connectOnScanDone = true;
|
_connectOnScanDone = true;
|
||||||
_openAP = false;
|
_openAP = false;
|
||||||
scan(false, true);
|
scan(false, true);
|
||||||
@@ -371,7 +377,10 @@ void WifiDevice::onDisconnected()
|
|||||||
|
|
||||||
if(!isConnected())
|
if(!isConnected())
|
||||||
{
|
{
|
||||||
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000)) restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000))
|
||||||
|
{
|
||||||
|
restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||||
|
}
|
||||||
|
|
||||||
WiFi.disconnect(true);
|
WiFi.disconnect(true);
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
|
|||||||
Reference in New Issue
Block a user