Merge branch 'master' into separate-config

This commit is contained in:
iranl
2024-04-25 16:58:32 +02:00
committed by GitHub
23 changed files with 935 additions and 1676 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,53 +1,79 @@
name: Build using Github Actions
on: [push, pull_request]
jobs:
build-source:
build:
name: Checkout source code and build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y python3-serial cmake
- name: Install Arduino IDE
run: |
curl -L https://downloads.arduino.cc/arduino-1.8.19-linux64.tar.xz -o /tmp/arduino-ide.tar.xz
tar -xf /tmp/arduino-ide.tar.xz --directory ~/
cd ~/arduino*
./install.sh
./arduino --pref "boardsmanager.additional.urls=https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json" --save-prefs
./arduino --install-boards esp32:esp32:2.0.15
- name: Install Arduino CMake Toolchain
uses: actions/checkout@v2
- uses: actions/cache@v4
with:
repository: technyon/Arduino-CMake-Toolchain
path: arduino-toolchain
- name: Build
run: |
mkdir -p build
cd build
touch file_opts
cmake -D CMAKE_TOOLCHAIN_FILE=../arduino-toolchain/Arduino-toolchain.cmake ..
echo "# Espressif ESP32 Partition Table" > partitions.csv
echo "# Name, Type, SubType, Offset, Size, Flags" >> partitions.csv
echo "nvs, data, nvs, 0x9000, 0x5000," >> partitions.csv
echo "otadata, data, ota, 0xe000, 0x2000," >> partitions.csv
echo "app0, app, ota_0, 0x10000, 0x1E0000," >> partitions.csv
echo "app1, app, ota_1, 0x1F0000,0x1E0000," >> partitions.csv
echo "spiffs, data, spiffs, 0x3D0000,0x30000," >> partitions.csv
make
- name: Upload artifacts
run: |
mkdir release
cp build/nuki_hub.bin release/
cp build/nuki_hub.partitions.bin release/
cp $(find ~/.arduino15/packages/esp32/ | grep boot_app0.bin) release/
echo "esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size detect 0xe000 boot_app0.bin 0x1000 bootloader_dio_80m.bin 0x10000 nuki_hub.bin 0x8000 nuki_hub.partitions.bin" > release/flash.sh
- uses: actions/upload-artifact@v3
path: |
~/.cache/pip
~/.platformio/.cache
key: ${{ runner.os }}-pio
- uses: actions/setup-python@v5
with:
name: release-assets
path: release/
python-version: '3.9'
- name: Install PlatformIO Core
run: pip install --upgrade platformio
- name: Install ESPTool
run: pip install --upgrade esptool
- name: Build PlatformIO Project esp32dev
run: |
pio run --environment esp32dev
mkdir -p release/esp32dev
cp .pio/build/esp32dev/firmware.bin release/esp32dev/nuki_hub.bin
cp .pio/build/esp32dev/partitions.bin release/esp32dev/nuki_hub.partitions.bin
cp .pio/build/esp32dev/bootloader.bin release/esp32dev/bootloader.bin
esptool.py --chip esp32 merge_bin -o release/esp32dev/nuki_hub_esp32.bin --flash_mode dio --flash_freq keep --flash_size keep 0x1000 release/esp32dev/bootloader.bin 0x10000 release/esp32dev/nuki_hub.bin 0x8000 release/esp32dev/nuki_hub.partitions.bin
echo "esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq keep --flash_size detect 0x1000 bootloader.bin 0x10000 nuki_hub.bin 0x8000 nuki_hub.partitions.bin" > release/esp32dev/flash.sh
- name: Build PlatformIO Project esp32-s3
run: |
pio run --environment esp32-s3
mkdir -p release/esp32-s3
cp .pio/build/esp32-s3/firmware.bin release/esp32-s3/nuki_hub.bin
cp .pio/build/esp32-s3/partitions.bin release/esp32-s3/nuki_hub.partitions.bin
cp .pio/build/esp32-s3/bootloader.bin release/esp32-s3/bootloader.bin
esptool.py --chip esp32s3 merge_bin -o release/esp32-s3/nuki_hub_esp32s3.bin --flash_mode dio --flash_freq keep --flash_size keep 0x0 release/esp32-s3/bootloader.bin 0x10000 release/esp32-s3/nuki_hub.bin 0x8000 release/esp32-s3/nuki_hub.partitions.bin
echo "esptool.py --chip esp32s3 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq keep --flash_size detect 0x0 bootloader.bin 0x10000 nuki_hub.bin 0x8000 nuki_hub.partitions.bin" > release/esp32-s3/flash.sh
- name: Build PlatformIO Project esp32-c3
run: |
pio run --environment esp32-c3
mkdir -p release/esp32-c3
cp .pio/build/esp32-c3/firmware.bin release/esp32-c3/nuki_hub.bin
cp .pio/build/esp32-c3/partitions.bin release/esp32-c3/nuki_hub.partitions.bin
cp .pio/build/esp32-c3/bootloader.bin release/esp32-c3/bootloader.bin
esptool.py --chip esp32c3 merge_bin -o release/esp32-c3/nuki_hub_esp32c3.bin --flash_mode dio --flash_freq keep --flash_size keep 0x0 release/esp32-c3/bootloader.bin 0x10000 release/esp32-c3/nuki_hub.bin 0x8000 release/esp32-c3/nuki_hub.partitions.bin
echo "esptool.py --chip esp32c3 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq keep --flash_size detect 0x0 bootloader.bin 0x10000 nuki_hub.bin 0x8000 nuki_hub.partitions.bin" > release/esp32-c3/flash.sh
- name: Build PlatformIO Project esp32solo1
run: |
pio run --environment esp32solo1
mkdir -p release/esp32solo1
cp .pio/build/esp32solo1/firmware.bin release/esp32solo1/nuki_hub.bin
cp .pio/build/esp32solo1/partitions.bin release/esp32solo1/nuki_hub.partitions.bin
cp .pio/build/esp32solo1/bootloader.bin release/esp32solo1/bootloader.bin
esptool.py --chip esp32 merge_bin -o release/esp32solo1/nuki_hub_esp32solo1.bin --flash_mode dio --flash_freq keep --flash_size keep 0x1000 release/esp32solo1/bootloader.bin 0x10000 release/esp32solo1/nuki_hub.bin 0x8000 release/esp32solo1/nuki_hub.partitions.bin
echo "esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq keep --flash_size detect 0x1000 bootloader.bin 0x10000 nuki_hub.bin 0x8000 nuki_hub.partitions.bin" > release/esp32solo1/flash.sh
- name: Upload Artifact esp32dev
uses: actions/upload-artifact@v4
with:
name: esp32dev-assets
path: release/esp32dev
- name: Upload Artifact esp32-s3
uses: actions/upload-artifact@v4
with:
name: esp32-s3-assets
path: release/esp32-s3
- name: Upload Artifact esp32-c3
uses: actions/upload-artifact@v4
with:
name: esp32-c3-assets
path: release/esp32-c3
- name: Upload Artifact esp32solo1
uses: actions/upload-artifact@v4
with:
name: esp32solo1-assets
path: release/esp32solo1

View File

@@ -58,6 +58,10 @@
#define mqtt_topic_keypad_json_action "/keypad/actionJson"
#define mqtt_topic_keypad_json_command_result "/keypad/commandResultJson"
#define mqtt_topic_timecontrol_json "/timecontrol/json"
#define mqtt_topic_timecontrol_action "/timecontrol/action"
#define mqtt_topic_timecontrol_command_result "/timecontrol/commandResult"
#define mqtt_topic_info_hardware_version "/info/hardwareVersion"
#define mqtt_topic_info_firmware_version "/info/firmwareVersion"
#define mqtt_topic_info_nuki_hub_version "/info/nukiHubVersion"

View File

