Retain Input GPIO

This commit is contained in:
iranl
2024-12-20 21:09:23 +01:00
parent eb0ecbf762
commit 180f61f499
5 changed files with 30 additions and 12 deletions

View File

@@ -324,7 +324,7 @@ void NukiNetwork::initialize()
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);
publishString(_lockPath.c_str(), gpioPath, std::to_string(digitalRead(pinEntry.pin)).c_str(), _retainGpio);
}
break;
case PinRole::GeneralOutput:
@@ -353,6 +353,7 @@ void NukiNetwork::readSettings()
_restartOnDisconnect = _preferences->getBool(preference_restart_on_disconnect, false);
_checkUpdates = _preferences->getBool(preference_check_updates, false);
_rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval, 0) * 1000;
_retainGpio = _preferences->getBool(preference_retain_gpio, false);
if(_rssiPublishInterval == 0)
{
@@ -573,7 +574,7 @@ bool NukiNetwork::update()
uint8_t pinState = digitalRead(pin) == HIGH ? 1 : 0;
char gpioPath[250];
buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pin)).c_str(), mqtt_topic_gpio_state});
publishInt(_lockPath.c_str(), gpioPath, pinState, false);
publishInt(_lockPath.c_str(), gpioPath, pinState, _retainGpio);
Log->print(F("GPIO "));
Log->print(pin);