add code to ignore lock action after mqtt reconnect

This commit is contained in:
technyon
2024-07-12 13:03:21 +02:00
parent 94a8bd1c8e
commit ef878592c1
4 changed files with 32 additions and 0 deletions

View File

@@ -616,6 +616,7 @@ bool NukiNetwork::reconnect()
if (_device->mqttConnected())
{
Log->println(F("MQTT connected"));
_mqttConnectedTs = millis();
_mqttConnectionState = 1;
delay(100);
@@ -718,6 +719,8 @@ 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;
parseGpioTopics(properties, topic, payload, len, index, total);
for(auto receiver : _mqttReceivers)
@@ -786,6 +789,22 @@ bool NukiNetwork::encryptionSupported()
return _device->supportsEncryption();
}
bool NukiNetwork::mqttRecentlyConnected()
{
return _mqttConnectedTs != -1 && (millis() - _mqttConnectedTs < 6000);
}
bool NukiNetwork::pathEquals(const char* prefix, const char* path, const char* referencePath)
{
char prefixedPath[500];
buildMqttPath(prefixedPath, { prefix, path });
Log->println(prefixedPath);
Log->println(referencePath);
return strcmp(prefixedPath, referencePath) == 0;
}
void NukiNetwork::publishFloat(const char* prefix, const char* topic, const float value, bool retain, const uint8_t precision)
{
char str[30];

View File

@@ -97,6 +97,8 @@ public:
int mqttConnectionState(); // 0 = not connected; 1 = connected; 2 = connected and mqtt processed
bool encryptionSupported();
bool mqttRecentlyConnected();
bool pathEquals(const char* prefix, const char* path, const char* referencePath);
uint16_t subscribe(const char* topic, uint8_t qos);
@@ -156,6 +158,7 @@ private:
Gpio* _gpio;
int _mqttConnectionState = 0;
long _mqttConnectedTs = -1;
bool _connectReplyReceived = false;
bool _firstDisconnected = true;

View File

@@ -182,6 +182,11 @@ void NukiNetworkLock::onMqttDataReceived(const char* topic, byte* payload, const
{
char* value = (char*)payload;
if(_network->mqttRecentlyConnected() && _network->pathEquals(_mqttPath, mqtt_topic_lock_action, topic))
{
Log->println("MQTT recently connected, ignoring lock action.");
}
if(comparePrefixedPath(topic, mqtt_topic_reset) && strcmp(value, "1") == 0)
{
Log->println(F("Restart requested via MQTT."));

View File

@@ -133,6 +133,11 @@ void NukiNetworkOpener::onMqttDataReceived(const char* topic, byte* payload, con
{
char* value = (char*)payload;
if(_network->mqttRecentlyConnected() && _network->pathEquals(_mqttPath, mqtt_topic_lock_action, topic))
{
Log->println("MQTT recently connected, ignoring opener action.");
}
if(comparePrefixedPath(topic, mqtt_topic_lock_log_rolling_last))
{
if(strcmp(value, "") == 0 ||