make rssi publish interval configurable

This commit is contained in:
technyon
2023-01-22 19:42:12 +01:00
parent d754f6319f
commit 5512a517c6
9 changed files with 26 additions and 9 deletions

View File

@@ -80,13 +80,18 @@ void Network::setupDevice()
void Network::initialize()
{
_restartOnDisconnect = _preferences->getBool(preference_restart_on_disconnect);
_rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval);
if(_hostname == "")
{
_hostname = "nukihub";
_preferences->putString(preference_hostname, _hostname);
}
if(_rssiPublishInterval == 0)
{
_rssiPublishInterval = -1;
_preferences->putInt(preference_rssi_publish_interval, _rssiPublishInterval);
}
_device->initialize();
Log->print(F("Host name: "));
@@ -205,15 +210,15 @@ int Network::update()
_presenceCsv = nullptr;
}
if(_device->signalStrength() != 127 && ts - _lastRssiTs > 2000)
if(_device->signalStrength() != 127 && _rssiPublishInterval > 0 && ts - _lastRssiTs > _rssiPublishInterval)
{
_lastRssiTs = ts;
int8_t rssi = _device->signalStrength();
if(rssi != _lastRssi)
{
publishInt(_maintenancePathPrefix, mqtt_topic_wifi_rssi, _device->signalStrength());
_lastRssi = rssi;
_lastRssiTs = ts;
}
}

View File

@@ -79,6 +79,7 @@ private:
unsigned long _lastConnectedTs = 0;
unsigned long _lastMaintenanceTs = 0;
unsigned long _lastRssiTs = 0;
long _rssiPublishInterval = 0;
NetworkDeviceType _networkDeviceType = (NetworkDeviceType)-1;

View File

@@ -45,6 +45,7 @@ void NukiOpenerWrapper::initialize()
_hassEnabled = _preferences->getString(preference_mqtt_hass_discovery) != "";
_nrOfRetries = _preferences->getInt(preference_command_nr_of_retries);
_retryDelay = _preferences->getInt(preference_command_retry_delay);
_rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval);
if(_intervalLockstate == 0)
{
@@ -132,9 +133,9 @@ void NukiOpenerWrapper::update()
setupHASS();
}
}
if(_nextRssiTs == 0 || ts > _nextRssiTs)
if(_rssiPublishInterval > 0 && (_nextRssiTs == 0 || ts > _nextRssiTs))
{
_nextRssiTs = ts + 3000;
_nextRssiTs = ts + _rssiPublishInterval;
int rssi = _nukiOpener.getRssi();
if(rssi != _lastRssi)

View File

@@ -77,11 +77,12 @@ private:
bool _paired = false;
bool _statusUpdated = false;
unsigned long _rssiPublishInterval = 0;
unsigned long _nextLockStateUpdateTs = 0;
unsigned long _nextBatteryReportTs = 0;
unsigned long _nextConfigUpdateTs = 0;
unsigned long _nextPairTs = 0;
unsigned long _nextRssiTs = 0;
long _nextRssiTs = 0;
unsigned long _lastRssi = 0;
NukiOpener::LockAction _nextLockAction = (NukiOpener::LockAction)0xff;
};

View File

@@ -50,6 +50,7 @@ void NukiWrapper::initialize(const bool& firstStart)
_hassEnabled = _preferences->getString(preference_mqtt_hass_discovery) != "";
_nrOfRetries = _preferences->getInt(preference_command_nr_of_retries);
_retryDelay = _preferences->getInt(preference_command_retry_delay);
_rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval);
if(firstStart)
{
@@ -158,9 +159,9 @@ void NukiWrapper::update()
setupHASS();
}
}
if(_nextRssiTs == 0 || ts > _nextRssiTs)
if(_rssiPublishInterval > 0 && (_nextRssiTs == 0 || ts > _nextRssiTs))
{
_nextRssiTs = ts + 3000;
_nextRssiTs = ts + _rssiPublishInterval;
int rssi = _nukiLock.getRssi();
if(rssi != _lastRssi)

View File

@@ -87,6 +87,7 @@ private:
int _nrOfRetries = 0;
int _retryDelay = 0;
int _retryCount = 0;
long _rssiPublishInterval = 0;
unsigned long _nextRetryTs = 0;
unsigned long _nextLockStateUpdateTs = 0;
unsigned long _nextBatteryReportTs = 0;

View File

@@ -17,6 +17,7 @@
#define preference_mqtt_key "mqttkey"
#define preference_mqtt_hass_discovery "hassdiscovery"
#define preference_network_hardware_detect "nwhwdt"
#define preference_rssi_publish_interval "rssipb"
#define preference_hostname "hostname"
#define preference_network_timeout "nettmout"
#define preference_restart_on_disconnect "restdisc"

View File

@@ -1,3 +1,3 @@
#pragma once
#define nuki_hub_version "7.0"
#define nuki_hub_version "7.1"

View File

@@ -245,6 +245,11 @@ bool WebCfgServer::processArgs(String& message)
_preferences->putInt(preference_network_hardware_detect, value.toInt());
configChanged = true;
}
else if(key == "RSSI")
{
_preferences->putInt(preference_rssi_publish_interval, value.toInt());
configChanged = true;
}
else if(key == "HASSDISCOVERY")
{
if(_preferences->getString(preference_mqtt_hass_discovery) != value)
@@ -604,6 +609,7 @@ void WebCfgServer::buildMqttConfigHtml(String &response)
printTextarea(response, "MQTTCRT", "MQTT SSL Client Certificate (*, optional)", _preferences->getString(preference_mqtt_crt).c_str(), TLS_CERT_MAX_SIZE);
printTextarea(response, "MQTTKEY", "MQTT SSL Client Key (*, optional)", _preferences->getString(preference_mqtt_key).c_str(), TLS_KEY_MAX_SIZE);
printDropDown(response, "NWHWDT", "Network hardware detection", String(_preferences->getInt(preference_network_hardware_detect)), getNetworkDetectionOptions());
printInputField(response, "RSSI", "RSSI Publish interval (milliseconds; -1 to disable)", _preferences->getInt(preference_rssi_publish_interval), 6);
printInputField(response, "NETTIMEOUT", "Network Timeout until restart (seconds; -1 to disable)", _preferences->getInt(preference_network_timeout), 5);
printCheckBox(response, "RSTDISC", "Restart on disconnect", _preferences->getBool(preference_restart_on_disconnect));
printInputField(response, "RSTTMR", "Restart timer (minutes; -1 to disable)", _preferences->getInt(preference_restart_timer), 10);