Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
iranl committed Apr 26, 2024
1 parent c9710ef commit 47fc663
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 74 deletions.
29 changes: 14 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,45 @@ jobs:
run: pip install --upgrade platformio
- name: Install ESPTool
run: pip install --upgrade esptool
- name: Build PlatformIO Project esp32dev
- name: Build PlatformIO Project esp32
run: |
pio run --environment esp32dev
mkdir -p release/esp32dev
cp .pio/build/esp32dev/firmware.bin release/esp32dev/nuki_hub.bin
cp .pio/build/esp32dev/firmware.bin release/esp32dev/nuki_hub_esp32.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
esptool.py --chip esp32 merge_bin -o release/esp32dev/webflash_nuki_hub_esp32.bin --flash_mode dio --flash_freq keep --flash_size keep 0x1000 release/esp32dev/bootloader.bin 0x10000 release/esp32dev/nuki_hub_esp32.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_esp32.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/firmware.bin release/esp32-s3/nuki_hub_esp32s3.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
esptool.py --chip esp32s3 merge_bin -o release/esp32-s3/webflash_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_esp32s3.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_esp32s3.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/firmware.bin release/esp32-c3/nuki_hub_esp32c3.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
esptool.py --chip esp32c3 merge_bin -o release/esp32-c3/webflash_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_esp32c3.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_esp32c3.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/firmware.bin release/esp32solo1/nuki_hub_esp32solo1.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
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_esp32solo1.bin 0x8000 nuki_hub.partitions.bin" > release/esp32solo1/flash.sh
- name: Upload Artifact esp32
uses: actions/upload-artifact@v4
with:
name: esp32dev-assets
name: esp32-assets
path: release/esp32dev
- name: Upload Artifact esp32-s3
uses: actions/upload-artifact@v4
Expand Down
21 changes: 20 additions & 1 deletion Config.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
#pragma once

#include "sdkconfig.h"

#define NUKI_HUB_VERSION "8.34-pre-4"

#define GITHUB_LATEST_RELEASE_URL "https://github.com/technyon/nuki_hub/releases/latest"
#define GITHUB_LATEST_RELEASE_API_URL "https://api.github.com/repos/technyon/nuki_hub/releases/latest"
#define GITHUB_LATEST_RELEASE_BINARY_URL "https://github.com/technyon/nuki_hub/raw/master/webflash/nuki_hub.bin"

#if defined(CONFIG_IDF_TARGET_ESP32C3)
<some Linux code here>
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
<some Windows code here>
#endif

#if defined(CONFIG_IDF_TARGET_ESP32C3)
#define GITHUB_LATEST_RELEASE_BINARY_URL "https://github.com/technyon/nuki_hub/raw/master/ota/nuki_hub_esp32c3.bin"
#elif defined(CONFIG_IDF_TARGET_ESP32S3)
#define GITHUB_LATEST_RELEASE_BINARY_URL "https://github.com/technyon/nuki_hub/raw/master/ota/nuki_hub_esp32s3.bin"
#else
#if defined(FRAMEWORK_ARDUINO_SOLO1)
#define GITHUB_LATEST_RELEASE_BINARY_URL "https://github.com/technyon/nuki_hub/raw/master/ota/nuki_hub_esp32solo1.bin"
#else
#define GITHUB_LATEST_RELEASE_BINARY_URL "https://github.com/technyon/nuki_hub/raw/master/ota/nuki_hub_esp32.bin"
#endif
#endif

