add gpio output for bluetooth communication active

This commit is contained in:
technyon
2025-10-06 17:51:00 +07:00
parent e05ff0fdd0
commit 0e1caf6211
8 changed files with 27 additions and 22 deletions

View File

@@ -5,8 +5,8 @@
#define NUKI_HUB_VERSION "9.13"
#define NUKI_HUB_VERSION_INT (uint32_t)913
#define NUKI_HUB_BUILD "unknownbuildnr"
#define NUKI_HUB_DATE "2025-10-05"
#define NUKI_HUB_DATE "2025-10-05"
#define NUKI_HUB_DATE "2025-10-06"
#define NUKI_HUB_DATE "2025-10-06"
#define GITHUB_LATEST_RELEASE_URL (char*)"https://github.com/technyon/nuki_hub/releases/latest"
#define GITHUB_OTA_MANIFEST_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/manifest.json"

View File

@@ -181,6 +181,7 @@ void Gpio::setPins()
case PinRole::OutputHighMqttConnected:
case PinRole::OutputHighNetworkConnected:
case PinRole::OutputHighBluetoothCommError:
case PinRole::OutputHighBluetoothComm:
pinMode(entry.pin, OUTPUT);
break;
case PinRole::Ethernet:
@@ -504,6 +505,8 @@ String Gpio::getRoleDescription(const PinRole& role) const
return "Output: High when MQTT connected";
case PinRole::OutputHighNetworkConnected:
return "Output: High when network connected";
case PinRole::OutputHighBluetoothComm:
return "Output: High on bluetooth communication active";
case PinRole::OutputHighBluetoothCommError:
return "Output: High on bluetooth communication error";
default:
@@ -554,6 +557,7 @@ GpioAction Gpio::getGpioAction(const PinRole &role) const
case PinRole::OutputHighRtoOrCmActive:
case PinRole::OutputHighMqttConnected:
case PinRole::OutputHighNetworkConnected:
case PinRole::OutputHighBluetoothComm:
case PinRole::OutputHighBluetoothCommError:
default:
return GpioAction::None;

View File

@@ -31,7 +31,8 @@ enum class PinRole
Ethernet,
OutputHighMqttConnected,
OutputHighNetworkConnected,
OutputHighBluetoothCommError
OutputHighBluetoothCommError,
OutputHighBluetoothComm
};
enum class GpioAction
@@ -128,6 +129,7 @@ private:
PinRole::InputDeactivateCM,
PinRole::OutputHighMqttConnected,
PinRole::OutputHighNetworkConnected,
PinRole::OutputHighBluetoothComm,
PinRole::OutputHighBluetoothCommError,
PinRole::OutputHighLocked,
PinRole::OutputHighUnlocked,

View File