@@ -75,6 +75,12 @@ void NetworkLock::initialize()
_network->initTopic(_mqttPath, mqtt_topic_keypad_json_action, "--");
}
if(_preferences->getBool(preference_timecontrol_control_enabled))
{
_network->subscribe(_mqttPath, mqtt_topic_timecontrol_action);
_network->initTopic(_mqttPath, mqtt_topic_timecontrol_action, "--");
}
_network->addReconnectedCallback([&]()
{
_reconnected = true;
@@ -210,6 +216,18 @@ void NetworkLock::onMqttDataReceived(const char* topic, byte* payload, const uns
publishString(mqtt_topic_keypad_json_action, "--");
}
if(comparePrefixedPath(topic, mqtt_topic_timecontrol_action))
{
if(strcmp(value, "") == 0 || strcmp(value, "--") == 0) return;
if(_timeControlCommandReceivedReceivedCallback != NULL)
{
_timeControlCommandReceivedReceivedCallback(value);
}
publishString(mqtt_topic_timecontrol_action, "--");
}
}
void NetworkLock::publishKeyTurnerState(const NukiLock::KeyTurnerState& keyTurnerState, const NukiLock::KeyTurnerState& lastKeyTurnerState)
@@ -692,6 +710,78 @@ void NetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entries,
}
}
void NetworkLock::publishTimeControl(const std::list<NukiLock::TimeControlEntry>& timeControlEntries)
{
char str[50];
JsonDocument json;
for(const auto& entry : timeControlEntries)
{
auto jsonEntry = json.add();
jsonEntry["entryId"] = entry.entryId;
jsonEntry["enabled"] = entry.enabled;
uint8_t weekdaysInt = entry.weekdays;
JsonArray weekdays = jsonEntry["weekdays"].to<JsonArray>();
while(weekdaysInt > 0) {
if(weekdaysInt >= 64)
{
weekdays.add("mon");
weekdaysInt -= 64;
continue;
}
if(weekdaysInt >= 32)
{
weekdays.add("tue");
weekdaysInt -= 32;
continue;
}
if(weekdaysInt >= 16)
{
weekdays.add("wed");
weekdaysInt -= 16;
continue;
}
if(weekdaysInt >= 8)
{
weekdays.add("thu");
weekdaysInt -= 8;
continue;
}
if(weekdaysInt >= 4)
{
weekdays.add("fri");
weekdaysInt -= 4;
continue;
}
if(weekdaysInt >= 2)
{
weekdays.add("sat");
weekdaysInt -= 2;
continue;
}
if(weekdaysInt >= 1)
{
weekdays.add("sun");
weekdaysInt -= 1;
continue;
}
}
char timeT[5];
sprintf(timeT, "%02d:%02d", entry.timeHour, entry.timeMin);
jsonEntry["time"] = timeT;
memset(str, 0, sizeof(str));
NukiLock::lockactionToString(entry.lockAction, str);
jsonEntry["lockAction"] = str;
}
serializeJson(json, _buffer, _bufferSize);
publishString(mqtt_topic_timecontrol_json, _buffer);
}
void NetworkLock::publishConfigCommandResult(const char* result)
{
publishString(mqtt_topic_config_action_command_result, result);
@@ -707,6 +797,11 @@ void NetworkLock::publishKeypadJsonCommandResult(const char* result)
publishString(mqtt_topic_keypad_json_command_result, result);
}
void NetworkLock::publishTimeControlCommandResult(const char* result)
{
publishString(mqtt_topic_timecontrol_command_result, result);
}
void NetworkLock::setLockActionReceivedCallback(LockActionResult (*lockActionReceivedCallback)(const char *))
{
_lockActionReceivedCallback = lockActionReceivedCallback;
@@ -727,6 +822,11 @@ void NetworkLock::setKeypadJsonCommandReceivedCallback(void (*keypadJsonCommandR
_keypadJsonCommandReceivedReceivedCallback = keypadJsonCommandReceivedReceivedCallback;
}
void NetworkLock::setTimeControlCommandReceivedCallback(void (*timeControlCommandReceivedReceivedCallback)(const char *))
{
_timeControlCommandReceivedReceivedCallback = timeControlCommandReceivedReceivedCallback;
}
void NetworkLock::buildMqttPath(const char* path, char* outPath)
{
int offset = 0;

View File

@@ -37,15 +37,17 @@ public:
void publishHASSConfig(char* deviceType, const char* baseTopic, char* name, char* uidString, const bool& hasDoorSensor, const bool& hasKeypad, const bool& publishAuthData, char* lockAction, char* unlockAction, char* openAction);
void removeHASSConfig(char* uidString);
void publishKeypad(const std::list<NukiLock::KeypadEntry>& entries, uint maxKeypadCodeCount);
void publishTimeControl(const std::list<NukiLock::TimeControlEntry>& timeControlEntries);
void publishConfigCommandResult(const char* result);
void publishKeypadCommandResult(const char* result);
void publishKeypadJsonCommandResult(const char* result);
void publishTimeControlCommandResult(const char* result);
void setLockActionReceivedCallback(LockActionResult (*lockActionReceivedCallback)(const char* value));
void setConfigUpdateReceivedCallback(void (*configUpdateReceivedCallback)(const char* value));
void setKeypadCommandReceivedCallback(void (*keypadCommandReceivedReceivedCallback)(const char* command, const uint& id, const String& name, const String& code, const int& enabled));
void setKeypadJsonCommandReceivedCallback(void (*keypadJsonCommandReceivedReceivedCallback)(const char* value));
void setTimeControlCommandReceivedCallback(void (*timeControlCommandReceivedReceivedCallback)(const char* value));
void onMqttDataReceived(const char* topic, byte* payload, const unsigned int length) override;
bool reconnected();
@@ -99,4 +101,5 @@ private:
void (*_configUpdateReceivedCallback)(const char* value) = nullptr;
void (*_keypadCommandReceivedReceivedCallback)(const char* command, const uint& id, const String& name, const String& code, const int& enabled) = nullptr;
void (*_keypadJsonCommandReceivedReceivedCallback)(const char* value) = nullptr;
};
void (*_timeControlCommandReceivedReceivedCallback)(const char* value) = nullptr;
};

View File

@@ -66,6 +66,12 @@ void NetworkOpener::initialize()
_network->initTopic(_mqttPath, mqtt_topic_keypad_json_action, "--");
}
if(_preferences->getBool(preference_timecontrol_control_enabled))
{
_network->subscribe(_mqttPath, mqtt_topic_timecontrol_action);
_network->initTopic(_mqttPath, mqtt_topic_timecontrol_action, "--");
}
_network->addReconnectedCallback([&]()
{
_reconnected = true;
@@ -202,6 +208,18 @@ void NetworkOpener::onMqttDataReceived(const char* topic, byte* payload, const u
publishString(mqtt_topic_keypad_json_action, "--");
}
if(comparePrefixedPath(topic, mqtt_topic_timecontrol_action))
{
if(strcmp(value, "") == 0 || strcmp(value, "--") == 0) return;
if(_timeControlCommandReceivedReceivedCallback != NULL)
{
_timeControlCommandReceivedReceivedCallback(value);
}
publishString(mqtt_topic_timecontrol_action, "--");
}
}
void NetworkOpener::publishKeyTurnerState(const NukiOpener::OpenerState& keyTurnerState, const NukiOpener::OpenerState& lastKeyTurnerState)
@@ -375,24 +393,24 @@ void NetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::LogEntr
{
case NukiOpener::LoggingType::LockAction:
memset(str, 0, sizeof(str));
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
NukiOpener::lockactionToString((NukiOpener::LockAction)log.data[0], str);
entry["action"] = str;
memset(str, 0, sizeof(str));
NukiLock::triggerToString((NukiLock::Trigger)log.data[1], str);
NukiOpener::triggerToString((NukiOpener::Trigger)log.data[1], str);
entry["trigger"] = str;
memset(str, 0, sizeof(str));
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[3], str);
NukiOpener::completionStatusToString((NukiOpener::CompletionStatus)log.data[3], str);
entry["completionStatus"] = str;
break;
case NukiOpener::LoggingType::KeypadAction:
memset(str, 0, sizeof(str));
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
NukiOpener::lockactionToString((NukiOpener::LockAction)log.data[0], str);
entry["action"] = str;
memset(str, 0, sizeof(str));
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[2], str);
NukiOpener::completionStatusToString((NukiOpener::CompletionStatus)log.data[2], str);
entry["completionStatus"] = str;
break;
case NukiOpener::LoggingType::DoorbellRecognition:
@@ -751,6 +769,78 @@ void NetworkOpener::publishKeypad(const std::list<NukiLock::KeypadEntry>& entrie
}
}
void NetworkOpener::publishTimeControl(const std::list<NukiOpener::TimeControlEntry>& timeControlEntries)
{
char str[50];
JsonDocument json;
for(const auto& entry : timeControlEntries)
{
auto jsonEntry = json.add();
jsonEntry["entryId"] = entry.entryId;
jsonEntry["enabled"] = entry.enabled;
uint8_t weekdaysInt = entry.weekdays;
JsonArray weekdays = jsonEntry["weekdays"].to<JsonArray>();
while(weekdaysInt > 0) {
if(weekdaysInt >= 64)
{
weekdays.add("mon");
weekdaysInt -= 64;
continue;
}
if(weekdaysInt >= 32)
{
weekdays.add("tue");
weekdaysInt -= 32;
continue;
}
if(weekdaysInt >= 16)
{
weekdays.add("wed");
weekdaysInt -= 16;
continue;
}
if(weekdaysInt >= 8)
{
weekdays.add("thu");
weekdaysInt -= 8;
continue;
}
if(weekdaysInt >= 4)
{
weekdays.add("fri");
weekdaysInt -= 4;
continue;
}
if(weekdaysInt >= 2)
{
weekdays.add("sat");
weekdaysInt -= 2;
continue;
}
if(weekdaysInt >= 1)
{
weekdays.add("sun");
weekdaysInt -= 1;
continue;
}
}
char timeT[5];
sprintf(timeT, "%02d:%02d", entry.timeHour, entry.timeMin);
jsonEntry["time"] = timeT;
memset(str, 0, sizeof(str));
NukiOpener::lockactionToString(entry.lockAction, str);
jsonEntry["lockAction"] = str;
}
serializeJson(json, _buffer, _bufferSize);
publishString(mqtt_topic_timecontrol_json, _buffer);
}
void NetworkOpener::publishConfigCommandResult(const char* result)
{
publishString(mqtt_topic_config_action_command_result, result);
@@ -766,6 +856,11 @@ void NetworkOpener::publishKeypadJsonCommandResult(const char* result)
publishString(mqtt_topic_keypad_json_command_result, result);
}
void NetworkOpener::publishTimeControlCommandResult(const char* result)
{
publishString(mqtt_topic_timecontrol_command_result, result);
}
void NetworkOpener::setLockActionReceivedCallback(LockActionResult (*lockActionReceivedCallback)(const char *))
{
_lockActionReceivedCallback = lockActionReceivedCallback;
@@ -786,6 +881,11 @@ void NetworkOpener::setKeypadJsonCommandReceivedCallback(void (*keypadJsonComman
_keypadJsonCommandReceivedReceivedCallback = keypadJsonCommandReceivedReceivedCallback;
}
void NetworkOpener::setTimeControlCommandReceivedCallback(void (*timeControlCommandReceivedReceivedCallback)(const char *))
{
_timeControlCommandReceivedReceivedCallback = timeControlCommandReceivedReceivedCallback;
}
void NetworkOpener::publishFloat(const char *topic, const float value, const uint8_t precision)
{
_network->publishFloat(_mqttPath, topic, value, precision);

View File

@@ -34,15 +34,17 @@ public:
void publishHASSConfig(char* deviceType, const char* baseTopic, char* name, char* uidString, char* lockAction, char* unlockAction, char* openAction);
void removeHASSConfig(char* uidString);
void publishKeypad(const std::list<NukiLock::KeypadEntry>& entries, uint maxKeypadCodeCount);
void publishTimeControl(const std::list<NukiOpener::TimeControlEntry>& timeControlEntries);
void publishConfigCommandResult(const char* result);
void publishKeypadCommandResult(const char* result);
void publishKeypadJsonCommandResult(const char* result);
void publishTimeControlCommandResult(const char* result);
void setLockActionReceivedCallback(LockActionResult (*lockActionReceivedCallback)(const char* value));
void setConfigUpdateReceivedCallback(void (*configUpdateReceivedCallback)(const char* value));
void setKeypadCommandReceivedCallback(void (*keypadCommandReceivedReceivedCallback)(const char* command, const uint& id, const String& name, const String& code, const int& enabled));
void setKeypadJsonCommandReceivedCallback(void (*keypadJsonCommandReceivedReceivedCallback)(const char* value));
void setTimeControlCommandReceivedCallback(void (*timeControlCommandReceivedReceivedCallback)(const char* value));
void onMqttDataReceived(const char* topic, byte* payload, const unsigned int length) override;
bool reconnected();
@@ -104,4 +106,5 @@ private:
void (*_configUpdateReceivedCallback)(const char* value) = nullptr;
void (*_keypadCommandReceivedReceivedCallback)(const char* command, const uint& id, const String& name, const String& code, const int& enabled) = nullptr;
void (*_keypadJsonCommandReceivedReceivedCallback)(const char* value) = nullptr;
void (*_timeControlCommandReceivedReceivedCallback)(const char* value) = nullptr;
};

View File

@@ -172,6 +172,11 @@ void NukiOpenerWrapper::update()
setupHASS();
}
}
if(_nextTimeControlUpdateTs != 0 && ts > _nextTimeControlUpdateTs)
{
_nextTimeControlUpdateTs = 0;
updateTimeControl(true);
}
if(_hassEnabled && _configRead && _network->reconnected())
{
setupHASS();
@@ -406,7 +411,9 @@ void NukiOpenerWrapper::updateConfig()
_hardwareVersion = std::to_string(_nukiConfig.hardwareRevision[0]) + "." + std::to_string(_nukiConfig.hardwareRevision[1]);
_network->publishConfig(_nukiConfig);
_retryConfigCount = 0;
if(_preferences->getBool(preference_timecontrol_info_enabled)) updateTimeControl(false);
const int pinStatus = _preferences->getInt(preference_opener_pin_status, 4);
if(isPinSet()) {
@@ -501,6 +508,9 @@ void NukiOpenerWrapper::updateKeypad()
{
std::list<NukiLock::KeypadEntry> entries;
_nukiOpener.getKeypadEntries(&entries);
Log->print(F("Opener keypad codes: "));
Log->println(entries.size());
entries.sort([](const NukiLock::KeypadEntry& a, const NukiLock::KeypadEntry& b) { return a.codeId < b.codeId; });
@@ -524,6 +534,43 @@ void NukiOpenerWrapper::updateKeypad()
postponeBleWatchdog();
}
void NukiOpenerWrapper::updateTimeControl(bool retrieved)
{
if(!_preferences->getBool(preference_timecontrol_info_enabled)) return;
if(!retrieved)
{
Log->print(F("Querying opener time control: "));
Nuki::CmdResult result = _nukiOpener.retrieveTimeControlEntries();
printCommandResult(result);
if(result == Nuki::CmdResult::Success)
{
_nextTimeControlUpdateTs = millis() + 5000;
}
}
else
{
std::list<NukiOpener::TimeControlEntry> timeControlEntries;
_nukiOpener.getTimeControlEntries(&timeControlEntries);
Log->print(F("Opener time control entries: "));
Log->println(timeControlEntries.size());
timeControlEntries.sort([](const NukiOpener::TimeControlEntry& a, const NukiOpener::TimeControlEntry& b) { return a.entryId < b.entryId; });
_network->publishTimeControl(timeControlEntries);
_timeControlIds.clear();
_timeControlIds.reserve(timeControlEntries.size());
for(const auto& entry : timeControlEntries)
{
_timeControlIds.push_back(entry.entryId);
}
}
postponeBleWatchdog();
}
void NukiOpenerWrapper::postponeBleWatchdog()
{
_disableBleWatchdogTs = millis() + 15000;
@@ -531,24 +578,31 @@ void NukiOpenerWrapper::postponeBleWatchdog()
NukiOpener::LockAction NukiOpenerWrapper::lockActionToEnum(const char *str)
{
if(strcmp(str, "activateRTO") == 0) return NukiOpener::LockAction::ActivateRTO;
else if(strcmp(str, "deactivateRTO") == 0) return NukiOpener::LockAction::DeactivateRTO;
else if(strcmp(str, "electricStrikeActuation") == 0) return NukiOpener::LockAction::ElectricStrikeActuation;
else if(strcmp(str, "activateCM") == 0) return NukiOpener::LockAction::ActivateCM;
else if(strcmp(str, "deactivateCM") == 0) return NukiOpener::LockAction::DeactivateCM;
else if(strcmp(str, "fobAction2") == 0) return NukiOpener::LockAction::FobAction2;
else if(strcmp(str, "fobAction1") == 0) return NukiOpener::LockAction::FobAction1;
else if(strcmp(str, "fobAction3") == 0) return NukiOpener::LockAction::FobAction3;
if(strcmp(str, "activateRTO") == 0 || strcmp(str, "ActivateRTO") == 0) return NukiOpener::LockAction::ActivateRTO;
else if(strcmp(str, "deactivateRTO") == 0 || strcmp(str, "DeactivateRTO") == 0) return NukiOpener::LockAction::DeactivateRTO;
else if(strcmp(str, "electricStrikeActuation") == 0 || strcmp(str, "ElectricStrikeActuation") == 0) return NukiOpener::LockAction::ElectricStrikeActuation;
else if(strcmp(str, "activateCM") == 0 || strcmp(str, "ActivateCM") == 0) return NukiOpener::LockAction::ActivateCM;
else if(strcmp(str, "deactivateCM") == 0 || strcmp(str, "DeactivateCM") == 0) return NukiOpener::LockAction::DeactivateCM;
else if(strcmp(str, "fobAction2") == 0 || strcmp(str, "FobAction2") == 0) return NukiOpener::LockAction::FobAction2;
else if(strcmp(str, "fobAction1") == 0 || strcmp(str, "FobAction1") == 0) return NukiOpener::LockAction::FobAction1;
else if(strcmp(str, "fobAction3") == 0 || strcmp(str, "FobAction3") == 0) return NukiOpener::LockAction::FobAction3;
return (NukiOpener::LockAction)0xff;
}
LockActionResult NukiOpenerWrapper::onLockActionReceivedCallback(const char *value)
{
NukiOpener::LockAction action = nukiOpenerInst->lockActionToEnum(value);
if((int)action == 0xff)
NukiOpener::LockAction action;
if(strlen(value) > 0)
{
return LockActionResult::UnknownAction;
action = nukiOpenerInst->lockActionToEnum(value);
if((int)action == 0xff)
{
return LockActionResult::UnknownAction;
}
}
else return LockActionResult::UnknownAction;
nukiOpenerPreferences = new Preferences();
nukiOpenerPreferences->begin("nukihub", true);
@@ -1672,6 +1726,181 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
}
}
void NukiOpenerWrapper::onTimeControlCommandReceived(const char *value)
{
if(_nukiOpener.getSecurityPincode() == 0)
{
_network->publishTimeControlCommandResult("noPinSet");
return;
}
if(!_preferences->getBool(preference_timecontrol_control_enabled))
{
_network->publishTimeControlCommandResult("timeControlControlDisabled");
return;
}
JsonDocument json;
DeserializationError jsonError = deserializeJson(json, value);
if(jsonError)
{
_network->publishTimeControlCommandResult("invalidJson");
return;
}
Nuki::CmdResult result = (Nuki::CmdResult)-1;
const char *action = json["action"].as<const char*>();
uint8_t entryId = json["entryId"].as<unsigned int>();
uint8_t enabled = json["enabled"].as<unsigned int>();
String weekdays = json["weekdays"].as<String>();
const char *time = json["time"].as<const char*>();
const char *lockAct = json["lockAction"].as<const char*>();
NukiOpener::LockAction timeControlLockAction;
if(strlen(lockAct) > 0)
{
timeControlLockAction = nukiOpenerInst->lockActionToEnum(lockAct);
if((int)timeControlLockAction == 0xff)
{
_network->publishTimeControlCommandResult("invalidLockAction");
return;
}
}
else
{
_network->publishTimeControlCommandResult("invalidLockAction");
return;
}
if(action)
{
bool idExists = false;
if(entryId)
{
idExists = std::find(_timeControlIds.begin(), _timeControlIds.end(), entryId) != _timeControlIds.end();
}
if(strcmp(action, "delete") == 0) {
if(idExists)
{
result = _nukiOpener.removeTimeControlEntry(entryId);
Log->print("Delete time control ");
Log->println((int)result);
}
else
{
_network->publishTimeControlCommandResult("noExistingEntryIdSet");
return;
}
}
else if(strcmp(action, "add") == 0 || strcmp(action, "update") == 0)
{
uint8_t timeHour;
uint8_t timeMin;
uint8_t weekdaysInt = 0;
unsigned int timeAr[2];
if(time)
{
if(strlen(time) == 5)
{
String timeStr = time;
timeAr[0] = (uint8_t)timeStr.substring(0, 2).toInt();
timeAr[1] = (uint8_t)timeStr.substring(3, 5).toInt();
if(timeAr[0] < 0 || timeAr[0] > 23 || timeAr[1] < 0 || timeAr[1] > 59)
{
_network->publishTimeControlCommandResult("invalidTime");
return;
}
}
else
{
_network->publishTimeControlCommandResult("invalidTime");
return;
}
}
else
{
_network->publishTimeControlCommandResult("invalidTime");
return;
}
if(weekdays.indexOf("mon") >= 0) weekdaysInt += 64;
if(weekdays.indexOf("tue") >= 0) weekdaysInt += 32;
if(weekdays.indexOf("wed") >= 0) weekdaysInt += 16;
if(weekdays.indexOf("thu") >= 0) weekdaysInt += 8;
if(weekdays.indexOf("fri") >= 0) weekdaysInt += 4;
if(weekdays.indexOf("sat") >= 0) weekdaysInt += 2;
if(weekdays.indexOf("sun") >= 0) weekdaysInt += 1;
if(strcmp(action, "add") == 0)
{
NukiOpener::NewTimeControlEntry entry;
memset(&entry, 0, sizeof(entry));
entry.weekdays = weekdaysInt;
if(time)
{
entry.timeHour = timeAr[0];
entry.timeMin = timeAr[1];
}
entry.lockAction = timeControlLockAction;
result = _nukiOpener.addTimeControlEntry(entry);
Log->print("Add time control: ");
Log->println((int)result);
}
else if (strcmp(action, "update") == 0)
{
NukiOpener::TimeControlEntry entry;
memset(&entry, 0, sizeof(entry));
entry.entryId = entryId;
entry.enabled = enabled == 0 ? 0 : 1;
entry.weekdays = weekdaysInt;
if(time)
{
entry.timeHour = timeAr[0];
entry.timeMin = timeAr[1];
}
entry.lockAction = timeControlLockAction;
result = _nukiOpener.updateTimeControlEntry(entry);
Log->print("Update time control: ");
Log->println((int)result);
}
}
else
{
_network->publishTimeControlCommandResult("invalidAction");
return;
}
if((int)result != -1)
{
char resultStr[15];
memset(&resultStr, 0, sizeof(resultStr));
NukiOpener::cmdResultToString(result, resultStr);
_network->publishTimeControlCommandResult(resultStr);
}
_nextConfigUpdateTs = millis() + 300;
}
else
{
_network->publishTimeControlCommandResult("noActionSet");
return;
}
}
const NukiOpener::OpenerState &NukiOpenerWrapper::keyTurnerState()
{
return _keyTurnerState;

View File

@@ -50,16 +50,19 @@ private:
static void onConfigUpdateReceivedCallback(const char* value);
static void onKeypadCommandReceivedCallback(const char* command, const uint& id, const String& name, const String& code, const int& enabled);
static void onKeypadJsonCommandReceivedCallback(const char* value);
static void onTimeControlCommandReceivedCallback(const char* value);
static void gpioActionCallback(const GpioAction& action, const int& pin);
void onKeypadCommandReceived(const char* command, const uint& id, const String& name, const String& code, const int& enabled);
void onConfigUpdateReceived(const char* value);
void onKeypadJsonCommandReceived(const char* value);
void onTimeControlCommandReceived(const char* value);
void updateKeyTurnerState();
void updateBatteryState();
void updateConfig();
void updateAuthData();
void updateKeypad();
void updateTimeControl(bool retrieved);
void postponeBleWatchdog();
void updateGpioOutputs();
@@ -102,6 +105,7 @@ private:
int _retryLockstateCount = 0;
unsigned long _nextRetryTs = 0;
std::vector<uint16_t> _keypadCodeIds;
std::vector<uint8_t> _timeControlIds;
NukiOpener::OpenerState _lastKeyTurnerState;
NukiOpener::OpenerState _keyTurnerState;
@@ -126,6 +130,7 @@ private:
unsigned long _nextLockStateUpdateTs = 0;
unsigned long _nextBatteryReportTs = 0;
unsigned long _nextConfigUpdateTs = 0;
unsigned long _nextTimeControlUpdateTs = 0;
unsigned long _nextKeypadUpdateTs = 0;
unsigned long _nextPairTs = 0;
long _nextRssiTs = 0;

View File

@@ -33,6 +33,7 @@ NukiWrapper::NukiWrapper(const std::string& deviceName, NukiDeviceId* deviceId,
network->setConfigUpdateReceivedCallback(nukiInst->onConfigUpdateReceivedCallback);
network->setKeypadCommandReceivedCallback(nukiInst->onKeypadCommandReceivedCallback);
network->setKeypadJsonCommandReceivedCallback(nukiInst->onKeypadJsonCommandReceivedCallback);
network->setTimeControlCommandReceivedCallback(nukiInst->onTimeControlCommandReceivedCallback);
_gpio->addCallback(NukiWrapper::gpioActionCallback);
}
@@ -190,6 +191,11 @@ void NukiWrapper::update()
setupHASS();
}
}
if(_nextTimeControlUpdateTs != 0 && ts > _nextTimeControlUpdateTs)
{
_nextTimeControlUpdateTs = 0;
updateTimeControl(true);
}
if(_hassEnabled && _configRead && _network->reconnected())
{
setupHASS();
@@ -386,7 +392,9 @@ void NukiWrapper::updateConfig()
_hardwareVersion = std::to_string(_nukiConfig.hardwareRevision[0]) + "." + std::to_string(_nukiConfig.hardwareRevision[1]);
_network->publishConfig(_nukiConfig);
_retryConfigCount = 0;
if(_preferences->getBool(preference_timecontrol_info_enabled)) updateTimeControl(false);
const int pinStatus = _preferences->getInt(preference_lock_pin_status, 4);
if(isPinSet()) {
@@ -481,6 +489,9 @@ void NukiWrapper::updateKeypad()
{
std::list<NukiLock::KeypadEntry> entries;
_nukiLock.getKeypadEntries(&entries);
Log->print(F("Lock keypad codes: "));
Log->println(entries.size());
entries.sort([](const NukiLock::KeypadEntry& a, const NukiLock::KeypadEntry& b) { return a.codeId < b.codeId; });
@@ -504,6 +515,43 @@ void NukiWrapper::updateKeypad()
postponeBleWatchdog();
}
void NukiWrapper::updateTimeControl(bool retrieved)
{
if(!_preferences->getBool(preference_timecontrol_info_enabled)) return;
if(!retrieved)
{
Log->print(F("Querying lock time control: "));
Nuki::CmdResult result = _nukiLock.retrieveTimeControlEntries();
printCommandResult(result);
if(result == Nuki::CmdResult::Success)
{
_nextTimeControlUpdateTs = millis() + 5000;
}
}
else
{
std::list<NukiLock::TimeControlEntry> timeControlEntries;
_nukiLock.getTimeControlEntries(&timeControlEntries);
Log->print(F("Lock time control entries: "));
Log->println(timeControlEntries.size());
timeControlEntries.sort([](const NukiLock::TimeControlEntry& a, const NukiLock::TimeControlEntry& b) { return a.entryId < b.entryId; });
_network->publishTimeControl(timeControlEntries);
_timeControlIds.clear();
_timeControlIds.reserve(timeControlEntries.size());
for(const auto& entry : timeControlEntries)
{
_timeControlIds.push_back(entry.entryId);
}
}
postponeBleWatchdog();
}
void NukiWrapper::postponeBleWatchdog()
{
_disableBleWatchdogTs = millis() + 15000;
@@ -511,26 +559,32 @@ void NukiWrapper::postponeBleWatchdog()
NukiLock::LockAction NukiWrapper::lockActionToEnum(const char *str)
{
if(strcmp(str, "unlock") == 0) return NukiLock::LockAction::Unlock;
else if(strcmp(str, "lock") == 0) return NukiLock::LockAction::Lock;
else if(strcmp(str, "unlatch") == 0) return NukiLock::LockAction::Unlatch;
else if(strcmp(str, "lockNgo") == 0) return NukiLock::LockAction::LockNgo;
else if(strcmp(str, "lockNgoUnlatch") == 0) return NukiLock::LockAction::LockNgoUnlatch;
else if(strcmp(str, "fullLock") == 0) return NukiLock::LockAction::FullLock;
else if(strcmp(str, "fobAction2") == 0) return NukiLock::LockAction::FobAction2;
else if(strcmp(str, "fobAction1") == 0) return NukiLock::LockAction::FobAction1;
else if(strcmp(str, "fobAction3") == 0) return NukiLock::LockAction::FobAction3;
if(strcmp(str, "unlock") == 0 || strcmp(str, "Unlock") == 0) return NukiLock::LockAction::Unlock;
else if(strcmp(str, "lock") == 0 || strcmp(str, "Lock") == 0) return NukiLock::LockAction::Lock;
else if(strcmp(str, "unlatch") == 0 || strcmp(str, "Unlatch") == 0) return NukiLock::LockAction::Unlatch;
else if(strcmp(str, "lockNgo") == 0 || strcmp(str, "LockNgo") == 0) return NukiLock::LockAction::LockNgo;
else if(strcmp(str, "lockNgoUnlatch") == 0 || strcmp(str, "LockNgoUnlatch") == 0) return NukiLock::LockAction::LockNgoUnlatch;
else if(strcmp(str, "fullLock") == 0 || strcmp(str, "FullLock") == 0) return NukiLock::LockAction::FullLock;
else if(strcmp(str, "fobAction2") == 0 || strcmp(str, "FobAction2") == 0) return NukiLock::LockAction::FobAction2;
else if(strcmp(str, "fobAction1") == 0 || strcmp(str, "FobAction1") == 0) return NukiLock::LockAction::FobAction1;
else if(strcmp(str, "fobAction3") == 0 || strcmp(str, "FobAction3") == 0) return NukiLock::LockAction::FobAction3;
return (NukiLock::LockAction)0xff;
}
LockActionResult NukiWrapper::onLockActionReceivedCallback(const char *value)
{
NukiLock::LockAction action = nukiInst->lockActionToEnum(value);
if((int)action == 0xff)
NukiLock::LockAction action;
if(strlen(value) > 0)
{
return LockActionResult::UnknownAction;
action = nukiInst->lockActionToEnum(value);
if((int)action == 0xff)
{
return LockActionResult::UnknownAction;
}
}
else return LockActionResult::UnknownAction;
nukiLockPreferences = new Preferences();
nukiLockPreferences->begin("nukihub", true);
@@ -1185,6 +1239,11 @@ void NukiWrapper::onKeypadJsonCommandReceivedCallback(const char *value)
nukiInst->onKeypadJsonCommandReceived(value);
}
void NukiWrapper::onTimeControlCommandReceivedCallback(const char *value)
{
nukiInst->onTimeControlCommandReceived(value);
}
void NukiWrapper::gpioActionCallback(const GpioAction &action, const int& pin)
{
switch(action)
@@ -1654,6 +1713,181 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
}
}
void NukiWrapper::onTimeControlCommandReceived(const char *value)
{
if(_nukiLock.getSecurityPincode() == 0)
{
_network->publishTimeControlCommandResult("noPinSet");
return;
}
if(!_preferences->getBool(preference_timecontrol_control_enabled))
{
_network->publishTimeControlCommandResult("timeControlControlDisabled");
return;
}
JsonDocument json;
DeserializationError jsonError = deserializeJson(json, value);
if(jsonError)
{
_network->publishTimeControlCommandResult("invalidJson");
return;
}
Nuki::CmdResult result = (Nuki::CmdResult)-1;
const char *action = json["action"].as<const char*>();
uint8_t entryId = json["entryId"].as<unsigned int>();
uint8_t enabled = json["enabled"].as<unsigned int>();
String weekdays = json["weekdays"].as<String>();
const char *time = json["time"].as<const char*>();
const char *lockAct = json["lockAction"].as<const char*>();
NukiLock::LockAction timeControlLockAction;
if(strlen(lockAct) > 0)
{
timeControlLockAction = nukiInst->lockActionToEnum(lockAct);
if((int)timeControlLockAction == 0xff)
{
_network->publishTimeControlCommandResult("invalidLockAction");
return;
}
}
else
{
_network->publishTimeControlCommandResult("invalidLockAction");
return;
}
if(action)
{
bool idExists = false;
if(entryId)
{
idExists = std::find(_timeControlIds.begin(), _timeControlIds.end(), entryId) != _timeControlIds.end();
}
if(strcmp(action, "delete") == 0) {
if(idExists)
{
result = _nukiLock.removeTimeControlEntry(entryId);
Log->print("Delete time control ");
Log->println((int)result);
}
else
{
_network->publishTimeControlCommandResult("noExistingEntryIdSet");
return;
}
}
else if(strcmp(action, "add") == 0 || strcmp(action, "update") == 0)
{
uint8_t timeHour;
uint8_t timeMin;
uint8_t weekdaysInt = 0;
unsigned int timeAr[2];
if(time)
{
if(strlen(time) == 5)
{
String timeStr = time;
timeAr[0] = (uint8_t)timeStr.substring(0, 2).toInt();
timeAr[1] = (uint8_t)timeStr.substring(3, 5).toInt();
if(timeAr[0] < 0 || timeAr[0] > 23 || timeAr[1] < 0 || timeAr[1] > 59)
{
_network->publishTimeControlCommandResult("invalidTime");
return;
}
}
else
{
_network->publishTimeControlCommandResult("invalidTime");
return;
}
}
else
{
_network->publishTimeControlCommandResult("invalidTime");
return;
}
if(weekdays.indexOf("mon") >= 0) weekdaysInt += 64;
if(weekdays.indexOf("tue") >= 0) weekdaysInt += 32;
if(weekdays.indexOf("wed") >= 0) weekdaysInt += 16;
if(weekdays.indexOf("thu") >= 0) weekdaysInt += 8;
if(weekdays.indexOf("fri") >= 0) weekdaysInt += 4;
if(weekdays.indexOf("sat") >= 0) weekdaysInt += 2;
if(weekdays.indexOf("sun") >= 0) weekdaysInt += 1;
if(strcmp(action, "add") == 0)
{
NukiLock::NewTimeControlEntry entry;
memset(&entry, 0, sizeof(entry));
entry.weekdays = weekdaysInt;
if(time)
{
entry.timeHour = timeAr[0];
entry.timeMin = timeAr[1];
}
entry.lockAction = timeControlLockAction;
result = _nukiLock.addTimeControlEntry(entry);
Log->print("Add time control: ");
Log->println((int)result);
}
else if (strcmp(action, "update") == 0)
{
NukiLock::TimeControlEntry entry;
memset(&entry, 0, sizeof(entry));
entry.entryId = entryId;
entry.enabled = enabled == 0 ? 0 : 1;
entry.weekdays = weekdaysInt;
if(time)
{
entry.timeHour = timeAr[0];
entry.timeMin = timeAr[1];
}
entry.lockAction = timeControlLockAction;
result = _nukiLock.updateTimeControlEntry(entry);
Log->print("Update time control: ");
Log->println((int)result);
}
}
else
{
_network->publishTimeControlCommandResult("invalidAction");
return;
}
if((int)result != -1)
{
char resultStr[15];
memset(&resultStr, 0, sizeof(resultStr));
NukiLock::cmdResultToString(result, resultStr);
_network->publishTimeControlCommandResult(resultStr);
}
_nextConfigUpdateTs = millis() + 300;
}
else
{
_network->publishTimeControlCommandResult("noActionSet");
return;
}
}
const NukiLock::KeyTurnerState &NukiWrapper::keyTurnerState()
{
return _keyTurnerState;

View File

@@ -48,16 +48,19 @@ private:
static void onConfigUpdateReceivedCallback(const char* value);
static void onKeypadCommandReceivedCallback(const char* command, const uint& id, const String& name, const String& code, const int& enabled);
static void onKeypadJsonCommandReceivedCallback(const char* value);
static void onTimeControlCommandReceivedCallback(const char* value);
static void gpioActionCallback(const GpioAction& action, const int& pin);
void onKeypadCommandReceived(const char* command, const uint& id, const String& name, const String& code, const int& enabled);
void onConfigUpdateReceived(const char* value);
void onKeypadJsonCommandReceived(const char* value);
void onTimeControlCommandReceived(const char* value);
void updateKeyTurnerState();
void updateBatteryState();
void updateConfig();
void updateAuthData();
void updateKeypad();
void updateTimeControl(bool retrieved);
void postponeBleWatchdog();
void updateGpioOutputs();
@@ -91,6 +94,7 @@ private:
bool _publishAuthData = false;
bool _clearAuthData = false;
std::vector<uint16_t> _keypadCodeIds;
std::vector<uint8_t> _timeControlIds;
NukiLock::KeyTurnerState _lastKeyTurnerState;
NukiLock::KeyTurnerState _keyTurnerState;
@@ -121,6 +125,7 @@ private:
unsigned long _nextLockStateUpdateTs = 0;
unsigned long _nextBatteryReportTs = 0;
unsigned long _nextConfigUpdateTs = 0;
unsigned long _nextTimeControlUpdateTs = 0;
unsigned long _nextKeypadUpdateTs = 0;
unsigned long _nextRssiTs = 0;
unsigned long _lastRssi = 0;

View File

@@ -49,6 +49,8 @@
#define preference_access_level "accLvl"
#define preference_keypad_info_enabled "kpInfoEnabled"
#define preference_keypad_control_enabled "kpCntrlEnabled"
#define preference_timecontrol_control_enabled "tcCntrlEnabled"
#define preference_timecontrol_info_enabled "tcInfoEnabled"
#define preference_publish_authdata "pubAuth"
#define preference_acl "aclLckOpn"
#define preference_conf_lock_basic_acl "confLckBasAcl"
@@ -82,9 +84,10 @@ private:
preference_ip_dhcp_enabled, preference_ip_address, preference_ip_subnet, preference_ip_gateway, preference_ip_dns_server,
preference_network_hardware, preference_network_wifi_fallback_disabled, preference_rssi_publish_interval,
preference_hostname, preference_network_timeout, preference_restart_on_disconnect,
preference_restart_ble_beacon_lost, preference_query_interval_lockstate,
preference_restart_ble_beacon_lost, preference_query_interval_lockstate,
preference_query_interval_configuration, preference_query_interval_battery, preference_query_interval_keypad,
preference_keypad_control_enabled, preference_keypad_info_enabled, preference_acl,
preference_timecontrol_control_enabled, preference_timecontrol_info_enabled,
preference_conf_lock_basic_acl, preference_conf_lock_advanced_acl, preference_conf_opener_basic_acl, preference_conf_opener_advanced_acl,
preference_access_level, preference_register_as_app, preference_command_nr_of_retries,
preference_command_retry_delay, preference_cred_user, preference_cred_password, preference_publish_authdata,
@@ -102,7 +105,7 @@ private:
{
preference_started_before, preference_mqtt_log_enabled, preference_check_updates, preference_lock_enabled, preference_opener_enabled, preference_opener_continuous_mode,
preference_restart_on_disconnect, preference_keypad_control_enabled, preference_keypad_info_enabled,
preference_register_as_app, preference_ip_dhcp_enabled,
preference_timecontrol_control_enabled, preference_timecontrol_info_enabled, preference_register_as_app, preference_ip_dhcp_enabled,
preference_publish_authdata, preference_has_mac_saved, preference_publish_debug_info, preference_network_wifi_fallback_disabled
};
@@ -135,56 +138,56 @@ private:
{
s.concat(description);
s.concat(": ");
s.concat(isRedacted(key) ? redact(preferences->getChar(key)) : String(preferences->getChar(key)));
s.concat(isRedacted(key) ? redact((const int32_t)preferences->getChar(key)) : String(preferences->getChar(key)));
s.concat("\n");
}
const void appendPreferenceUInt8(Preferences *preferences, String& s, const char* description, const char* key)
{
s.concat(description);
s.concat(": ");
s.concat(isRedacted(key) ? redact(preferences->getUChar(key)) : String(preferences->getUChar(key)));
s.concat(isRedacted(key) ? redact((const uint32_t)preferences->getUChar(key)) : String(preferences->getUChar(key)));
s.concat("\n");
}
const void appendPreferenceInt16(Preferences *preferences, String& s, const char* description, const char* key)
{
s.concat(description);
s.concat(": ");
s.concat(isRedacted(key) ? redact(preferences->getShort(key)) : String(preferences->getShort(key)));
s.concat(isRedacted(key) ? redact((const int32_t)preferences->getShort(key)) : String(preferences->getShort(key)));
s.concat("\n");
}
const void appendPreferenceUInt16(Preferences *preferences, String& s, const char* description, const char* key)
{
s.concat(description);
s.concat(": ");
s.concat(isRedacted(key) ? redact(preferences->getUShort(key)) : String(preferences->getUShort(key)));
s.concat(isRedacted(key) ? redact((const uint32_t)preferences->getUShort(key)) : String(preferences->getUShort(key)));
s.concat("\n");
}
const void appendPreferenceInt32(Preferences *preferences, String& s, const char* description, const char* key)
{
s.concat(description);
s.concat(": ");
s.concat(isRedacted(key) ? redact(preferences->getInt(key)) : String(preferences->getInt(key)));
s.concat(isRedacted(key) ? redact((const int32_t)preferences->getInt(key)) : String(preferences->getInt(key)));
s.concat("\n");
}
const void appendPreferenceUInt32(Preferences *preferences, String& s, const char* description, const char* key)
{
s.concat(description);
s.concat(": ");
s.concat(isRedacted(key) ? redact(preferences->getUInt(key)) : String(preferences->getUInt(key)));
s.concat(isRedacted(key) ? redact((const uint32_t)preferences->getUInt(key)) : String(preferences->getUInt(key)));
s.concat("\n");
}
const void appendPreferenceInt64(Preferences *preferences, String& s, const char* description, const char* key)
{
s.concat(description);
s.concat(": ");
s.concat(isRedacted(key) ? redact(preferences->getLong64(key)) : String(preferences->getLong64(key)));
s.concat(isRedacted(key) ? redact((const int64_t)preferences->getLong64(key)) : String(preferences->getLong64(key)));
s.concat("\n");
}
const void appendPreferenceUInt64(Preferences *preferences, String& s, const char* description, const char* key)
{
s.concat(description);
s.concat(": ");
s.concat(isRedacted(key) ? redact(preferences->getULong64(key)) : String(preferences->getULong64(key)));
s.concat(isRedacted(key) ? redact((const uint64_t)preferences->getULong64(key)) : String(preferences->getULong64(key)));
s.concat("\n");
}
const void appendPreferenceBool(Preferences *preferences, String& s, const char* description, const char* key)
@@ -198,7 +201,7 @@ private:
{
s.concat(description);
s.concat(": ");
s.concat(isRedacted(key) ? redact(preferences->getString(key)) : preferences->getString(key));
s.concat(isRedacted(key) ? redact((const String)preferences->getString(key)) : preferences->getString(key));
s.concat("\n");
}
@@ -258,4 +261,4 @@ public:
return s;
}
};
};

View File

@@ -15,7 +15,8 @@ Feel free to join us on Discord: https://discord.gg/feB9FnMY
## Supported devices
<b>Supported ESP32 devices:</b>
- All dual-core ESP32 models with WIFI and BLE which are supported by Arduino Core 2.0.15 should work, but builds are currently only provided for the ESP32 and not for the ESP32-S3 or ESP32-C3.
- All dual-core ESP32 models with WIFI and BLE which are supported by Arduino Core 2.0.15 should work. Tested builds are provided for the ESP32 and ESP32-S3.
- Single-core ESP32 models with WIFI and BLE which are supported by Arduino Core 2.0.15 might work. Untested builds are provided for the ESP32-C3 and ESP32-Solo1.
- The ESP32-S2 has no BLE and as such can't run Nuki Hub.
- The ESP32-C6 and ESP32-H2 are not supported by Arduino Core 2.0.15 as such can't run Nuki Hub (at this time).
@@ -46,8 +47,9 @@ Please go to "MQTT and Network Configuration" and select "Wi-Fi only" as the net
Flash the firmware to an ESP32. The easiest way to install is to use the web installer using a compatible browser like Chrome/Opera/Edge:<br>
https://technyon.github.io/nuki_hub/<br>
NOTE: Webflash is not available for the ESP32-Solo1<br>
<br>
Alternatively download the latest release from https://github.com/technyon/nuki_hub/releases<br>
Alternatively download the latest release for your ESP32 model from https://github.com/technyon/nuki_hub/releases<br>
Unpack the 7z archive and read the included readme.txt for installation instructions for either "Espressif Flash Download Tools" or "esptool".
## Initial setup (Network and MQTT)
@@ -150,6 +152,8 @@ In a browser navigate to the IP address assigned to the ESP32.
#### Nuki General Access Control
- Publish keypad codes information (Only available when a Keypad is detected): Enable to publish information about keypad codes through MQTT, see the "[Keypad control](#keypad-control-optional)" section of this README
- Add, modify and delete keypad codes (Only available when a Keypad is detected): Enable to allow configuration of keypad codes through MQTT, see the "[Keypad control](#keypad-control-optional)" section of this README
- Publish time control information: Enable to publish information about time control entries through MQTT, see the "Time control" section of this README
- Add, modify and delete time control entries: Enable to allow configuration of time control entries through MQTT, see the "Time control" section of this README
- Publish auth data: Enable to publish authorization data to the MQTT topic lock/log. Requires the Nuki security code / PIN to be set, see "Nuki Lock PIN / Nuki Opener PIN" below.
#### Nuki Lock/Opener Access Control
@@ -257,6 +261,10 @@ In a browser navigate to the IP address assigned to the ESP32.
- See the "[Keypad control](#keypad-control-optional)" section of this README.
### Time Control
- See the "Time control" section of this README.
### Info
- info/nukiHubVersion: Set to the current version number of the Nuki Hub firmware.
@@ -489,6 +497,30 @@ For example, to add a code:
- write 1 to enabled
- write "add" to action
## Time control using JSON (optional)
Time control entries can be added, updated and removed. This has to enabled first in the configuration portal. Check "Add, modify and delete time control entries" under "Access Level Configuration" and save the configuration.
Information about current time control entries is published as JSON data to the "timecontrol/json" MQTT topic.<br>
This needs to be enabled separately by checking "Publish time control entries information" under "Access Level Configuration" and saving the configuration.
To change Nuki Lock/Opener time control settings set the `timecontrol/actionJson` topic to a JSON formatted value containing the following nodes.
| Node | Delete | Add | Update | Usage | Possible values |
|------------------|----------|----------|----------|------------------------------------------------------------------------------------------|----------------------------------------------------------------|
| action | Required | Required | Required | The action to execute | "delete", "add", "update" |
| entryId | Required | Not used | Required | The entry ID of the existing entry to delete or update | Integer |
| enabled | Not used | Not used | Optional | Enable or disable the entry, enabled if not set | 1 = enabled, 0 = disabled |
| weekdays | Not used | Optional | Optional | Weekdays on which the chosen lock action should be exectued | Array of days: "mon", "tue", "wed", "thu" , "fri" "sat", "sun" |
| time | Not used | Required | Required | The time on which the chosen lock action should be executed | "HH:MM" |
| lockAction | Not used | Required | Required | The lock action that should be executed on the chosen weekdays at the chosen time | For the Nuki lock: "Unlock", "Lock", "Unlatch", "LockNgo", "LockNgoUnlatch", "FullLock". For the Nuki Opener: "ActivateRTO", "DeactivateRTO", "ElectricStrikeActuation", "ActivateCM", "DeactivateCM" |
Example usage:<br>
Examples:
- Delete: `{ "action": "delete", "entryId": "1234" }`
- Add: `{ "action": "add", "weekdays": [ "wed", "thu", "fri" ], "time": "08:00", "lockAction": "Unlock" }`
- Update: `{ "action": "update", "entryId": "1234", "enabled": "1", "weekdays": [ "mon", "tue", "sat", "sun" ], "time": "08:00", "lockAction": "Lock" }`
## GPIO lock control (optional)
The lock can be controlled via GPIO.<br>
@@ -567,6 +599,7 @@ Reported as working are:
- [M5Stack ATOM Lite](https://shop.m5stack.com/products/atom-lite-esp32-development-kit)
- ESP32-WROOM-32D (DEVKIT V4)
- ESP32-WROOM-32E
- ESP32-S3-WROOM-1
For more information check the related issue: https://github.com/technyon/nuki_hub/issues/39

View File

@@ -479,6 +479,16 @@ bool WebCfgServer::processArgs(String& message)
_preferences->putBool(preference_keypad_control_enabled, (value == "1"));
configChanged = true;
}
else if(key == "TCPUB")
{
_preferences->putBool(preference_timecontrol_info_enabled, (value == "1"));
configChanged = true;
}
else if(key == "TCENA")
{
_preferences->putBool(preference_timecontrol_control_enabled, (value == "1"));
configChanged = true;
}
else if(key == "PUBAUTH")
{
_preferences->putBool(preference_publish_authdata, (value == "1"));
@@ -1268,7 +1278,9 @@ void WebCfgServer::buildAccLvlHtml(String &response)
printCheckBox(response, "KPPUB", "Publish keypad codes information", _preferences->getBool(preference_keypad_info_enabled), "");
printCheckBox(response, "KPENA", "Add, modify and delete keypad codes", _preferences->getBool(preference_keypad_control_enabled), "");
}
printCheckBox(response, "PUBAUTH", "Publish authorisation log (may reduce battery life)", _preferences->getBool(preference_publish_authdata), "");
printCheckBox(response, "TCPUB", "Publish time control entries information", _preferences->getBool(preference_timecontrol_info_enabled));
printCheckBox(response, "TCENA", "Add, modify and delete time control entries", _preferences->getBool(preference_timecontrol_control_enabled));
printCheckBox(response, "PUBAUTH", "Publish authorisation log (may reduce battery life)", _preferences->getBool(preference_publish_authdata));
response.concat("</table><br>");
if(_nuki != nullptr)
{

View File

@@ -332,7 +332,7 @@ void setup() {
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failure to configure Ethernet using DHCP");
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;

View File

@@ -1,5 +1,5 @@
name=Ethernet
version=2.0.0
version=2.0.2
author=Various (see AUTHORS file for details)
maintainer=Arduino <info@arduino.cc>
sentence=Enables network connection (local and Internet) using the Arduino Ethernet Board or Shield.
@@ -7,4 +7,4 @@ paragraph=With this library you can use the Arduino Ethernet (shield or board) t
category=Communication
url=https://www.arduino.cc/en/Reference/Ethernet
architectures=*
includes=Ethernet.h
includes=Ethernet.h

View File

@@ -32,6 +32,7 @@ void DhcpClass::reset_DHCP_lease()
memset(_dhcpDhcpServerIp, 0, sizeof(_dhcpDhcpServerIp));
memset(_dhcpDnsServerIp, 0, sizeof(_dhcpDnsServerIp));
}
//return:0 on error, 1 if request is sent and response is received
int DhcpClass::request_DHCP_lease()
{
@@ -433,4 +434,4 @@ void DhcpClass::printByte(char * buf, uint8_t n )
char c = m - 16 * n;
*str-- = c < 10 ? c + '0' : c + 'A' - 10;
} while(n);
}
}

