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 "9.13"
#define NUKI_HUB_VERSION_INT (uint32_t)913 #define NUKI_HUB_VERSION_INT (uint32_t)913
#define NUKI_HUB_BUILD "unknownbuildnr" #define NUKI_HUB_BUILD "unknownbuildnr"
#define NUKI_HUB_DATE "2025-10-05" #define NUKI_HUB_DATE "2025-10-06"
#define NUKI_HUB_DATE "2025-10-05" #define NUKI_HUB_DATE "2025-10-06"
#define GITHUB_LATEST_RELEASE_URL (char*)"https://github.com/technyon/nuki_hub/releases/latest" #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" #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::OutputHighMqttConnected:
case PinRole::OutputHighNetworkConnected: case PinRole::OutputHighNetworkConnected:
case PinRole::OutputHighBluetoothCommError: case PinRole::OutputHighBluetoothCommError:
case PinRole::OutputHighBluetoothComm:
pinMode(entry.pin, OUTPUT); pinMode(entry.pin, OUTPUT);
break; break;
case PinRole::Ethernet: case PinRole::Ethernet:
@@ -504,6 +505,8 @@ String Gpio::getRoleDescription(const PinRole& role) const
return "Output: High when MQTT connected"; return "Output: High when MQTT connected";
case PinRole::OutputHighNetworkConnected: case PinRole::OutputHighNetworkConnected:
return "Output: High when network connected"; return "Output: High when network connected";
case PinRole::OutputHighBluetoothComm:
return "Output: High on bluetooth communication active";
case PinRole::OutputHighBluetoothCommError: case PinRole::OutputHighBluetoothCommError:
return "Output: High on bluetooth communication error"; return "Output: High on bluetooth communication error";
default: default:
@@ -554,6 +557,7 @@ GpioAction Gpio::getGpioAction(const PinRole &role) const
case PinRole::OutputHighRtoOrCmActive: case PinRole::OutputHighRtoOrCmActive:
case PinRole::OutputHighMqttConnected: case PinRole::OutputHighMqttConnected:
case PinRole::OutputHighNetworkConnected: case PinRole::OutputHighNetworkConnected:
case PinRole::OutputHighBluetoothComm:
case PinRole::OutputHighBluetoothCommError: case PinRole::OutputHighBluetoothCommError:
default: default:
return GpioAction::None; return GpioAction::None;

View File

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

View File

@@ -46,9 +46,6 @@ NukiOpenerWrapper::NukiOpenerWrapper(const std::string& deviceName, NukiDeviceId
network->setAuthCommandReceivedCallback(nukiOpenerInst->onAuthCommandReceivedCallback); network->setAuthCommandReceivedCallback(nukiOpenerInst->onAuthCommandReceivedCallback);
_gpio->addCallback(NukiOpenerWrapper::gpioActionCallback); _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); _hassEnabled = _preferences->getBool(preference_mqtt_hass_enabled, false);
readSettings(); readSettings();
#ifndef NUKI_HUB_UPDATER #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 #endif
} }
@@ -3658,14 +3655,6 @@ const std::string NukiOpenerWrapper::hardwareVersion() const
return _hardwareVersion; return _hardwareVersion;
} }
void NukiOpenerWrapper::setCommErrorPins(const uint8_t& value)
{
for (uint8_t pin : _pinsCommError)
{
_gpio->setPinOutput(pin, value);
}
}
void NukiOpenerWrapper::disableWatchdog() void NukiOpenerWrapper::disableWatchdog()
{ {
_restartBeaconTimeout = -1; _restartBeaconTimeout = -1;

View File

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

View File

@@ -80,7 +80,7 @@ void NukiWrapper::initialize()
readSettings(); readSettings();
#ifndef NUKI_HUB_UPDATER #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 #endif
} }

View File

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

View File

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