@@ -46,9 +46,6 @@ NukiOpenerWrapper::NukiOpenerWrapper(const std::string& deviceName, NukiDeviceId
network->setAuthCommandReceivedCallback(nukiOpenerInst->onAuthCommandReceivedCallback);
_gpio->addCallback(NukiOpenerWrapper::gpioActionCallback);
#ifndef NUKI_HUB_UPDATER
_pinsCommError = _gpio->getPinsWithRole(PinRole::OutputHighBluetoothCommError);
#endif
}
@@ -76,7 +73,7 @@ void NukiOpenerWrapper::initialize()
_hassEnabled = _preferences->getBool(preference_mqtt_hass_enabled, false);
readSettings();
#ifndef NUKI_HUB_UPDATER
_nukiRetryHandler = new NukiRetryHandler("Opener", _gpio, _gpio->getPinsWithRole(PinRole::OutputHighBluetoothCommError), _nrOfRetries, _retryDelay);
_nukiRetryHandler = new NukiRetryHandler("Opener", _gpio, _gpio->getPinsWithRole(PinRole::OutputHighBluetoothComm), _gpio->getPinsWithRole(PinRole::OutputHighBluetoothCommError), _nrOfRetries, _retryDelay);
#endif
}
@@ -3658,14 +3655,6 @@ const std::string NukiOpenerWrapper::hardwareVersion() const
return _hardwareVersion;
}
void NukiOpenerWrapper::setCommErrorPins(const uint8_t& value)
{
for (uint8_t pin : _pinsCommError)
{
_gpio->setPinOutput(pin, value);
}
}
void NukiOpenerWrapper::disableWatchdog()
{
_restartBeaconTimeout = -1;

View File

@@ -43,8 +43,6 @@ public:
const std::string firmwareVersion() const;
const std::string hardwareVersion() const;
void setCommErrorPins(const uint8_t& value);
const BleScanner::Scanner* bleScanner();
void notify(NukiOpener::EventType eventType) override;
@@ -88,8 +86,6 @@ private:
Gpio* _gpio = nullptr;
NukiRetryHandler* _nukiRetryHandler = nullptr;
std::vector<uint8_t> _pinsCommError;
int _intervalLockstate = 0; // seconds
int _intervalBattery = 0; // seconds
int _intervalConfig = 60 * 60; // seconds

View File

@@ -80,7 +80,7 @@ void NukiWrapper::initialize()
readSettings();
#ifndef NUKI_HUB_UPDATER
_nukiRetryHandler = new NukiRetryHandler("Lock", _gpio, _gpio->getPinsWithRole(PinRole::OutputHighBluetoothCommError), _nrOfRetries, _retryDelay);
_nukiRetryHandler = new NukiRetryHandler("Lock", _gpio, _gpio->getPinsWithRole(PinRole::OutputHighBluetoothComm), _gpio->getPinsWithRole(PinRole::OutputHighBluetoothCommError), _nrOfRetries, _retryDelay);
#endif
}

View File

@@ -1,9 +1,10 @@
#include "NukiRetryHandler.h"
#include "Logger.h"
NukiRetryHandler::NukiRetryHandler(std::string reference, Gpio* gpio, std::vector<uint8_t> pinsCommError, int nrOfRetries, int retryDelay)
NukiRetryHandler::NukiRetryHandler(std::string reference, Gpio* gpio, std::vector<uint8_t> pinsComm, std::vector<uint8_t> pinsCommError, int nrOfRetries, int retryDelay)
: _reference(reference),
_gpio(gpio),
_pinsComm(pinsComm),
_pinsCommError(pinsCommError),
_nrOfRetries(nrOfRetries),
_retryDelay(retryDelay)
@@ -16,6 +17,8 @@ const Nuki::CmdResult NukiRetryHandler::retryComm(std::function<Nuki::CmdResult(
int retryCount = 0;
setCommPins(HIGH);
while(retryCount < _nrOfRetries + 1 && cmdResult != Nuki::CmdResult::Success)
{
cmdResult = func();
@@ -36,11 +39,20 @@ const Nuki::CmdResult NukiRetryHandler::retryComm(std::function<Nuki::CmdResult(
vTaskDelay(_retryDelay / portTICK_PERIOD_MS);
}
}
setCommPins(LOW);
setCommErrorPins(LOW);
return cmdResult;
}
void NukiRetryHandler::setCommPins(const uint8_t& value)
{
for (uint8_t pin : _pinsComm)
{
_gpio->setPinOutput(pin, value);
}
}
void NukiRetryHandler::setCommErrorPins(const uint8_t& value)
{
for (uint8_t pin : _pinsCommError)

View File

@@ -6,17 +6,19 @@
class NukiRetryHandler
{
public:
NukiRetryHandler(std::string reference, Gpio* gpio, std::vector<uint8_t> pinsCommError, int nrOfRetries, int retryDelay);
NukiRetryHandler(std::string reference, Gpio* gpio, std::vector<uint8_t> pinsComm, std::vector<uint8_t> pinsCommError, int nrOfRetries, int retryDelay);
const Nuki::CmdResult retryComm(std::function<Nuki::CmdResult ()> func);
private:
void setCommPins(const uint8_t& value);
void setCommErrorPins(const uint8_t& value);
std::string _reference;
Gpio* _gpio = nullptr;
int _nrOfRetries = 0;
int _retryDelay = 0;
std::vector<uint8_t> _pinsComm;
std::vector<uint8_t> _pinsCommError;
};