View File

@@ -87,14 +87,10 @@ void EthernetClass::begin(uint8_t *mac, IPAddress ip, IPAddress dns, IPAddress g
W5100.setIPAddress(&ip[0]);
W5100.setGatewayIp(&gateway[0]);
W5100.setSubnetMask(&subnet[0]);
#elif ARDUINO > 106 || TEENSYDUINO > 121
W5100.setIPAddress(ip._address.bytes);
W5100.setGatewayIp(gateway._address.bytes);
W5100.setSubnetMask(subnet._address.bytes);
#else
W5100.setIPAddress(ip._address);
W5100.setGatewayIp(gateway._address);
W5100.setSubnetMask(subnet._address);
W5100.setIPAddress(ip.raw_address());
W5100.setGatewayIp(gateway.raw_address());
W5100.setSubnetMask(subnet.raw_address());
#endif
SPI.endTransaction();
_dnsServerAddress = dns;
@@ -244,4 +240,4 @@ void EthernetClass::setRetransmissionCount(uint8_t num)
EthernetClass Ethernet;
EthernetClass Ethernet;

1
partitions.csv Normal file
View File

@@ -0,0 +1 @@
# Espressif ESP32 Partition Table
1 # Espressif ESP32 Partition Table # Name Type SubType Offset Size Flags nvs data nvs 0x9000 0x5000 otadata data ota 0xe000 0x2000 app0 app ota_0 0x10000 0x1E0000 app1 app ota_1 0x1F0000 0x1E0000 #spiffs data spiffs 0x3D0000 0x30000 spiffs data spiffs 0x3D0000 0x20000 coredump data coredump 0x3F0000 0x10000

64
platformio.ini Normal file
View File

@@ -0,0 +1,64 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[platformio]
default_envs = esp32dev
src_dir = .
[env]
platform = espressif32
framework = arduino
build_type = release
board_build.partitions = partitions.csv
build_flags =
-fexceptions
-DTLS_CA_MAX_SIZE=2200
-DTLS_CERT_MAX_SIZE=1500
-DTLS_KEY_MAX_SIZE=1800
-DESP_PLATFORM
-DESP32
-DARDUINO_ARCH_ESP32
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=0
; -DDEBUG_SENSE_NUKI
; -DDEBUG_NUKI_COMMAND
; -DDEBUG_NUKI_CONNECT
; -DDEBUG_NUKI_COMMUNICATION
; -DDEBUG_NUKI_HEX_DATA
; -DDEBUG_NUKI_READABLE_DATA
lib_deps =
https://github.com/technyon/nuki_ble.git
bertmelis/espMqttClient@1.6.0
bblanchon/ArduinoJson@7.0.4
monitor_speed = 115200
monitor_filters =
esp32_exception_decoder
time
build_src_filter =
-<*>
+<*.cpp>
+<*.h>
+<networkDevices>
[env:esp32dev]
board = esp32dev
[env:esp32-c3]
board = esp32-c3-devkitc-02
[env:esp32solo1]
platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.10.03/platform-espressif32-2023.10.03.zip
board = esp32-solo1
build_flags =
${env.build_flags}
-DFRAMEWORK_ARDUINO_SOLO1
[env:esp32-s3]
board = esp32-s3-devkitc-1

View File

@@ -10,6 +10,18 @@
{ "path": "nuki_hub.bin", "offset": 65536 },
{ "path": "nuki_hub.partitions.bin", "offset": 32768 }
]
},
{
"chipFamily": "ESP32-S3",
"parts": [
{ "path": "nuki_hub_esp32s3.bin", "offset": 0 },
]
},
{
"chipFamily": "ESP32-C3",
"parts": [
{ "path": "nuki_hub_esp32c3.bin", "offset": 0 },
]
}
]
}

Binary file not shown.

Binary file not shown.