#define MQTT_QOS_LEVEL 1
#define MQTT_CLEAN_SESSIONS false
Expand Down
52 changes: 34 additions & 18 deletions NukiOpenerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ void NukiOpenerWrapper::updateKeypad()
{
std::list<NukiLock::KeypadEntry> entries;
_nukiOpener.getKeypadEntries(&entries);

Log->print(F("Opener keypad codes: "));
Log->println(entries.size());

Expand Down Expand Up @@ -552,7 +552,7 @@ void NukiOpenerWrapper::updateTimeControl(bool retrieved)
{
std::list<NukiOpener::TimeControlEntry> timeControlEntries;
_nukiOpener.getTimeControlEntries(&timeControlEntries);

Log->print(F("Opener time control entries: "));
Log->println(timeControlEntries.size());

Expand Down Expand Up @@ -593,14 +593,18 @@ LockActionResult NukiOpenerWrapper::onLockActionReceivedCallback(const char *val
{
NukiOpener::LockAction action;

if(strlen(value) > 0)
if(value)
{
action = nukiOpenerInst->lockActionToEnum(value);

if((int)action == 0xff)
if(strlen(value) > 0)
{
return LockActionResult::UnknownAction;
action = nukiOpenerInst->lockActionToEnum(value);

if((int)action == 0xff)
{
return LockActionResult::UnknownAction;
}
}
else return LockActionResult::UnknownAction;
}
else return LockActionResult::UnknownAction;

Expand Down Expand Up @@ -803,7 +807,7 @@ void NukiOpenerWrapper::onConfigUpdateReceived(const char *value)
if(json[basicKeys[i]])
{
const char *jsonchar = json[basicKeys[i]].as<const char*>();

if(strlen(jsonchar) == 0)
{
jsonResult[basicKeys[i]] = "noValueSet";
Expand Down Expand Up @@ -984,7 +988,7 @@ void NukiOpenerWrapper::onConfigUpdateReceived(const char *value)
if(json[advancedKeys[i]])
{
const char *jsonchar = json[advancedKeys[i]].as<const char*>();

if(strlen(jsonchar) == 0)
{
jsonResult[advancedKeys[i]] = "noValueSet";
Expand Down Expand Up @@ -1420,7 +1424,7 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
_network->publishKeypadJsonCommandResult("configNotReady");
return;
}

if(!_keypadEnabled)
{
_network->publishKeypadJsonCommandResult("keypadDisabled");
Expand Down Expand Up @@ -1503,7 +1507,7 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
unsigned int allowedUntilTimeAr[2];
uint8_t allowedWeekdaysInt = 0;

if(timeLimited == 1 && enabled != 0)
if(timeLimited == 1)
{
if(allowedFrom)
{
Expand Down Expand Up @@ -1655,6 +1659,18 @@ void NukiOpenerWrapper::onKeypadJsonCommandReceived(const char *value)
}
else if (strcmp(action, "update") == 0)
{
if(!codeId)
{
_network->publishKeypadJsonCommandResult("noCodeIdSet");
return;
}

if(!idExists)
{
_network->publishKeypadJsonCommandResult("noExistingCodeIdSet");
return;
}

NukiOpener::UpdatedKeypadEntry entry;
memset(&entry, 0, sizeof(entry));
entry.codeId = codeId;
Expand Down Expand Up @@ -1759,9 +1775,8 @@ void NukiOpenerWrapper::onTimeControlCommandReceived(const char *value)
const char *lockAct = json["lockAction"].as<const char*>();
NukiOpener::LockAction timeControlLockAction;

if(strlen(lockAct) > 0)
if(lockAct)
{

timeControlLockAction = nukiOpenerInst->lockActionToEnum(lockAct);

if((int)timeControlLockAction == 0xff)
Expand All @@ -1770,11 +1785,6 @@ void NukiOpenerWrapper::onTimeControlCommandReceived(const char *value)
return;
}
}
else
{
_network->publishTimeControlCommandResult("invalidLockAction");
return;
}

if(action)
{
Expand Down Expand Up @@ -1859,6 +1869,12 @@ void NukiOpenerWrapper::onTimeControlCommandReceived(const char *value)
}
else if (strcmp(action, "update") == 0)
{
if(!idExists)
{
_network->publishTimeControlCommandResult("noExistingEntryIdSet");
return;
}

NukiOpener::TimeControlEntry entry;
memset(&entry, 0, sizeof(entry));
entry.entryId = entryId;
Expand Down
46 changes: 31 additions & 15 deletions NukiWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,17 +575,21 @@ LockActionResult NukiWrapper::onLockActionReceivedCallback(const char *value)
{
NukiLock::LockAction action;

if(strlen(value) > 0)
if(value)
{
action = nukiInst->lockActionToEnum(value);

if((int)action == 0xff)
if(strlen(value) > 0)
{
return LockActionResult::UnknownAction;
action = nukiInst->lockActionToEnum(value);

if((int)action == 0xff)
{
return LockActionResult::UnknownAction;
}
}
else return LockActionResult::UnknownAction;
}
else return LockActionResult::UnknownAction;

nukiLockPreferences = new Preferences();
nukiLockPreferences->begin("nukihub", true);
uint32_t aclPrefs[17];
Expand Down Expand Up @@ -1490,7 +1494,7 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
unsigned int allowedUntilTimeAr[2];
uint8_t allowedWeekdaysInt = 0;

if(timeLimited == 1 && enabled != 0)
if(timeLimited == 1)
{
if(allowedFrom)
{
Expand Down Expand Up @@ -1642,6 +1646,18 @@ void NukiWrapper::onKeypadJsonCommandReceived(const char *value)
}
else if (strcmp(action, "update") == 0)
{
if(!codeId)
{
_network->publishKeypadJsonCommandResult("noCodeIdSet");
return;
}

if(!idExists)
{
_network->publishKeypadJsonCommandResult("noExistingCodeIdSet");
return;
}

NukiLock::UpdatedKeypadEntry entry;
memset(&entry, 0, sizeof(entry));
entry.codeId = codeId;
Expand Down Expand Up @@ -1746,9 +1762,8 @@ void NukiWrapper::onTimeControlCommandReceived(const char *value)
const char *lockAct = json["lockAction"].as<const char*>();
NukiLock::LockAction timeControlLockAction;

if(strlen(lockAct) > 0)
if(lockAct)
{

timeControlLockAction = nukiInst->lockActionToEnum(lockAct);

if((int)timeControlLockAction == 0xff)
Expand All @@ -1757,12 +1772,7 @@ void NukiWrapper::onTimeControlCommandReceived(const char *value)
return;
}
}
else
{
_network->publishTimeControlCommandResult("invalidLockAction");
return;
}


if(action)
{
bool idExists = false;
Expand Down Expand Up @@ -1846,6 +1856,12 @@ void NukiWrapper::onTimeControlCommandReceived(const char *value)
}
else if (strcmp(action, "update") == 0)
{
if(!idExists)
{
_network->publishTimeControlCommandResult("noExistingEntryIdSet");
return;
}

NukiLock::TimeControlEntry entry;
memset(&entry, 0, sizeof(entry));
entry.entryId = entryId;
Expand Down
Loading

0 comments on commit 47fc663

Please sign in to comment.