add astylerc and apply code formatting
This commit is contained in:
465
src/Gpio.cpp
465
src/Gpio.cpp
@@ -12,7 +12,7 @@
|
||||
Gpio* Gpio::_inst = nullptr;
|
||||
|
||||
Gpio::Gpio(Preferences* preferences)
|
||||
: _preferences(preferences)
|
||||
: _preferences(preferences)
|
||||
{
|
||||
_inst = this;
|
||||
loadPinConfiguration();
|
||||
@@ -80,35 +80,35 @@ void Gpio::onTimer()
|
||||
{
|
||||
switch(entry.role)
|
||||
{
|
||||
case PinRole::InputLock:
|
||||
case PinRole::InputUnlock:
|
||||
case PinRole::InputUnlatch:
|
||||
case PinRole::InputLockNgo:
|
||||
case PinRole::InputLockNgoUnlatch:
|
||||
case PinRole::InputElectricStrikeActuation:
|
||||
case PinRole::InputActivateRTO:
|
||||
case PinRole::InputActivateCM:
|
||||
case PinRole::InputDeactivateRtoCm:
|
||||
case PinRole::InputDeactivateRTO:
|
||||
case PinRole::InputDeactivateCM:
|
||||
case PinRole::GeneralInputPullDown:
|
||||
case PinRole::GeneralInputPullUp:
|
||||
if(isTriggered(entry))
|
||||
{
|
||||
_inst->notify(getGpioAction(entry.role), entry.pin);
|
||||
}
|
||||
break;
|
||||
case PinRole::OutputHighLocked:
|
||||
case PinRole::OutputHighUnlocked:
|
||||
case PinRole::OutputHighMotorBlocked:
|
||||
case PinRole::OutputHighRtoActive:
|
||||
case PinRole::OutputHighCmActive:
|
||||
case PinRole::OutputHighRtoOrCmActive:
|
||||
case PinRole::GeneralOutput:
|
||||
case PinRole::Ethernet:
|
||||
// ignore. This case should not occur since pins are configured as output
|
||||
default:
|
||||
break;
|
||||
case PinRole::InputLock:
|
||||
case PinRole::InputUnlock:
|
||||
case PinRole::InputUnlatch:
|
||||
case PinRole::InputLockNgo:
|
||||
case PinRole::InputLockNgoUnlatch:
|
||||
case PinRole::InputElectricStrikeActuation:
|
||||
case PinRole::InputActivateRTO:
|
||||
case PinRole::InputActivateCM:
|
||||
case PinRole::InputDeactivateRtoCm:
|
||||
case PinRole::InputDeactivateRTO:
|
||||
case PinRole::InputDeactivateCM:
|
||||
case PinRole::GeneralInputPullDown:
|
||||
case PinRole::GeneralInputPullUp:
|
||||
if(isTriggered(entry))
|
||||
{
|
||||
_inst->notify(getGpioAction(entry.role), entry.pin);
|
||||
}
|
||||
break;
|
||||
case PinRole::OutputHighLocked:
|
||||
case PinRole::OutputHighUnlocked:
|
||||
case PinRole::OutputHighMotorBlocked:
|
||||
case PinRole::OutputHighRtoActive:
|
||||
case PinRole::OutputHighCmActive:
|
||||
case PinRole::OutputHighRtoOrCmActive:
|
||||
case PinRole::GeneralOutput:
|
||||
case PinRole::Ethernet:
|
||||
// ignore. This case should not occur since pins are configured as output
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,37 +139,37 @@ void Gpio::init()
|
||||
|
||||
switch(entry.role)
|
||||
{
|
||||
case PinRole::InputLock:
|
||||
case PinRole::InputUnlock:
|
||||
case PinRole::InputUnlatch:
|
||||
case PinRole::InputLockNgo:
|
||||
case PinRole::InputLockNgoUnlatch:
|
||||
case PinRole::InputElectricStrikeActuation:
|
||||
case PinRole::InputActivateRTO:
|
||||
case PinRole::InputActivateCM:
|
||||
case PinRole::InputDeactivateRtoCm:
|
||||
case PinRole::InputDeactivateRTO:
|
||||
case PinRole::InputDeactivateCM:
|
||||
case PinRole::GeneralInputPullUp:
|
||||
pinMode(entry.pin, INPUT_PULLUP);
|
||||
hasInputPin = true;
|
||||
break;
|
||||
case PinRole::GeneralInputPullDown:
|
||||
pinMode(entry.pin, INPUT_PULLDOWN);
|
||||
hasInputPin = true;
|
||||
break;
|
||||
case PinRole::OutputHighLocked:
|
||||
case PinRole::OutputHighUnlocked:
|
||||
case PinRole::OutputHighMotorBlocked:
|
||||
case PinRole::OutputHighRtoActive:
|
||||
case PinRole::OutputHighCmActive:
|
||||
case PinRole::OutputHighRtoOrCmActive:
|
||||
case PinRole::GeneralOutput:
|
||||
pinMode(entry.pin, OUTPUT);
|
||||
break;
|
||||
case PinRole::Ethernet:
|
||||
default:
|
||||
break;
|
||||
case PinRole::InputLock:
|
||||
case PinRole::InputUnlock:
|
||||
case PinRole::InputUnlatch:
|
||||
case PinRole::InputLockNgo:
|
||||
case PinRole::InputLockNgoUnlatch:
|
||||
case PinRole::InputElectricStrikeActuation:
|
||||
case PinRole::InputActivateRTO:
|
||||
case PinRole::InputActivateCM:
|
||||
case PinRole::InputDeactivateRtoCm:
|
||||
case PinRole::InputDeactivateRTO:
|
||||
case PinRole::InputDeactivateCM:
|
||||
case PinRole::GeneralInputPullUp:
|
||||
pinMode(entry.pin, INPUT_PULLUP);
|
||||
hasInputPin = true;
|
||||
break;
|
||||
case PinRole::GeneralInputPullDown:
|
||||
pinMode(entry.pin, INPUT_PULLDOWN);
|
||||
hasInputPin = true;
|
||||
break;
|
||||
case PinRole::OutputHighLocked:
|
||||
case PinRole::OutputHighUnlocked:
|
||||
case PinRole::OutputHighMotorBlocked:
|
||||
case PinRole::OutputHighRtoActive:
|
||||
case PinRole::OutputHighCmActive:
|
||||
case PinRole::OutputHighRtoOrCmActive:
|
||||
case PinRole::GeneralOutput:
|
||||
pinMode(entry.pin, OUTPUT);
|
||||
break;
|
||||
case PinRole::Ethernet:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,7 +221,10 @@ void Gpio::loadPinConfiguration()
|
||||
|
||||
if(std::find(disabledPins.begin(), disabledPins.end(), entry.pin) == disabledPins.end())
|
||||
{
|
||||
if(entry.role == PinRole::Ethernet) entry.role = PinRole::Disabled;
|
||||
if(entry.role == PinRole::Ethernet)
|
||||
{
|
||||
entry.role = PinRole::Disabled;
|
||||
}
|
||||
entry.role = (PinRole) serialized[(i * 2 + 1)];
|
||||
Log->println("Not found in Ethernet disabled pins");
|
||||
Log->print(F("Role: "));
|
||||
@@ -234,7 +237,10 @@ void Gpio::loadPinConfiguration()
|
||||
Log->print(F("Role: "));
|
||||
Log->println(getRoleDescription(entry.role));
|
||||
}
|
||||
if(entry.role != PinRole::Disabled) _pinConfiguration.push_back(entry);
|
||||
if(entry.role != PinRole::Disabled)
|
||||
{
|
||||
_pinConfiguration.push_back(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,90 +250,94 @@ const std::vector<int> Gpio::getDisabledPins() const
|
||||
|
||||
switch(_preferences->getInt(preference_network_hardware, 0))
|
||||
{
|
||||
case 2:
|
||||
disabledPins.push_back(ETH_PHY_CS_GENERIC_W5500);
|
||||
disabledPins.push_back(ETH_PHY_IRQ_GENERIC_W5500);
|
||||
disabledPins.push_back(ETH_PHY_RST_GENERIC_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_SCK_GENERIC_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MISO_GENERIC_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MOSI_GENERIC_W5500);
|
||||
break;
|
||||
case 3:
|
||||
disabledPins.push_back(ETH_PHY_CS_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_IRQ_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_RST_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_SCK_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MISO_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MOSI_M5_W5500);
|
||||
break;
|
||||
case 10:
|
||||
disabledPins.push_back(ETH_PHY_CS_M5_W5500_S3);
|
||||
disabledPins.push_back(ETH_PHY_IRQ_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_RST_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_SCK_M5_W5500_S3);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MISO_M5_W5500_S3);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MOSI_M5_W5500_S3);
|
||||
break;
|
||||
case 9:
|
||||
disabledPins.push_back(ETH_PHY_CS_ETH01EVO);
|
||||
disabledPins.push_back(ETH_PHY_IRQ_ETH01EVO);
|
||||
disabledPins.push_back(ETH_PHY_RST_ETH01EVO);
|
||||
disabledPins.push_back(ETH_PHY_SPI_SCK_ETH01EVO);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MISO_ETH01EVO);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MOSI_ETH01EVO);
|
||||
break;
|
||||
case 6:
|
||||
disabledPins.push_back(ETH_PHY_CS_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_IRQ_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_RST_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_SCK_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MISO_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MOSI_M5_W5500);
|
||||
break;
|
||||
case 11:
|
||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_cs, -1));
|
||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_irq, -1));
|
||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_rst, -1));
|
||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_sck, -1));
|
||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_miso, -1));
|
||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_mosi, -1));
|
||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_pwr, -1));
|
||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_mdc, -1));
|
||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_mdio, -1));
|
||||
break;
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32)
|
||||
case 4:
|
||||
disabledPins.push_back(12);
|
||||
disabledPins.push_back(ETH_RESET_PIN_LAN8720);
|
||||
disabledPins.push_back(ETH_PHY_MDC_LAN8720);
|
||||
disabledPins.push_back(ETH_PHY_MDIO_LAN8720);
|
||||
break;
|
||||
case 5:
|
||||
disabledPins.push_back(16);
|
||||
disabledPins.push_back(ETH_RESET_PIN_LAN8720);
|
||||
disabledPins.push_back(ETH_PHY_MDC_LAN8720);
|
||||
disabledPins.push_back(ETH_PHY_MDIO_LAN8720);
|
||||
break;
|
||||
case 8:
|
||||
disabledPins.push_back(5);
|
||||
disabledPins.push_back(ETH_RESET_PIN_LAN8720);
|
||||
disabledPins.push_back(ETH_PHY_MDC_LAN8720);
|
||||
disabledPins.push_back(ETH_PHY_MDIO_LAN8720);
|
||||
break;
|
||||
case 7:
|
||||
disabledPins.push_back(-1);
|
||||
disabledPins.push_back(ETH_RESET_PIN_LAN8720);
|
||||
disabledPins.push_back(ETH_PHY_MDC_LAN8720);
|
||||
disabledPins.push_back(ETH_PHY_MDIO_LAN8720);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
case 2:
|
||||
disabledPins.push_back(ETH_PHY_CS_GENERIC_W5500);
|
||||
disabledPins.push_back(ETH_PHY_IRQ_GENERIC_W5500);
|
||||
disabledPins.push_back(ETH_PHY_RST_GENERIC_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_SCK_GENERIC_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MISO_GENERIC_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MOSI_GENERIC_W5500);
|
||||
break;
|
||||
case 3:
|
||||
disabledPins.push_back(ETH_PHY_CS_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_IRQ_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_RST_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_SCK_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MISO_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MOSI_M5_W5500);
|
||||
break;
|
||||
case 10:
|
||||
disabledPins.push_back(ETH_PHY_CS_M5_W5500_S3);
|
||||
disabledPins.push_back(ETH_PHY_IRQ_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_RST_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_SCK_M5_W5500_S3);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MISO_M5_W5500_S3);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MOSI_M5_W5500_S3);
|
||||
break;
|
||||
case 9:
|
||||
disabledPins.push_back(ETH_PHY_CS_ETH01EVO);
|
||||
disabledPins.push_back(ETH_PHY_IRQ_ETH01EVO);
|
||||
disabledPins.push_back(ETH_PHY_RST_ETH01EVO);
|
||||
disabledPins.push_back(ETH_PHY_SPI_SCK_ETH01EVO);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MISO_ETH01EVO);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MOSI_ETH01EVO);
|
||||
break;
|
||||
case 6:
|
||||
disabledPins.push_back(ETH_PHY_CS_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_IRQ_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_RST_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_SCK_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MISO_M5_W5500);
|
||||
disabledPins.push_back(ETH_PHY_SPI_MOSI_M5_W5500);
|
||||
break;
|
||||
case 11:
|
||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_cs, -1));
|
||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_irq, -1));
|
||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_rst, -1));
|
||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_sck, -1));
|
||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_miso, -1));
|
||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_mosi, -1));
|
||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_pwr, -1));
|
||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_mdc, -1));
|
||||
disabledPins.push_back(_preferences->getInt(preference_network_custom_mdio, -1));
|
||||
break;
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32)
|
||||
case 4:
|
||||
disabledPins.push_back(12);
|
||||
disabledPins.push_back(ETH_RESET_PIN_LAN8720);
|
||||
disabledPins.push_back(ETH_PHY_MDC_LAN8720);
|
||||
disabledPins.push_back(ETH_PHY_MDIO_LAN8720);
|
||||
break;
|
||||
case 5:
|
||||
disabledPins.push_back(16);
|
||||
disabledPins.push_back(ETH_RESET_PIN_LAN8720);
|
||||
disabledPins.push_back(ETH_PHY_MDC_LAN8720);
|
||||
disabledPins.push_back(ETH_PHY_MDIO_LAN8720);
|
||||
break;
|
||||
case 8:
|
||||
disabledPins.push_back(5);
|
||||
disabledPins.push_back(ETH_RESET_PIN_LAN8720);
|
||||
disabledPins.push_back(ETH_PHY_MDC_LAN8720);
|
||||
disabledPins.push_back(ETH_PHY_MDIO_LAN8720);
|
||||
break;
|
||||
case 7:
|
||||
disabledPins.push_back(-1);
|
||||
disabledPins.push_back(ETH_RESET_PIN_LAN8720);
|
||||
disabledPins.push_back(ETH_PHY_MDC_LAN8720);
|
||||
disabledPins.push_back(ETH_PHY_MDIO_LAN8720);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Log->print(F("GPIO Ethernet disabled pins:"));
|
||||
for_each_n(disabledPins.begin(), disabledPins.size(),
|
||||
[](int x) { Log->print(" "); Log->print(x); });
|
||||
[](int x)
|
||||
{
|
||||
Log->print(" ");
|
||||
Log->print(x);
|
||||
});
|
||||
Log->println();
|
||||
return disabledPins;
|
||||
}
|
||||
@@ -393,52 +403,52 @@ String Gpio::getRoleDescription(const PinRole& role) const
|
||||
{
|
||||
switch(role)
|
||||
{
|
||||
case PinRole::Disabled:
|
||||
return "Disabled";
|
||||
case PinRole::InputLock:
|
||||
return "Input: Lock";
|
||||
case PinRole::InputUnlock:
|
||||
return "Input: Unlock";
|
||||
case PinRole::InputUnlatch:
|
||||
return "Input: Unlatch";
|
||||
case PinRole::InputLockNgo:
|
||||
return "Input: Lock n Go";
|
||||
case PinRole::InputLockNgoUnlatch:
|
||||
return "Input: Lock n Go and unlatch";
|
||||
case PinRole::InputElectricStrikeActuation:
|
||||
return "Input: Electric strike actuation";
|
||||
case PinRole::InputActivateRTO:
|
||||
return "Input: Activate RTO";
|
||||
case PinRole::InputActivateCM:
|
||||
return "Input: Activate CM";
|
||||
case PinRole::InputDeactivateRtoCm:
|
||||
return "Input: Deactivate RTO/CM";
|
||||
case PinRole::InputDeactivateRTO:
|
||||
return "Input: Deactivate RTO";
|
||||
case PinRole::InputDeactivateCM:
|
||||
return "Input: Deactivate CM";
|
||||
case PinRole::OutputHighLocked:
|
||||
return "Output: High when locked";
|
||||
case PinRole::OutputHighUnlocked:
|
||||
return "Output: High when unlocked";
|
||||
case PinRole::OutputHighMotorBlocked:
|
||||
return "Output: High when motor blocked";
|
||||
case PinRole::OutputHighRtoActive:
|
||||
return "Output: High when RTO active";
|
||||
case PinRole::OutputHighCmActive:
|
||||
return "Output: High when CM active";
|
||||
case PinRole::OutputHighRtoOrCmActive:
|
||||
return "Output: High when RTO or CM active";
|
||||
case PinRole::GeneralOutput:
|
||||
return "General output";
|
||||
case PinRole::GeneralInputPullDown:
|
||||
return "General input (Pull-down)";
|
||||
case PinRole::GeneralInputPullUp:
|
||||
return "General input (Pull-up)";
|
||||
case PinRole::Ethernet:
|
||||
return "Ethernet";
|
||||
default:
|
||||
return "Unknown";
|
||||
case PinRole::Disabled:
|
||||
return "Disabled";
|
||||
case PinRole::InputLock:
|
||||
return "Input: Lock";
|
||||
case PinRole::InputUnlock:
|
||||
return "Input: Unlock";
|
||||
case PinRole::InputUnlatch:
|
||||
return "Input: Unlatch";
|
||||
case PinRole::InputLockNgo:
|
||||
return "Input: Lock n Go";
|
||||
case PinRole::InputLockNgoUnlatch:
|
||||
return "Input: Lock n Go and unlatch";
|
||||
case PinRole::InputElectricStrikeActuation:
|
||||
return "Input: Electric strike actuation";
|
||||
case PinRole::InputActivateRTO:
|
||||
return "Input: Activate RTO";
|
||||
case PinRole::InputActivateCM:
|
||||
return "Input: Activate CM";
|
||||
case PinRole::InputDeactivateRtoCm:
|
||||
return "Input: Deactivate RTO/CM";
|
||||
case PinRole::InputDeactivateRTO:
|
||||
return "Input: Deactivate RTO";
|
||||
case PinRole::InputDeactivateCM:
|
||||
return "Input: Deactivate CM";
|
||||
case PinRole::OutputHighLocked:
|
||||
return "Output: High when locked";
|
||||
case PinRole::OutputHighUnlocked:
|
||||
return "Output: High when unlocked";
|
||||
case PinRole::OutputHighMotorBlocked:
|
||||
return "Output: High when motor blocked";
|
||||
case PinRole::OutputHighRtoActive:
|
||||
return "Output: High when RTO active";
|
||||
case PinRole::OutputHighCmActive:
|
||||
return "Output: High when CM active";
|
||||
case PinRole::OutputHighRtoOrCmActive:
|
||||
return "Output: High when RTO or CM active";
|
||||
case PinRole::GeneralOutput:
|
||||
return "General output";
|
||||
case PinRole::GeneralInputPullDown:
|
||||
return "General input (Pull-down)";
|
||||
case PinRole::GeneralInputPullUp:
|
||||
return "General input (Pull-up)";
|
||||
case PinRole::Ethernet:
|
||||
return "Ethernet";
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -447,46 +457,47 @@ GpioAction Gpio::getGpioAction(const PinRole &role) const
|
||||
{
|
||||
switch(role)
|
||||
{
|
||||
case PinRole::Disabled:
|
||||
return GpioAction::None;
|
||||
case PinRole::InputLock:
|
||||
return GpioAction::Lock;
|
||||
case PinRole::InputUnlock:
|
||||
return GpioAction::Unlock;
|
||||
case PinRole::InputUnlatch:
|
||||
return GpioAction::Unlatch;
|
||||
case PinRole::InputLockNgo:
|
||||
return GpioAction::LockNgo;
|
||||
case PinRole::InputLockNgoUnlatch:
|
||||
return GpioAction::LockNgoUnlatch;
|
||||
case PinRole::InputElectricStrikeActuation:
|
||||
return GpioAction::ElectricStrikeActuation;
|
||||
case PinRole::InputActivateRTO:
|
||||
return GpioAction::ActivateRTO;
|
||||
case PinRole::InputActivateCM:
|
||||
return GpioAction::ActivateCM;
|
||||
case PinRole::InputDeactivateRtoCm:
|
||||
return GpioAction::DeactivateRtoCm;
|
||||
case PinRole::InputDeactivateRTO:
|
||||
return GpioAction::DeactivateRTO;
|
||||
case PinRole::InputDeactivateCM:
|
||||
return GpioAction::DeactivateCM;
|
||||
case PinRole::Disabled:
|
||||
return GpioAction::None;
|
||||
case PinRole::InputLock:
|
||||
return GpioAction::Lock;
|
||||
case PinRole::InputUnlock:
|
||||
return GpioAction::Unlock;
|
||||
case PinRole::InputUnlatch:
|
||||
return GpioAction::Unlatch;
|
||||
case PinRole::InputLockNgo:
|
||||
return GpioAction::LockNgo;
|
||||
case PinRole::InputLockNgoUnlatch:
|
||||
return GpioAction::LockNgoUnlatch;
|
||||
case PinRole::InputElectricStrikeActuation:
|
||||
return GpioAction::ElectricStrikeActuation;
|
||||
case PinRole::InputActivateRTO:
|
||||
return GpioAction::ActivateRTO;
|
||||
case PinRole::InputActivateCM:
|
||||
return GpioAction::ActivateCM;
|
||||
case PinRole::InputDeactivateRtoCm:
|
||||
return GpioAction::DeactivateRtoCm;
|
||||
case PinRole::InputDeactivateRTO:
|
||||
return GpioAction::DeactivateRTO;
|
||||
case PinRole::InputDeactivateCM:
|
||||
return GpioAction::DeactivateCM;
|
||||
|
||||
case PinRole::GeneralInputPullDown:
|
||||
case PinRole::GeneralInputPullUp:
|
||||
return GpioAction::GeneralInput;
|
||||
case PinRole::GeneralInputPullDown:
|
||||
case PinRole::GeneralInputPullUp:
|
||||
return GpioAction::GeneralInput;
|
||||
|
||||
case PinRole::GeneralOutput:
|
||||
case PinRole::Ethernet:
|
||||
case PinRole::OutputHighLocked:
|
||||
case PinRole::OutputHighUnlocked:
|
||||
case PinRole::OutputHighMotorBlocked:
|
||||
case PinRole::OutputHighRtoActive:
|
||||
case PinRole::OutputHighCmActive:
|
||||
case PinRole::OutputHighRtoOrCmActive:
|
||||
default:
|
||||
return GpioAction::None;
|
||||
}}
|
||||
case PinRole::GeneralOutput:
|
||||
case PinRole::Ethernet:
|
||||
case PinRole::OutputHighLocked:
|
||||
case PinRole::OutputHighUnlocked:
|
||||
case PinRole::OutputHighMotorBlocked:
|
||||
case PinRole::OutputHighRtoActive:
|
||||
case PinRole::OutputHighCmActive:
|
||||
case PinRole::OutputHighRtoOrCmActive:
|
||||
default:
|
||||
return GpioAction::None;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Gpio::getConfigurationText(String& text, const std::vector<PinEntry>& pinConfiguration, const String& linebreak) const
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
#include "PreferencesKeys.h"
|
||||
|
||||
NukiDeviceId::NukiDeviceId(Preferences* preferences, const std::string& preferencesId)
|
||||
: _preferences(preferences),
|
||||
_preferencesId(preferencesId)
|
||||
: _preferences(preferences),
|
||||
_preferencesId(preferencesId)
|
||||
{
|
||||
_deviceId = _preferences->getUInt(_preferencesId.c_str(), 0);
|
||||
|
||||
|
||||
1360
src/NukiNetwork.cpp
1360
src/NukiNetwork.cpp
File diff suppressed because it is too large
Load Diff
@@ -15,11 +15,11 @@ extern const uint8_t x509_crt_imported_bundle_bin_start[] asm("_binary_x509_crt_
|
||||
extern const uint8_t x509_crt_imported_bundle_bin_end[] asm("_binary_x509_crt_bundle_end");
|
||||
|
||||
NukiNetworkLock::NukiNetworkLock(NukiNetwork* network, NukiOfficial* nukiOfficial, Preferences* preferences, char* buffer, size_t bufferSize)
|
||||
: _network(network),
|
||||
_nukiOfficial(nukiOfficial),
|
||||
_preferences(preferences),
|
||||
_buffer(buffer),
|
||||
_bufferSize(bufferSize)
|
||||
: _network(network),
|
||||
_nukiOfficial(nukiOfficial),
|
||||
_preferences(preferences),
|
||||
_buffer(buffer),
|
||||
_bufferSize(bufferSize)
|
||||
{
|
||||
_nukiPublisher = new NukiPublisher(network, _mqttPath);
|
||||
_nukiOfficial->setPublisher(_nukiPublisher);
|
||||
@@ -201,21 +201,26 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
JsonDocument doc;
|
||||
|
||||
NetworkClientSecure *client = new NetworkClientSecure;
|
||||
if (client) {
|
||||
if (client)
|
||||
{
|
||||
client->setCACertBundle(x509_crt_imported_bundle_bin_start, x509_crt_imported_bundle_bin_end - x509_crt_imported_bundle_bin_start);
|
||||
{
|
||||
HTTPClient https;
|
||||
https.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
|
||||
https.useHTTP10(true);
|
||||
|
||||
if (https.begin(*client, GITHUB_OTA_MANIFEST_URL)) {
|
||||
if (https.begin(*client, GITHUB_OTA_MANIFEST_URL))
|
||||
{
|
||||
int httpResponseCode = https.GET();
|
||||
|
||||
if (httpResponseCode == HTTP_CODE_OK || httpResponseCode == HTTP_CODE_MOVED_PERMANENTLY)
|
||||
{
|
||||
DeserializationError jsonError = deserializeJson(doc, https.getStream());
|
||||
|
||||
if (!jsonError) { otaManifestSuccess = true; }
|
||||
if (!jsonError)
|
||||
{
|
||||
otaManifestSuccess = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
https.end();
|
||||
@@ -296,18 +301,27 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
else if(comparePrefixedPath(topic, mqtt_topic_webserver_action))
|
||||
{
|
||||
if(strcmp(data, "") == 0 ||
|
||||
strcmp(data, "--") == 0) return;
|
||||
strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(strcmp(data, "1") == 0)
|
||||
{
|
||||
if(_preferences->getBool(preference_webserver_enabled, true) || forceEnableWebServer) return;
|
||||
if(_preferences->getBool(preference_webserver_enabled, true) || forceEnableWebServer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Log->println(F("Webserver enabled, restarting."));
|
||||
_preferences->putBool(preference_webserver_enabled, true);
|
||||
|
||||
}
|
||||
else if (strcmp(data, "0") == 0)
|
||||
{
|
||||
if(!_preferences->getBool(preference_webserver_enabled, true) && !forceEnableWebServer) return;
|
||||
if(!_preferences->getBool(preference_webserver_enabled, true) && !forceEnableWebServer)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Log->println(F("Webserver disabled, restarting."));
|
||||
_preferences->putBool(preference_webserver_enabled, false);
|
||||
}
|
||||
@@ -320,9 +334,15 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
else if(comparePrefixedPath(topic, mqtt_topic_lock_log_rolling_last))
|
||||
{
|
||||
if(strcmp(data, "") == 0 ||
|
||||
strcmp(data, "--") == 0) return;
|
||||
strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(atoi(data) > 0 && atoi(data) > _lastRollingLog) _lastRollingLog = atoi(data);
|
||||
if(atoi(data) > 0 && atoi(data) > _lastRollingLog)
|
||||
{
|
||||
_lastRollingLog = atoi(data);
|
||||
}
|
||||
}
|
||||
|
||||
if(_nukiOfficial->getOffEnabled())
|
||||
@@ -342,11 +362,14 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
if(comparePrefixedPath(topic, mqtt_topic_lock_action))
|
||||
{
|
||||
if(strcmp(data, "") == 0 ||
|
||||
strcmp(data, "--") == 0 ||
|
||||
strcmp(data, "ack") == 0 ||
|
||||
strcmp(data, "unknown_action") == 0 ||
|
||||
strcmp(data, "denied") == 0 ||
|
||||
strcmp(data, "error") == 0) return;
|
||||
strcmp(data, "--") == 0 ||
|
||||
strcmp(data, "ack") == 0 ||
|
||||
strcmp(data, "unknown_action") == 0 ||
|
||||
strcmp(data, "denied") == 0 ||
|
||||
strcmp(data, "error") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Log->print(F("Lock action received: "));
|
||||
Log->println(data);
|
||||
@@ -358,18 +381,18 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
|
||||
switch(lockActionResult)
|
||||
{
|
||||
case LockActionResult::Success:
|
||||
publishString(mqtt_topic_lock_action, "ack", false);
|
||||
break;
|
||||
case LockActionResult::UnknownAction:
|
||||
publishString(mqtt_topic_lock_action, "unknown_action", false);
|
||||
break;
|
||||
case LockActionResult::AccessDenied:
|
||||
publishString(mqtt_topic_lock_action, "denied", false);
|
||||
break;
|
||||
case LockActionResult::Failed:
|
||||
publishString(mqtt_topic_lock_action, "error", false);
|
||||
break;
|
||||
case LockActionResult::Success:
|
||||
publishString(mqtt_topic_lock_action, "ack", false);
|
||||
break;
|
||||
case LockActionResult::UnknownAction:
|
||||
publishString(mqtt_topic_lock_action, "unknown_action", false);
|
||||
break;
|
||||
case LockActionResult::AccessDenied:
|
||||
publishString(mqtt_topic_lock_action, "denied", false);
|
||||
break;
|
||||
case LockActionResult::Failed:
|
||||
publishString(mqtt_topic_lock_action, "error", false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,7 +402,10 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
{
|
||||
if(_keypadCommandReceivedReceivedCallback != nullptr)
|
||||
{
|
||||
if(strcmp(data, "--") == 0) return;
|
||||
if(strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_keypadCommandReceivedReceivedCallback(data, _keypadCommandId, _keypadCommandName, _keypadCommandCode, _keypadCommandEnabled);
|
||||
|
||||
@@ -439,7 +465,10 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
|
||||
if(comparePrefixedPath(topic, mqtt_topic_config_action))
|
||||
{
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(_configUpdateReceivedCallback != NULL)
|
||||
{
|
||||
@@ -451,7 +480,10 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
|
||||
if(comparePrefixedPath(topic, mqtt_topic_keypad_json_action))
|
||||
{
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(_keypadJsonCommandReceivedReceivedCallback != NULL)
|
||||
{
|
||||
@@ -463,7 +495,10 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
|
||||
if(comparePrefixedPath(topic, mqtt_topic_timecontrol_action))
|
||||
{
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(_timeControlCommandReceivedReceivedCallback != NULL)
|
||||
{
|
||||
@@ -475,7 +510,10 @@ void NukiNetworkLock::onMqttDataReceived(char* topic, int topic_len, char* data,
|
||||
|
||||
if(comparePrefixedPath(topic, mqtt_topic_auth_action))
|
||||
{
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(_authCommandReceivedReceivedCallback != NULL)
|
||||
{
|
||||
@@ -633,39 +671,39 @@ void NukiNetworkLock::publishState(NukiLock::LockState lockState)
|
||||
{
|
||||
switch(lockState)
|
||||
{
|
||||
case NukiLock::LockState::Locked:
|
||||
publishString(mqtt_topic_lock_ha_state, "locked", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "locked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Locking:
|
||||
publishString(mqtt_topic_lock_ha_state, "locking", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "locked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Unlocking:
|
||||
publishString(mqtt_topic_lock_ha_state, "unlocking", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Unlocked:
|
||||
case NukiLock::LockState::UnlockedLnga:
|
||||
publishString(mqtt_topic_lock_ha_state, "unlocked", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Unlatched:
|
||||
publishString(mqtt_topic_lock_ha_state, "open", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Unlatching:
|
||||
publishString(mqtt_topic_lock_ha_state, "opening", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Uncalibrated:
|
||||
case NukiLock::LockState::Calibration:
|
||||
case NukiLock::LockState::BootRun:
|
||||
case NukiLock::LockState::MotorBlocked:
|
||||
publishString(mqtt_topic_lock_ha_state, "jammed", true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case NukiLock::LockState::Locked:
|
||||
publishString(mqtt_topic_lock_ha_state, "locked", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "locked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Locking:
|
||||
publishString(mqtt_topic_lock_ha_state, "locking", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "locked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Unlocking:
|
||||
publishString(mqtt_topic_lock_ha_state, "unlocking", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Unlocked:
|
||||
case NukiLock::LockState::UnlockedLnga:
|
||||
publishString(mqtt_topic_lock_ha_state, "unlocked", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Unlatched:
|
||||
publishString(mqtt_topic_lock_ha_state, "open", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Unlatching:
|
||||
publishString(mqtt_topic_lock_ha_state, "opening", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiLock::LockState::Uncalibrated:
|
||||
case NukiLock::LockState::Calibration:
|
||||
case NukiLock::LockState::BootRun:
|
||||
case NukiLock::LockState::MotorBlocked:
|
||||
publishString(mqtt_topic_lock_ha_state, "jammed", true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -686,7 +724,10 @@ void NukiNetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntr
|
||||
{
|
||||
int sizeName = sizeof(log.name);
|
||||
memcpy(authName, log.name, sizeName);
|
||||
if(authName[sizeName - 1] != '\0') authName[sizeName] = '\0';
|
||||
if(authName[sizeName - 1] != '\0')
|
||||
{
|
||||
authName[sizeName] = '\0';
|
||||
}
|
||||
|
||||
if(log.index > authIndex)
|
||||
{
|
||||
@@ -712,7 +753,7 @@ void NukiNetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntr
|
||||
|
||||
if(entry["authorizationName"].as<String>().length() == 0 && _authEntries.count(log.authId) > 0)
|
||||
{
|
||||
entry["authorizationName"] = _authEntries[log.authId];
|
||||
entry["authorizationName"] = _authEntries[log.authId];
|
||||
}
|
||||
|
||||
entry["timeYear"] = log.timeStampYear;
|
||||
@@ -728,69 +769,75 @@ void NukiNetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntr
|
||||
|
||||
switch(log.loggingType)
|
||||
{
|
||||
case NukiLock::LoggingType::LockAction:
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
|
||||
entry["action"] = str;
|
||||
case NukiLock::LoggingType::LockAction:
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
|
||||
entry["action"] = str;
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiLock::triggerToString((NukiLock::Trigger)log.data[1], str);
|
||||
entry["trigger"] = str;
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiLock::triggerToString((NukiLock::Trigger)log.data[1], str);
|
||||
entry["trigger"] = str;
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[3], str);
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[3], str);
|
||||
entry["completionStatus"] = str;
|
||||
break;
|
||||
case NukiLock::LoggingType::KeypadAction:
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
|
||||
entry["action"] = str;
|
||||
|
||||
switch(log.data[1])
|
||||
{
|
||||
case 0:
|
||||
entry["trigger"] = "arrowkey";
|
||||
break;
|
||||
case 1:
|
||||
entry["trigger"] = "code";
|
||||
break;
|
||||
case 2:
|
||||
entry["trigger"] = "fingerprint";
|
||||
break;
|
||||
default:
|
||||
entry["trigger"] = "Unknown";
|
||||
break;
|
||||
}
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
|
||||
if(log.data[2] == 9)
|
||||
{
|
||||
entry["completionStatus"] = "notAuthorized";
|
||||
}
|
||||
else if (log.data[2] == 224)
|
||||
{
|
||||
entry["completionStatus"] = "invalidCode";
|
||||
}
|
||||
else
|
||||
{
|
||||
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[2], str);
|
||||
entry["completionStatus"] = str;
|
||||
}
|
||||
|
||||
entry["codeId"] = 256U*log.data[4]+log.data[3];
|
||||
break;
|
||||
case NukiLock::LoggingType::DoorSensor:
|
||||
switch(log.data[0])
|
||||
{
|
||||
case 0:
|
||||
entry["action"] = "DoorOpened";
|
||||
break;
|
||||
case NukiLock::LoggingType::KeypadAction:
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiLock::lockactionToString((NukiLock::LockAction)log.data[0], str);
|
||||
entry["action"] = str;
|
||||
|
||||
switch(log.data[1])
|
||||
{
|
||||
case 0:
|
||||
entry["trigger"] = "arrowkey";
|
||||
break;
|
||||
case 1:
|
||||
entry["trigger"] = "code";
|
||||
break;
|
||||
case 2:
|
||||
entry["trigger"] = "fingerprint";
|
||||
break;
|
||||
default:
|
||||
entry["trigger"] = "Unknown";
|
||||
break;
|
||||
}
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
|
||||
if(log.data[2] == 9) entry["completionStatus"] = "notAuthorized";
|
||||
else if (log.data[2] == 224) entry["completionStatus"] = "invalidCode";
|
||||
else
|
||||
{
|
||||
NukiLock::completionStatusToString((NukiLock::CompletionStatus)log.data[2], str);
|
||||
entry["completionStatus"] = str;
|
||||
}
|
||||
|
||||
entry["codeId"] = 256U*log.data[4]+log.data[3];
|
||||
case 1:
|
||||
entry["action"] = "DoorClosed";
|
||||
break;
|
||||
case NukiLock::LoggingType::DoorSensor:
|
||||
switch(log.data[0])
|
||||
{
|
||||
case 0:
|
||||
entry["action"] = "DoorOpened";
|
||||
break;
|
||||
case 1:
|
||||
entry["action"] = "DoorClosed";
|
||||
break;
|
||||
case 2:
|
||||
entry["action"] = "SensorJammed";
|
||||
break;
|
||||
default:
|
||||
entry["action"] = "Unknown";
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
entry["action"] = "SensorJammed";
|
||||
break;
|
||||
default:
|
||||
entry["action"] = "Unknown";
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(log.index > _lastRollingLog)
|
||||
@@ -804,8 +851,14 @@ void NukiNetworkLock::publishAuthorizationInfo(const std::list<NukiLock::LogEntr
|
||||
|
||||
serializeJson(json, _buffer, _bufferSize);
|
||||
|
||||
if(latest) publishString(mqtt_topic_lock_log_latest, _buffer, true);
|
||||
else publishString(mqtt_topic_lock_log, _buffer, true);
|
||||
if(latest)
|
||||
{
|
||||
publishString(mqtt_topic_lock_log_latest, _buffer, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
publishString(mqtt_topic_lock_log, _buffer, true);
|
||||
}
|
||||
|
||||
if(authIndex > 0)
|
||||
{
|
||||
@@ -1013,7 +1066,10 @@ void NukiNetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entr
|
||||
|
||||
jsonEntry["codeId"] = entry.codeId;
|
||||
|
||||
if(publishCode) jsonEntry["code"] = entry.code;
|
||||
if(publishCode)
|
||||
{
|
||||
jsonEntry["code"] = entry.code;
|
||||
}
|
||||
jsonEntry["enabled"] = entry.enabled;
|
||||
jsonEntry["name"] = entry.name;
|
||||
char createdDT[20];
|
||||
@@ -1034,7 +1090,8 @@ void NukiNetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entr
|
||||
uint8_t allowedWeekdaysInt = entry.allowedWeekdays;
|
||||
JsonArray weekdays = jsonEntry["allowedWeekdays"].to<JsonArray>();
|
||||
|
||||
while(allowedWeekdaysInt > 0) {
|
||||
while(allowedWeekdaysInt > 0)
|
||||
{
|
||||
if(allowedWeekdaysInt >= 64)
|
||||
{
|
||||
weekdays.add("mon");
|
||||
@@ -1111,24 +1168,26 @@ void NukiNetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entr
|
||||
std::string displayName = std::string("Keypad - ") + std::string((char*)codeName) + " - " + std::to_string(entry.codeId);
|
||||
|
||||
_network->publishHassTopic("switch",
|
||||
mqttDeviceName.c_str(),
|
||||
uidString,
|
||||
uidStringPostfix.c_str(),
|
||||
displayName.c_str(),
|
||||
_nukiName,
|
||||
baseTopic.c_str(),
|
||||
String("~") + basePath.c_str(),
|
||||
(char*)"SmartLock",
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
String("~") + mqtt_topic_keypad_json_action,
|
||||
{ { (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||
{ (char*)"stat_on", (char*)"1" },
|
||||
{ (char*)"stat_off", (char*)"0" }});
|
||||
mqttDeviceName.c_str(),
|
||||
uidString,
|
||||
uidStringPostfix.c_str(),
|
||||
displayName.c_str(),
|
||||
_nukiName,
|
||||
baseTopic.c_str(),
|
||||
String("~") + basePath.c_str(),
|
||||
(char*)"SmartLock",
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
String("~") + mqtt_topic_keypad_json_action,
|
||||
{
|
||||
{ (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||
{ (char*)"stat_on", (char*)"1" },
|
||||
{ (char*)"stat_off", (char*)"0" }
|
||||
});
|
||||
}
|
||||
|
||||
++index;
|
||||
@@ -1202,7 +1261,10 @@ void NukiNetworkLock::publishKeypad(const std::list<NukiLock::KeypadEntry>& entr
|
||||
|
||||
void NukiNetworkLock::publishKeypadEntry(const String topic, NukiLock::KeypadEntry entry)
|
||||
{
|
||||
if(_disableNonJSON) return;
|
||||
if(_disableNonJSON)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
char codeName[sizeof(entry.name) + 1];
|
||||
memset(codeName, 0, sizeof(codeName));
|
||||
@@ -1245,7 +1307,8 @@ void NukiNetworkLock::publishTimeControl(const std::list<NukiLock::TimeControlEn
|
||||
uint8_t weekdaysInt = entry.weekdays;
|
||||
JsonArray weekdays = jsonEntry["weekdays"].to<JsonArray>();
|
||||
|
||||
while(weekdaysInt > 0) {
|
||||
while(weekdaysInt > 0)
|
||||
{
|
||||
if(weekdaysInt >= 64)
|
||||
{
|
||||
weekdays.add("mon");
|
||||
@@ -1319,24 +1382,26 @@ void NukiNetworkLock::publishTimeControl(const std::list<NukiLock::TimeControlEn
|
||||
std::string displayName = std::string("Timecontrol - ") + std::to_string(entry.entryId);
|
||||
|
||||
_network->publishHassTopic("switch",
|
||||
mqttDeviceName.c_str(),
|
||||
uidString,
|
||||
uidStringPostfix.c_str(),
|
||||
displayName.c_str(),
|
||||
_nukiName,
|
||||
baseTopic.c_str(),
|
||||
String("~") + basePath.c_str(),
|
||||
(char*)"SmartLock",
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
String("~") + mqtt_topic_timecontrol_action,
|
||||
{ { (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||
{ (char*)"stat_on", (char*)"1" },
|
||||
{ (char*)"stat_off", (char*)"0" }});
|
||||
mqttDeviceName.c_str(),
|
||||
uidString,
|
||||
uidStringPostfix.c_str(),
|
||||
displayName.c_str(),
|
||||
_nukiName,
|
||||
baseTopic.c_str(),
|
||||
String("~") + basePath.c_str(),
|
||||
(char*)"SmartLock",
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
String("~") + mqtt_topic_timecontrol_action,
|
||||
{
|
||||
{ (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||
{ (char*)"stat_on", (char*)"1" },
|
||||
{ (char*)"stat_off", (char*)"0" }
|
||||
});
|
||||
}
|
||||
|
||||
++index;
|
||||
@@ -1393,7 +1458,8 @@ void NukiNetworkLock::publishAuth(const std::list<NukiLock::AuthorizationEntry>&
|
||||
uint8_t allowedWeekdaysInt = entry.allowedWeekdays;
|
||||
JsonArray weekdays = jsonEntry["allowedWeekdays"].to<JsonArray>();
|
||||
|
||||
while(allowedWeekdaysInt > 0) {
|
||||
while(allowedWeekdaysInt > 0)
|
||||
{
|
||||
if(allowedWeekdaysInt >= 64)
|
||||
{
|
||||
weekdays.add("mon");
|
||||
@@ -1466,24 +1532,26 @@ void NukiNetworkLock::publishAuth(const std::list<NukiLock::AuthorizationEntry>&
|
||||
std::string displayName = std::string("Authorization - ") + std::to_string(entry.authId);
|
||||
|
||||
_network->publishHassTopic("switch",
|
||||
mqttDeviceName.c_str(),
|
||||
uidString,
|
||||
uidStringPostfix.c_str(),
|
||||
displayName.c_str(),
|
||||
_nukiName,
|
||||
baseTopic.c_str(),
|
||||
String("~") + basePath.c_str(),
|
||||
(char*)"SmartLock",
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
String("~") + mqtt_topic_auth_action,
|
||||
{ { (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||
{ (char*)"stat_on", (char*)"1" },
|
||||
{ (char*)"stat_off", (char*)"0" }});
|
||||
mqttDeviceName.c_str(),
|
||||
uidString,
|
||||
uidStringPostfix.c_str(),
|
||||
displayName.c_str(),
|
||||
_nukiName,
|
||||
baseTopic.c_str(),
|
||||
String("~") + basePath.c_str(),
|
||||
(char*)"SmartLock",
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
String("~") + mqtt_topic_auth_action,
|
||||
{
|
||||
{ (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||
{ (char*)"stat_on", (char*)"1" },
|
||||
{ (char*)"stat_off", (char*)"0" }
|
||||
});
|
||||
}
|
||||
|
||||
++index;
|
||||
@@ -1510,7 +1578,10 @@ void NukiNetworkLock::publishConfigCommandResult(const char* result)
|
||||
|
||||
void NukiNetworkLock::publishKeypadCommandResult(const char* result)
|
||||
{
|
||||
if(_disableNonJSON) return;
|
||||
if(_disableNonJSON)
|
||||
{
|
||||
return;
|
||||
}
|
||||
publishString(mqtt_topic_keypad_command_result, result, true);
|
||||
}
|
||||
|
||||
@@ -1551,7 +1622,10 @@ void NukiNetworkLock::setConfigUpdateReceivedCallback(void (*configUpdateReceive
|
||||
|
||||
void NukiNetworkLock::setKeypadCommandReceivedCallback(void (*keypadCommandReceivedReceivedCallback)(const char* command, const uint& id, const String& name, const String& code, const int& enabled))
|
||||
{
|
||||
if(_disableNonJSON) return;
|
||||
if(_disableNonJSON)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_keypadCommandReceivedReceivedCallback = keypadCommandReceivedReceivedCallback;
|
||||
}
|
||||
|
||||
@@ -1604,7 +1678,7 @@ bool NukiNetworkLock::comparePrefixedPath(const char *fullPath, const char *subP
|
||||
}
|
||||
|
||||
void NukiNetworkLock::publishHASSConfig(char *deviceType, const char *baseTopic, char *name, char *uidString, const char *softwareVersion, const char *hardwareVersion, const bool& hasDoorSensor, const bool& hasKeypad, const bool& publishAuthData, char *lockAction,
|
||||
char *unlockAction, char *openAction)
|
||||
char *unlockAction, char *openAction)
|
||||
{
|
||||
_network->publishHASSConfig(deviceType, baseTopic, name, uidString, softwareVersion, hardwareVersion, "~/maintenance/mqttConnectionState", hasKeypad, lockAction, unlockAction, openAction);
|
||||
_network->publishHASSConfigAdditionalLockEntities(deviceType, baseTopic, name, uidString);
|
||||
@@ -1618,9 +1692,9 @@ void NukiNetworkLock::publishHASSConfig(char *deviceType, const char *baseTopic,
|
||||
_network->removeHASSConfigTopic((char*)"binary_sensor", (char*)"door_sensor", uidString);
|
||||
}
|
||||
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
||||
_network->publishHASSWifiRssiConfig(deviceType, baseTopic, name, uidString);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if(publishAuthData)
|
||||
{
|
||||
@@ -1719,76 +1793,82 @@ uint8_t NukiNetworkLock::queryCommands()
|
||||
return qc;
|
||||
}
|
||||
|
||||
void NukiNetworkLock::buttonPressActionToString(const NukiLock::ButtonPressAction btnPressAction, char* str) {
|
||||
switch (btnPressAction) {
|
||||
void NukiNetworkLock::buttonPressActionToString(const NukiLock::ButtonPressAction btnPressAction, char* str)
|
||||
{
|
||||
switch (btnPressAction)
|
||||
{
|
||||
case NukiLock::ButtonPressAction::NoAction:
|
||||
strcpy(str, "No Action");
|
||||
break;
|
||||
strcpy(str, "No Action");
|
||||
break;
|
||||
case NukiLock::ButtonPressAction::Intelligent:
|
||||
strcpy(str, "Intelligent");
|
||||
break;
|
||||
strcpy(str, "Intelligent");
|
||||
break;
|
||||
case NukiLock::ButtonPressAction::Unlock:
|
||||
strcpy(str, "Unlock");
|
||||
break;
|
||||
strcpy(str, "Unlock");
|
||||
break;
|
||||
case NukiLock::ButtonPressAction::Lock:
|
||||
strcpy(str, "Lock");
|
||||
break;
|
||||
strcpy(str, "Lock");
|
||||
break;
|
||||
case NukiLock::ButtonPressAction::Unlatch:
|
||||
strcpy(str, "Unlatch");
|
||||
break;
|
||||
strcpy(str, "Unlatch");
|
||||
break;
|
||||
case NukiLock::ButtonPressAction::LockNgo:
|
||||
strcpy(str, "Lock n Go");
|
||||
break;
|
||||
strcpy(str, "Lock n Go");
|
||||
break;
|
||||
case NukiLock::ButtonPressAction::ShowStatus:
|
||||
strcpy(str, "Show Status");
|
||||
break;
|
||||
strcpy(str, "Show Status");
|
||||
break;
|
||||
default:
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void NukiNetworkLock::homeKitStatusToString(const int hkstatus, char* str) {
|
||||
switch (hkstatus) {
|
||||
void NukiNetworkLock::homeKitStatusToString(const int hkstatus, char* str)
|
||||
{
|
||||
switch (hkstatus)
|
||||
{
|
||||
case 0:
|
||||
strcpy(str, "Not Available");
|
||||
break;
|
||||
strcpy(str, "Not Available");
|
||||
break;
|
||||
case 1:
|
||||
strcpy(str, "Disabled");
|
||||
break;
|
||||
strcpy(str, "Disabled");
|
||||
break;
|
||||
case 2:
|
||||
strcpy(str, "Enabled");
|
||||
break;
|
||||
strcpy(str, "Enabled");
|
||||
break;
|
||||
case 3:
|
||||
strcpy(str, "Enabled & Paired");
|
||||
break;
|
||||
strcpy(str, "Enabled & Paired");
|
||||
break;
|
||||
default:
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void NukiNetworkLock::fobActionToString(const int fobact, char* str) {
|
||||
switch (fobact) {
|
||||
void NukiNetworkLock::fobActionToString(const int fobact, char* str)
|
||||
{
|
||||
switch (fobact)
|
||||
{
|
||||
case 0:
|
||||
strcpy(str, "No Action");
|
||||
break;
|
||||
strcpy(str, "No Action");
|
||||
break;
|
||||
case 1:
|
||||
strcpy(str, "Unlock");
|
||||
break;
|
||||
strcpy(str, "Unlock");
|
||||
break;
|
||||
case 2:
|
||||
strcpy(str, "Lock");
|
||||
break;
|
||||
strcpy(str, "Lock");
|
||||
break;
|
||||
case 3:
|
||||
strcpy(str, "Lock n Go");
|
||||
break;
|
||||
strcpy(str, "Lock n Go");
|
||||
break;
|
||||
case 4:
|
||||
strcpy(str, "Intelligent");
|
||||
break;
|
||||
strcpy(str, "Intelligent");
|
||||
break;
|
||||
default:
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const uint32_t NukiNetworkLock::getAuthId() const
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
NukiNetworkOpener::NukiNetworkOpener(NukiNetwork* network, Preferences* preferences, char* buffer, size_t bufferSize)
|
||||
: _preferences(preferences),
|
||||
_network(network),
|
||||
_buffer(buffer),
|
||||
_bufferSize(bufferSize)
|
||||
: _preferences(preferences),
|
||||
_network(network),
|
||||
_buffer(buffer),
|
||||
_bufferSize(bufferSize)
|
||||
{
|
||||
_nukiPublisher = new NukiPublisher(network, _mqttPath);
|
||||
|
||||
@@ -124,9 +124,9 @@ void NukiNetworkOpener::initialize()
|
||||
}
|
||||
|
||||
_network->addReconnectedCallback([&]()
|
||||
{
|
||||
_reconnected = true;
|
||||
});
|
||||
{
|
||||
_reconnected = true;
|
||||
});
|
||||
}
|
||||
|
||||
void NukiNetworkOpener::update()
|
||||
@@ -149,19 +149,28 @@ void NukiNetworkOpener::onMqttDataReceived(char* topic, int topic_len, char* dat
|
||||
if(comparePrefixedPath(topic, mqtt_topic_lock_log_rolling_last))
|
||||
{
|
||||
if(strcmp(data, "") == 0 ||
|
||||
strcmp(data, "--") == 0) return;
|
||||
strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(atoi(data) > 0 && atoi(data) > _lastRollingLog) _lastRollingLog = atoi(data);
|
||||
if(atoi(data) > 0 && atoi(data) > _lastRollingLog)
|
||||
{
|
||||
_lastRollingLog = atoi(data);
|
||||
}
|
||||
}
|
||||
|
||||
if(comparePrefixedPath(topic, mqtt_topic_lock_action))
|
||||
{
|
||||
if(strcmp(data, "") == 0 ||
|
||||
strcmp(data, "--") == 0 ||
|
||||
strcmp(data, "ack") == 0 ||
|
||||
strcmp(data, "unknown_action") == 0 ||
|
||||
strcmp(data, "denied") == 0 ||
|
||||
strcmp(data, "error") == 0) return;
|
||||
strcmp(data, "--") == 0 ||
|
||||
strcmp(data, "ack") == 0 ||
|
||||
strcmp(data, "unknown_action") == 0 ||
|
||||
strcmp(data, "denied") == 0 ||
|
||||
strcmp(data, "error") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Log->print(F("Opener action received: "));
|
||||
Log->println(data);
|
||||
@@ -173,18 +182,18 @@ void NukiNetworkOpener::onMqttDataReceived(char* topic, int topic_len, char* dat
|
||||
|
||||
switch(lockActionResult)
|
||||
{
|
||||
case LockActionResult::Success:
|
||||
publishString(mqtt_topic_lock_action, "ack", false);
|
||||
break;
|
||||
case LockActionResult::UnknownAction:
|
||||
publishString(mqtt_topic_lock_action, "unknown_action", false);
|
||||
break;
|
||||
case LockActionResult::AccessDenied:
|
||||
publishString(mqtt_topic_lock_action, "denied", false);
|
||||
break;
|
||||
case LockActionResult::Failed:
|
||||
publishString(mqtt_topic_lock_action, "error", false);
|
||||
break;
|
||||
case LockActionResult::Success:
|
||||
publishString(mqtt_topic_lock_action, "ack", false);
|
||||
break;
|
||||
case LockActionResult::UnknownAction:
|
||||
publishString(mqtt_topic_lock_action, "unknown_action", false);
|
||||
break;
|
||||
case LockActionResult::AccessDenied:
|
||||
publishString(mqtt_topic_lock_action, "denied", false);
|
||||
break;
|
||||
case LockActionResult::Failed:
|
||||
publishString(mqtt_topic_lock_action, "error", false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +203,10 @@ void NukiNetworkOpener::onMqttDataReceived(char* topic, int topic_len, char* dat
|
||||
{
|
||||
if(_keypadCommandReceivedReceivedCallback != nullptr)
|
||||
{
|
||||
if(strcmp(data, "--") == 0) return;
|
||||
if(strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_keypadCommandReceivedReceivedCallback(data, _keypadCommandId, _keypadCommandName, _keypadCommandCode, _keypadCommandEnabled);
|
||||
|
||||
@@ -254,7 +266,10 @@ void NukiNetworkOpener::onMqttDataReceived(char* topic, int topic_len, char* dat
|
||||
|
||||
if(comparePrefixedPath(topic, mqtt_topic_config_action))
|
||||
{
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(_configUpdateReceivedCallback != NULL)
|
||||
{
|
||||
@@ -266,7 +281,10 @@ void NukiNetworkOpener::onMqttDataReceived(char* topic, int topic_len, char* dat
|
||||
|
||||
if(comparePrefixedPath(topic, mqtt_topic_keypad_json_action))
|
||||
{
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(_keypadJsonCommandReceivedReceivedCallback != NULL)
|
||||
{
|
||||
@@ -278,7 +296,10 @@ void NukiNetworkOpener::onMqttDataReceived(char* topic, int topic_len, char* dat
|
||||
|
||||
if(comparePrefixedPath(topic, mqtt_topic_timecontrol_action))
|
||||
{
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(_timeControlCommandReceivedReceivedCallback != NULL)
|
||||
{
|
||||
@@ -290,7 +311,10 @@ void NukiNetworkOpener::onMqttDataReceived(char* topic, int topic_len, char* dat
|
||||
|
||||
if(comparePrefixedPath(topic, mqtt_topic_auth_action))
|
||||
{
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0) return;
|
||||
if(strcmp(data, "") == 0 || strcmp(data, "--") == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(_authCommandReceivedReceivedCallback != NULL)
|
||||
{
|
||||
@@ -329,7 +353,9 @@ void NukiNetworkOpener::publishKeyTurnerState(const NukiOpener::OpenerState& key
|
||||
{
|
||||
publishString(mqtt_topic_lock_continuous_mode, "on", true);
|
||||
json["continuous_mode"] = 1;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
publishString(mqtt_topic_lock_continuous_mode, "off", true);
|
||||
json["continuous_mode"] = 0;
|
||||
}
|
||||
@@ -429,28 +455,28 @@ void NukiNetworkOpener::publishState(NukiOpener::OpenerState lockState)
|
||||
{
|
||||
switch (lockState.lockState)
|
||||
{
|
||||
case NukiOpener::LockState::Locked:
|
||||
publishString(mqtt_topic_lock_ha_state, "locked", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "locked", true);
|
||||
break;
|
||||
case NukiOpener::LockState::RTOactive:
|
||||
publishString(mqtt_topic_lock_ha_state, "unlocked", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiOpener::LockState::Open:
|
||||
publishString(mqtt_topic_lock_ha_state, "open", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiOpener::LockState::Opening:
|
||||
publishString(mqtt_topic_lock_ha_state, "opening", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiOpener::LockState::Undefined:
|
||||
case NukiOpener::LockState::Uncalibrated:
|
||||
publishString(mqtt_topic_lock_ha_state, "jammed", true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case NukiOpener::LockState::Locked:
|
||||
publishString(mqtt_topic_lock_ha_state, "locked", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "locked", true);
|
||||
break;
|
||||
case NukiOpener::LockState::RTOactive:
|
||||
publishString(mqtt_topic_lock_ha_state, "unlocked", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiOpener::LockState::Open:
|
||||
publishString(mqtt_topic_lock_ha_state, "open", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiOpener::LockState::Opening:
|
||||
publishString(mqtt_topic_lock_ha_state, "opening", true);
|
||||
publishString(mqtt_topic_lock_binary_state, "unlocked", true);
|
||||
break;
|
||||
case NukiOpener::LockState::Undefined:
|
||||
case NukiOpener::LockState::Uncalibrated:
|
||||
publishString(mqtt_topic_lock_ha_state, "jammed", true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -472,7 +498,10 @@ void NukiNetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::Log
|
||||
{
|
||||
int sizeName = sizeof(log.name);
|
||||
memcpy(authName, log.name, sizeName);
|
||||
if(authName[sizeName - 1] != '\0') authName[sizeName] = '\0';
|
||||
if(authName[sizeName - 1] != '\0')
|
||||
{
|
||||
authName[sizeName] = '\0';
|
||||
}
|
||||
|
||||
if(log.index > authIndex)
|
||||
{
|
||||
@@ -481,7 +510,7 @@ void NukiNetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::Log
|
||||
_authId = log.authId;
|
||||
memset(_authName, 0, sizeof(_authName));
|
||||
memcpy(_authName, authName, sizeof(authName));
|
||||
|
||||
|
||||
if(authName[sizeName - 1] != '\0' && _authEntries.count(_authId) > 0)
|
||||
{
|
||||
memset(_authName, 0, sizeof(_authName));
|
||||
@@ -495,12 +524,12 @@ void NukiNetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::Log
|
||||
entry["index"] = log.index;
|
||||
entry["authorizationId"] = log.authId;
|
||||
entry["authorizationName"] = _authName;
|
||||
|
||||
|
||||
if(entry["authorizationName"].as<String>().length() == 0 && _authEntries.count(log.authId) > 0)
|
||||
{
|
||||
entry["authorizationName"] = _authEntries[log.authId];
|
||||
entry["authorizationName"] = _authEntries[log.authId];
|
||||
}
|
||||
|
||||
|
||||
entry["timeYear"] = log.timeStampYear;
|
||||
entry["timeMonth"] = log.timeStampMonth;
|
||||
entry["timeDay"] = log.timeStampDay;
|
||||
@@ -514,104 +543,111 @@ void NukiNetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::Log
|
||||
|
||||
switch(log.loggingType)
|
||||
{
|
||||
case NukiOpener::LoggingType::LockAction:
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiOpener::lockactionToString((NukiOpener::LockAction)log.data[0], str);
|
||||
entry["action"] = str;
|
||||
case NukiOpener::LoggingType::LockAction:
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiOpener::lockactionToString((NukiOpener::LockAction)log.data[0], str);
|
||||
entry["action"] = str;
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiOpener::triggerToString((NukiOpener::Trigger)log.data[1], str);
|
||||
entry["trigger"] = str;
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiOpener::triggerToString((NukiOpener::Trigger)log.data[1], str);
|
||||
entry["trigger"] = str;
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiOpener::completionStatusToString((NukiOpener::CompletionStatus)log.data[3], str);
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiOpener::completionStatusToString((NukiOpener::CompletionStatus)log.data[3], str);
|
||||
entry["completionStatus"] = str;
|
||||
break;
|
||||
case NukiOpener::LoggingType::KeypadAction:
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiOpener::lockactionToString((NukiOpener::LockAction)log.data[0], str);
|
||||
entry["action"] = str;
|
||||
|
||||
switch(log.data[1])
|
||||
{
|
||||
case 0:
|
||||
entry["trigger"] = "arrowkey";
|
||||
break;
|
||||
case 1:
|
||||
entry["trigger"] = "code";
|
||||
break;
|
||||
case 2:
|
||||
entry["trigger"] = "fingerprint";
|
||||
break;
|
||||
default:
|
||||
entry["trigger"] = "Unknown";
|
||||
break;
|
||||
}
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
|
||||
if(log.data[2] == 9)
|
||||
{
|
||||
entry["completionStatus"] = "notAuthorized";
|
||||
}
|
||||
else if (log.data[2] == 224)
|
||||
{
|
||||
entry["completionStatus"] = "invalidCode";
|
||||
}
|
||||
else
|
||||
{
|
||||
NukiOpener::completionStatusToString((NukiOpener::CompletionStatus)log.data[2], str);
|
||||
entry["completionStatus"] = str;
|
||||
}
|
||||
|
||||
entry["codeId"] = 256U*log.data[4]+log.data[3];
|
||||
break;
|
||||
case NukiOpener::LoggingType::DoorbellRecognition:
|
||||
switch(log.data[0] & 3)
|
||||
{
|
||||
case 0:
|
||||
entry["mode"] = "None";
|
||||
break;
|
||||
case NukiOpener::LoggingType::KeypadAction:
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiOpener::lockactionToString((NukiOpener::LockAction)log.data[0], str);
|
||||
entry["action"] = str;
|
||||
|
||||
switch(log.data[1])
|
||||
{
|
||||
case 0:
|
||||
entry["trigger"] = "arrowkey";
|
||||
break;
|
||||
case 1:
|
||||
entry["trigger"] = "code";
|
||||
break;
|
||||
case 2:
|
||||
entry["trigger"] = "fingerprint";
|
||||
break;
|
||||
default:
|
||||
entry["trigger"] = "Unknown";
|
||||
break;
|
||||
}
|
||||
|
||||
memset(str, 0, sizeof(str));
|
||||
|
||||
if(log.data[2] == 9) entry["completionStatus"] = "notAuthorized";
|
||||
else if (log.data[2] == 224) entry["completionStatus"] = "invalidCode";
|
||||
else
|
||||
{
|
||||
NukiOpener::completionStatusToString((NukiOpener::CompletionStatus)log.data[2], str);
|
||||
entry["completionStatus"] = str;
|
||||
}
|
||||
|
||||
entry["codeId"] = 256U*log.data[4]+log.data[3];
|
||||
case 1:
|
||||
entry["mode"] = "RTO";
|
||||
break;
|
||||
case NukiOpener::LoggingType::DoorbellRecognition:
|
||||
switch(log.data[0] & 3)
|
||||
{
|
||||
case 0:
|
||||
entry["mode"] = "None";
|
||||
break;
|
||||
case 1:
|
||||
entry["mode"] = "RTO";
|
||||
break;
|
||||
case 2:
|
||||
entry["mode"] = "CM";
|
||||
break;
|
||||
default:
|
||||
entry["mode"] = "Unknown";
|
||||
break;
|
||||
}
|
||||
|
||||
switch(log.data[1])
|
||||
{
|
||||
case 0:
|
||||
entry["source"] = "Doorbell";
|
||||
break;
|
||||
case 1:
|
||||
entry["source"] = "Timecontrol";
|
||||
break;
|
||||
case 2:
|
||||
entry["source"] = "App";
|
||||
break;
|
||||
case 3:
|
||||
entry["source"] = "Button";
|
||||
break;
|
||||
case 4:
|
||||
entry["source"] = "Fob";
|
||||
break;
|
||||
case 5:
|
||||
entry["source"] = "Bridge";
|
||||
break;
|
||||
case 6:
|
||||
entry["source"] = "Keypad";
|
||||
break;
|
||||
default:
|
||||
entry["source"] = "Unknown";
|
||||
break; }
|
||||
|
||||
entry["geofence"] = log.data[2] == 1 ? "active" : "inactive";
|
||||
entry["doorbellSuppression"] = log.data[3] == 1 ? "active" : "inactive";
|
||||
entry["soundId"] = log.data[4];
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiOpener::completionStatusToString((NukiOpener::CompletionStatus)log.data[5], str);
|
||||
entry["completionStatus"] = str;
|
||||
entry["codeId"] = 256U*log.data[7]+log.data[6];
|
||||
case 2:
|
||||
entry["mode"] = "CM";
|
||||
break;
|
||||
default:
|
||||
entry["mode"] = "Unknown";
|
||||
break;
|
||||
}
|
||||
|
||||
switch(log.data[1])
|
||||
{
|
||||
case 0:
|
||||
entry["source"] = "Doorbell";
|
||||
break;
|
||||
case 1:
|
||||
entry["source"] = "Timecontrol";
|
||||
break;
|
||||
case 2:
|
||||
entry["source"] = "App";
|
||||
break;
|
||||
case 3:
|
||||
entry["source"] = "Button";
|
||||
break;
|
||||
case 4:
|
||||
entry["source"] = "Fob";
|
||||
break;
|
||||
case 5:
|
||||
entry["source"] = "Bridge";
|
||||
break;
|
||||
case 6:
|
||||
entry["source"] = "Keypad";
|
||||
break;
|
||||
default:
|
||||
entry["source"] = "Unknown";
|
||||
break;
|
||||
}
|
||||
|
||||
entry["geofence"] = log.data[2] == 1 ? "active" : "inactive";
|
||||
entry["doorbellSuppression"] = log.data[3] == 1 ? "active" : "inactive";
|
||||
entry["soundId"] = log.data[4];
|
||||
memset(str, 0, sizeof(str));
|
||||
NukiOpener::completionStatusToString((NukiOpener::CompletionStatus)log.data[5], str);
|
||||
entry["completionStatus"] = str;
|
||||
entry["codeId"] = 256U*log.data[7]+log.data[6];
|
||||
break;
|
||||
}
|
||||
|
||||
if(log.index > _lastRollingLog)
|
||||
@@ -625,8 +661,14 @@ void NukiNetworkOpener::publishAuthorizationInfo(const std::list<NukiOpener::Log
|
||||
|
||||
serializeJson(json, _buffer, _bufferSize);
|
||||
|
||||
if(latest) publishString(mqtt_topic_lock_log_latest, _buffer, true);
|
||||
else publishString(mqtt_topic_lock_log, _buffer, true);
|
||||
if(latest)
|
||||
{
|
||||
publishString(mqtt_topic_lock_log_latest, _buffer, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
publishString(mqtt_topic_lock_log, _buffer, true);
|
||||
}
|
||||
|
||||
if(authIndex > 0)
|
||||
{
|
||||
@@ -858,7 +900,10 @@ void NukiNetworkOpener::publishKeypad(const std::list<NukiLock::KeypadEntry>& en
|
||||
|
||||
jsonEntry["codeId"] = entry.codeId;
|
||||
|
||||
if(publishCode) jsonEntry["code"] = entry.code;
|
||||
if(publishCode)
|
||||
{
|
||||
jsonEntry["code"] = entry.code;
|
||||
}
|
||||
jsonEntry["enabled"] = entry.enabled;
|
||||
jsonEntry["name"] = entry.name;
|
||||
char createdDT[20];
|
||||
@@ -879,7 +924,8 @@ void NukiNetworkOpener::publishKeypad(const std::list<NukiLock::KeypadEntry>& en
|
||||
uint8_t allowedWeekdaysInt = entry.allowedWeekdays;
|
||||
JsonArray weekdays = jsonEntry["allowedWeekdays"].to<JsonArray>();
|
||||
|
||||
while(allowedWeekdaysInt > 0) {
|
||||
while(allowedWeekdaysInt > 0)
|
||||
{
|
||||
if(allowedWeekdaysInt >= 64)
|
||||
{
|
||||
weekdays.add("mon");
|
||||
@@ -956,24 +1002,26 @@ void NukiNetworkOpener::publishKeypad(const std::list<NukiLock::KeypadEntry>& en
|
||||
std::string displayName = std::string("Keypad - ") + std::string((char*)codeName) + " - " + std::to_string(entry.codeId);
|
||||
|
||||
_network->publishHassTopic("switch",
|
||||
mqttDeviceName.c_str(),
|
||||
uidString,
|
||||
uidStringPostfix.c_str(),
|
||||
displayName.c_str(),
|
||||
_nukiName,
|
||||
baseTopic.c_str(),
|
||||
String("~") + basePath.c_str(),
|
||||
(char*)"SmartLock",
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
String("~") + mqtt_topic_keypad_json_action,
|
||||
{ { (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||
{ (char*)"stat_on", (char*)"1" },
|
||||
{ (char*)"stat_off", (char*)"0" }});
|
||||
mqttDeviceName.c_str(),
|
||||
uidString,
|
||||
uidStringPostfix.c_str(),
|
||||
displayName.c_str(),
|
||||
_nukiName,
|
||||
baseTopic.c_str(),
|
||||
String("~") + basePath.c_str(),
|
||||
(char*)"SmartLock",
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
String("~") + mqtt_topic_keypad_json_action,
|
||||
{
|
||||
{ (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||
{ (char*)"stat_on", (char*)"1" },
|
||||
{ (char*)"stat_off", (char*)"0" }
|
||||
});
|
||||
}
|
||||
|
||||
++index;
|
||||
@@ -1062,7 +1110,8 @@ void NukiNetworkOpener::publishTimeControl(const std::list<NukiOpener::TimeContr
|
||||
uint8_t weekdaysInt = entry.weekdays;
|
||||
JsonArray weekdays = jsonEntry["weekdays"].to<JsonArray>();
|
||||
|
||||
while(weekdaysInt > 0) {
|
||||
while(weekdaysInt > 0)
|
||||
{
|
||||
if(weekdaysInt >= 64)
|
||||
{
|
||||
weekdays.add("mon");
|
||||
@@ -1134,24 +1183,26 @@ void NukiNetworkOpener::publishTimeControl(const std::list<NukiOpener::TimeContr
|
||||
std::string displayName = std::string("Timecontrol - ") + std::to_string(entry.entryId);
|
||||
|
||||
_network->publishHassTopic("switch",
|
||||
mqttDeviceName.c_str(),
|
||||
uidString,
|
||||
uidStringPostfix.c_str(),
|
||||
displayName.c_str(),
|
||||
_nukiName,
|
||||
baseTopic.c_str(),
|
||||
String("~") + basePath.c_str(),
|
||||
(char*)"Opener",
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
String("~") + mqtt_topic_timecontrol_action,
|
||||
{ { (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||
{ (char*)"stat_on", (char*)"1" },
|
||||
{ (char*)"stat_off", (char*)"0" }});
|
||||
mqttDeviceName.c_str(),
|
||||
uidString,
|
||||
uidStringPostfix.c_str(),
|
||||
displayName.c_str(),
|
||||
_nukiName,
|
||||
baseTopic.c_str(),
|
||||
String("~") + basePath.c_str(),
|
||||
(char*)"Opener",
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
String("~") + mqtt_topic_timecontrol_action,
|
||||
{
|
||||
{ (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||
{ (char*)"stat_on", (char*)"1" },
|
||||
{ (char*)"stat_off", (char*)"0" }
|
||||
});
|
||||
}
|
||||
|
||||
++index;
|
||||
@@ -1208,7 +1259,8 @@ void NukiNetworkOpener::publishAuth(const std::list<NukiOpener::AuthorizationEnt
|
||||
uint8_t allowedWeekdaysInt = entry.allowedWeekdays;
|
||||
JsonArray weekdays = jsonEntry["allowedWeekdays"].to<JsonArray>();
|
||||
|
||||
while(allowedWeekdaysInt > 0) {
|
||||
while(allowedWeekdaysInt > 0)
|
||||
{
|
||||
if(allowedWeekdaysInt >= 64)
|
||||
{
|
||||
weekdays.add("mon");
|
||||
@@ -1281,24 +1333,26 @@ void NukiNetworkOpener::publishAuth(const std::list<NukiOpener::AuthorizationEnt
|
||||
std::string displayName = std::string("Authorization - ") + std::to_string(entry.authId);
|
||||
|
||||
_network->publishHassTopic("switch",
|
||||
mqttDeviceName.c_str(),
|
||||
uidString,
|
||||
uidStringPostfix.c_str(),
|
||||
displayName.c_str(),
|
||||
_nukiName,
|
||||
baseTopic.c_str(),
|
||||
String("~") + basePath.c_str(),
|
||||
(char*)"Opener",
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
String("~") + mqtt_topic_auth_action,
|
||||
{ { (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||
{ (char*)"stat_on", (char*)"1" },
|
||||
{ (char*)"stat_off", (char*)"0" }});
|
||||
mqttDeviceName.c_str(),
|
||||
uidString,
|
||||
uidStringPostfix.c_str(),
|
||||
displayName.c_str(),
|
||||
_nukiName,
|
||||
baseTopic.c_str(),
|
||||
String("~") + basePath.c_str(),
|
||||
(char*)"Opener",
|
||||
"",
|
||||
"",
|
||||
"diagnostic",
|
||||
String("~") + mqtt_topic_auth_action,
|
||||
{
|
||||
{ (char*)"json_attr_t", (char*)basePathPrefixChr },
|
||||
{ (char*)"pl_on", (char*)enaCommand.c_str() },
|
||||
{ (char*)"pl_off", (char*)disCommand.c_str() },
|
||||
{ (char*)"val_tpl", (char*)"{{value_json.enabled}}" },
|
||||
{ (char*)"stat_on", (char*)"1" },
|
||||
{ (char*)"stat_off", (char*)"0" }
|
||||
});
|
||||
}
|
||||
|
||||
++index;
|
||||
@@ -1325,7 +1379,10 @@ void NukiNetworkOpener::publishConfigCommandResult(const char* result)
|
||||
|
||||
void NukiNetworkOpener::publishKeypadCommandResult(const char* result)
|
||||
{
|
||||
if(_disableNonJSON) return;
|
||||
if(_disableNonJSON)
|
||||
{
|
||||
return;
|
||||
}
|
||||
publishString(mqtt_topic_keypad_command_result, result, true);
|
||||
}
|
||||
|
||||
@@ -1361,7 +1418,10 @@ void NukiNetworkOpener::setConfigUpdateReceivedCallback(void (*configUpdateRecei
|
||||
|
||||
void NukiNetworkOpener::setKeypadCommandReceivedCallback(void (*keypadCommandReceivedReceivedCallback)(const char* command, const uint& id, const String& name, const String& code, const int& enabled))
|
||||
{
|
||||
if(_disableNonJSON) return;
|
||||
if(_disableNonJSON)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_keypadCommandReceivedReceivedCallback = keypadCommandReceivedReceivedCallback;
|
||||
}
|
||||
|
||||
@@ -1423,7 +1483,10 @@ void NukiNetworkOpener::publishString(const char* topic, const char* value, bool
|
||||
|
||||
void NukiNetworkOpener::publishKeypadEntry(const String topic, NukiLock::KeypadEntry entry)
|
||||
{
|
||||
if(_disableNonJSON) return;
|
||||
if(_disableNonJSON)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
char codeName[sizeof(entry.name) + 1];
|
||||
memset(codeName, 0, sizeof(codeName));
|
||||
@@ -1505,185 +1568,197 @@ uint8_t NukiNetworkOpener::queryCommands()
|
||||
return qc;
|
||||
}
|
||||
|
||||
void NukiNetworkOpener::buttonPressActionToString(const NukiOpener::ButtonPressAction btnPressAction, char* str) {
|
||||
switch (btnPressAction) {
|
||||
void NukiNetworkOpener::buttonPressActionToString(const NukiOpener::ButtonPressAction btnPressAction, char* str)
|
||||
{
|
||||
switch (btnPressAction)
|
||||
{
|
||||
case NukiOpener::ButtonPressAction::NoAction:
|
||||
strcpy(str, "No Action");
|
||||
break;
|
||||
strcpy(str, "No Action");
|
||||
break;
|
||||
case NukiOpener::ButtonPressAction::ToggleRTO:
|
||||
strcpy(str, "Toggle RTO");
|
||||
break;
|
||||
strcpy(str, "Toggle RTO");
|
||||
break;
|
||||
case NukiOpener::ButtonPressAction::ActivateRTO:
|
||||
strcpy(str, "Activate RTO");
|
||||
break;
|
||||
strcpy(str, "Activate RTO");
|
||||
break;
|
||||
case NukiOpener::ButtonPressAction::DeactivateRTO:
|
||||
strcpy(str, "Deactivate RTO");
|
||||
break;
|
||||
strcpy(str, "Deactivate RTO");
|
||||
break;
|
||||
case NukiOpener::ButtonPressAction::ToggleCM:
|
||||
strcpy(str, "Toggle CM");
|
||||
break;
|
||||
strcpy(str, "Toggle CM");
|
||||
break;
|
||||
case NukiOpener::ButtonPressAction::ActivateCM:
|
||||
strcpy(str, "Activate CM");
|
||||
break;
|
||||
strcpy(str, "Activate CM");
|
||||
break;
|
||||
case NukiOpener::ButtonPressAction::DectivateCM:
|
||||
strcpy(str, "Deactivate CM");
|
||||
break;
|
||||
strcpy(str, "Deactivate CM");
|
||||
break;
|
||||
case NukiOpener::ButtonPressAction::Open:
|
||||
strcpy(str, "Open");
|
||||
break;
|
||||
strcpy(str, "Open");
|
||||
break;
|
||||
default:
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void NukiNetworkOpener::fobActionToString(const int fobact, char* str) {
|
||||
switch (fobact) {
|
||||
void NukiNetworkOpener::fobActionToString(const int fobact, char* str)
|
||||
{
|
||||
switch (fobact)
|
||||
{
|
||||
case 0:
|
||||
strcpy(str, "No Action");
|
||||
break;
|
||||
strcpy(str, "No Action");
|
||||
break;
|
||||
case 1:
|
||||
strcpy(str, "Toggle RTO");
|
||||
break;
|
||||
strcpy(str, "Toggle RTO");
|
||||
break;
|
||||
case 2:
|
||||
strcpy(str, "Activate RTO");
|
||||
break;
|
||||
strcpy(str, "Activate RTO");
|
||||
break;
|
||||
case 3:
|
||||
strcpy(str, "Deactivate RTO");
|
||||
break;
|
||||
strcpy(str, "Deactivate RTO");
|
||||
break;
|
||||
case 7:
|
||||
strcpy(str, "Open");
|
||||
break;
|
||||
strcpy(str, "Open");
|
||||
break;
|
||||
case 8:
|
||||
strcpy(str, "Ring");
|
||||
break;
|
||||
strcpy(str, "Ring");
|
||||
break;
|
||||
default:
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void NukiNetworkOpener::capabilitiesToString(const int capabilities, char* str) {
|
||||
switch (capabilities) {
|
||||
void NukiNetworkOpener::capabilitiesToString(const int capabilities, char* str)
|
||||
{
|
||||
switch (capabilities)
|
||||
{
|
||||
case 0:
|
||||
strcpy(str, "Door opener");
|
||||
break;
|
||||
strcpy(str, "Door opener");
|
||||
break;
|
||||
case 1:
|
||||
strcpy(str, "Both");
|
||||
break;
|
||||
strcpy(str, "Both");
|
||||
break;
|
||||
case 2:
|
||||
strcpy(str, "RTO");
|
||||
break;
|
||||
strcpy(str, "RTO");
|
||||
break;
|
||||
default:
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void NukiNetworkOpener::operatingModeToString(const int opmode, char* str) {
|
||||
switch (opmode) {
|
||||
void NukiNetworkOpener::operatingModeToString(const int opmode, char* str)
|
||||
{
|
||||
switch (opmode)
|
||||
{
|
||||
case 0:
|
||||
strcpy(str, "Generic door opener");
|
||||
break;
|
||||
strcpy(str, "Generic door opener");
|
||||
break;
|
||||
case 1:
|
||||
strcpy(str, "Analogue intercom");
|
||||
break;
|
||||
strcpy(str, "Analogue intercom");
|
||||
break;
|
||||
case 2:
|
||||
strcpy(str, "Digital intercom");
|
||||
break;
|
||||
strcpy(str, "Digital intercom");
|
||||
break;
|
||||
case 3:
|
||||
strcpy(str, "Siedle");
|
||||
break;
|
||||
strcpy(str, "Siedle");
|
||||
break;
|
||||
case 4:
|
||||
strcpy(str, "TCS");
|
||||
break;
|
||||
strcpy(str, "TCS");
|
||||
break;
|
||||
case 5:
|
||||
strcpy(str, "Bticino");
|
||||
break;
|
||||
strcpy(str, "Bticino");
|
||||
break;
|
||||
case 6:
|
||||
strcpy(str, "Siedle HTS");
|
||||
break;
|
||||
strcpy(str, "Siedle HTS");
|
||||
break;
|
||||
case 7:
|
||||
strcpy(str, "STR");
|
||||
break;
|
||||
strcpy(str, "STR");
|
||||
break;
|
||||
case 8:
|
||||
strcpy(str, "Ritto");
|
||||
break;
|
||||
strcpy(str, "Ritto");
|
||||
break;
|
||||
case 9:
|
||||
strcpy(str, "Fermax");
|
||||
break;
|
||||
strcpy(str, "Fermax");
|
||||
break;
|
||||
case 10:
|
||||
strcpy(str, "Comelit");
|
||||
break;
|
||||
strcpy(str, "Comelit");
|
||||
break;
|
||||
case 11:
|
||||
strcpy(str, "Urmet BiBus");
|
||||
break;
|
||||
strcpy(str, "Urmet BiBus");
|
||||
break;
|
||||
case 12:
|
||||
strcpy(str, "Urmet 2Voice");
|
||||
break;
|
||||
strcpy(str, "Urmet 2Voice");
|
||||
break;
|
||||
case 13:
|
||||
strcpy(str, "Golmar");
|
||||
break;
|
||||
strcpy(str, "Golmar");
|
||||
break;
|
||||
case 14:
|
||||
strcpy(str, "SKS");
|
||||
break;
|
||||
strcpy(str, "SKS");
|
||||
break;
|
||||
case 15:
|
||||
strcpy(str, "Spare");
|
||||
break;
|
||||
strcpy(str, "Spare");
|
||||
break;
|
||||
default:
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void NukiNetworkOpener::doorbellSuppressionToString(const int dbsupr, char* str) {
|
||||
switch (dbsupr) {
|
||||
void NukiNetworkOpener::doorbellSuppressionToString(const int dbsupr, char* str)
|
||||
{
|
||||
switch (dbsupr)
|
||||
{
|
||||
case 0:
|
||||
strcpy(str, "Off");
|
||||
break;
|
||||
strcpy(str, "Off");
|
||||
break;
|
||||
case 1:
|
||||
strcpy(str, "CM");
|
||||
break;
|
||||
strcpy(str, "CM");
|
||||
break;
|
||||
case 2:
|
||||
strcpy(str, "RTO");
|
||||
break;
|
||||
strcpy(str, "RTO");
|
||||
break;
|
||||
case 3:
|
||||
strcpy(str, "CM & RTO");
|
||||
break;
|
||||
strcpy(str, "CM & RTO");
|
||||
break;
|
||||
case 4:
|
||||
strcpy(str, "Ring");
|
||||
break;
|
||||
strcpy(str, "Ring");
|
||||
break;
|
||||
case 5:
|
||||
strcpy(str, "CM & Ring");
|
||||
break;
|
||||
strcpy(str, "CM & Ring");
|
||||
break;
|
||||
case 6:
|
||||
strcpy(str, "RTO & Ring");
|
||||
break;
|
||||
strcpy(str, "RTO & Ring");
|
||||
break;
|
||||
case 7:
|
||||
strcpy(str, "CM & RTO & Ring");
|
||||
break;
|
||||
strcpy(str, "CM & RTO & Ring");
|
||||
break;
|
||||
default:
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void NukiNetworkOpener::soundToString(const int sound, char* str) {
|
||||
switch (sound) {
|
||||
void NukiNetworkOpener::soundToString(const int sound, char* str)
|
||||
{
|
||||
switch (sound)
|
||||
{
|
||||
case 0:
|
||||
strcpy(str, "No Sound");
|
||||
break;
|
||||
strcpy(str, "No Sound");
|
||||
break;
|
||||
case 1:
|
||||
strcpy(str, "Sound 1");
|
||||
break;
|
||||
strcpy(str, "Sound 1");
|
||||
break;
|
||||
case 2:
|
||||
strcpy(str, "Sound 2");
|
||||
break;
|
||||
strcpy(str, "Sound 2");
|
||||
break;
|
||||
case 3:
|
||||
strcpy(str, "Sound 3");
|
||||
break;
|
||||
strcpy(str, "Sound 3");
|
||||
break;
|
||||
default:
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
strcpy(str, "undefined");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,10 @@ void NukiOfficial::onOfficialUpdateReceived(const char *topic, const char *value
|
||||
Log->print(F("Battery critical: "));
|
||||
Log->println(offCritical);
|
||||
|
||||
if(!_disableNonJSON) _publisher->publishBool(mqtt_topic_battery_critical, offCritical, true);
|
||||
if(!_disableNonJSON)
|
||||
{
|
||||
_publisher->publishBool(mqtt_topic_battery_critical, offCritical, true);
|
||||
}
|
||||
publishBatteryJson = true;
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_official_batteryCharging) == 0)
|
||||
@@ -146,7 +149,10 @@ void NukiOfficial::onOfficialUpdateReceived(const char *topic, const char *value
|
||||
Log->print(F("Battery charging: "));
|
||||
Log->println(offCharging);
|
||||
|
||||
if(!_disableNonJSON) _publisher->publishBool(mqtt_topic_battery_charging, offCharging, true);
|
||||
if(!_disableNonJSON)
|
||||
{
|
||||
_publisher->publishBool(mqtt_topic_battery_charging, offCharging, true);
|
||||
}
|
||||
publishBatteryJson = true;
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_official_batteryChargeState) == 0)
|
||||
@@ -156,19 +162,28 @@ void NukiOfficial::onOfficialUpdateReceived(const char *topic, const char *value
|
||||
Log->print(F("Battery level: "));
|
||||
Log->println(offChargeState);
|
||||
|
||||
if(!_disableNonJSON) _publisher->publishInt(mqtt_topic_battery_level, offChargeState, true);
|
||||
if(!_disableNonJSON)
|
||||
{
|
||||
_publisher->publishInt(mqtt_topic_battery_level, offChargeState, true);
|
||||
}
|
||||
publishBatteryJson = true;
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_official_keypadBatteryCritical) == 0)
|
||||
{
|
||||
offKeypadCritical = (strcmp(value, "true") == 0 ? 1 : 0);
|
||||
if(!_disableNonJSON) _publisher->publishBool(mqtt_topic_battery_keypad_critical, offKeypadCritical, true);
|
||||
if(!_disableNonJSON)
|
||||
{
|
||||
_publisher->publishBool(mqtt_topic_battery_keypad_critical, offKeypadCritical, true);
|
||||
}
|
||||
publishBatteryJson = true;
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_official_doorsensorBatteryCritical) == 0)
|
||||
{
|
||||
offDoorsensorCritical = (strcmp(value, "true") == 0 ? 1 : 0);
|
||||
if(!_disableNonJSON) _publisher->publishBool(mqtt_topic_battery_doorsensor_critical, offDoorsensorCritical, true);
|
||||
if(!_disableNonJSON)
|
||||
{
|
||||
_publisher->publishBool(mqtt_topic_battery_doorsensor_critical, offDoorsensorCritical, true);
|
||||
}
|
||||
publishBatteryJson = true;
|
||||
}
|
||||
else if(strcmp(topic, mqtt_topic_official_commandResponse) == 0)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,8 +2,8 @@
|
||||
|
||||
|
||||
NukiPublisher::NukiPublisher(NukiNetwork *network, const char* mqttPath)
|
||||
: _network(network),
|
||||
_mqttPath(mqttPath)
|
||||
: _network(network),
|
||||
_mqttPath(mqttPath)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
1776
src/NukiWrapper.cpp
1776
src/NukiWrapper.cpp
File diff suppressed because it is too large
Load Diff
1012
src/WebCfgServer.cpp
1012
src/WebCfgServer.cpp
File diff suppressed because it is too large
Load Diff
184
src/main.cpp
184
src/main.cpp
@@ -77,8 +77,8 @@ TaskHandle_t networkTaskHandle = nullptr;
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
ssize_t write_fn(void* cookie, const char* buf, ssize_t size)
|
||||
{
|
||||
Log->write((uint8_t *)buf, (size_t)size);
|
||||
return size;
|
||||
Log->write((uint8_t *)buf, (size_t)size);
|
||||
return size;
|
||||
}
|
||||
|
||||
void ets_putc_handler(char c)
|
||||
@@ -87,21 +87,25 @@ void ets_putc_handler(char c)
|
||||
static size_t buf_pos = 0;
|
||||
buf[buf_pos] = c;
|
||||
buf_pos++;
|
||||
if (c == '\n' || buf_pos == sizeof(buf)) {
|
||||
if (c == '\n' || buf_pos == sizeof(buf))
|
||||
{
|
||||
write_fn(NULL, buf, buf_pos);
|
||||
buf_pos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int _log_vprintf(const char *fmt, va_list args) {
|
||||
int _log_vprintf(const char *fmt, va_list args)
|
||||
{
|
||||
int ret = vsnprintf(log_print_buffer, sizeof(log_print_buffer), fmt, args);
|
||||
if (ret >= 0){
|
||||
if (ret >= 0)
|
||||
{
|
||||
Log->write((uint8_t *)log_print_buffer, (size_t)ret);
|
||||
}
|
||||
return 0; //return vprintf(fmt, args);
|
||||
}
|
||||
|
||||
void setReroute(){
|
||||
void setReroute()
|
||||
{
|
||||
esp_log_set_vprintf(_log_vprintf);
|
||||
if(preferences->getBool(preference_mqtt_log_enabled))
|
||||
{
|
||||
@@ -152,7 +156,10 @@ void networkTask(void *pvParameters)
|
||||
setReroute();
|
||||
}
|
||||
#endif
|
||||
if(connected && openerEnabled) networkOpener->update();
|
||||
if(connected && openerEnabled)
|
||||
{
|
||||
networkOpener->update();
|
||||
}
|
||||
#endif
|
||||
|
||||
if((esp_timer_get_time() / 1000) - networkLoopTs > 120000)
|
||||
@@ -229,10 +236,10 @@ void bootloopDetection()
|
||||
}
|
||||
|
||||
if(esp_reset_reason() == esp_reset_reason_t::ESP_RST_PANIC ||
|
||||
esp_reset_reason() == esp_reset_reason_t::ESP_RST_INT_WDT ||
|
||||
esp_reset_reason() == esp_reset_reason_t::ESP_RST_TASK_WDT ||
|
||||
true ||
|
||||
esp_reset_reason() == esp_reset_reason_t::ESP_RST_WDT)
|
||||
esp_reset_reason() == esp_reset_reason_t::ESP_RST_INT_WDT ||
|
||||
esp_reset_reason() == esp_reset_reason_t::ESP_RST_TASK_WDT ||
|
||||
true ||
|
||||
esp_reset_reason() == esp_reset_reason_t::ESP_RST_WDT)
|
||||
{
|
||||
bootloopCounter++;
|
||||
Log->print(F("Bootloop counter incremented: "));
|
||||
@@ -263,38 +270,48 @@ uint8_t checkPartition()
|
||||
Log->print(F("Partition subtype: "));
|
||||
Log->println(running_partition->subtype);
|
||||
|
||||
if(running_partition->size == 1966080) return 0; //OLD PARTITION TABLE
|
||||
else if(running_partition->subtype == ESP_PARTITION_SUBTYPE_APP_OTA_0) return 1; //NEW PARTITION TABLE, RUNNING MAIN APP
|
||||
else return 2; //NEW PARTITION TABLE, RUNNING UPDATER APP
|
||||
if(running_partition->size == 1966080)
|
||||
{
|
||||
return 0; //OLD PARTITION TABLE
|
||||
}
|
||||
else if(running_partition->subtype == ESP_PARTITION_SUBTYPE_APP_OTA_0)
|
||||
{
|
||||
return 1; //NEW PARTITION TABLE, RUNNING MAIN APP
|
||||
}
|
||||
else
|
||||
{
|
||||
return 2; //NEW PARTITION TABLE, RUNNING UPDATER APP
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t _http_event_handler(esp_http_client_event_t *evt)
|
||||
{
|
||||
switch (evt->event_id) {
|
||||
case HTTP_EVENT_ERROR:
|
||||
Log->println("HTTP_EVENT_ERROR");
|
||||
break;
|
||||
case HTTP_EVENT_ON_CONNECTED:
|
||||
Log->println("HTTP_EVENT_ON_CONNECTED");
|
||||
break;
|
||||
case HTTP_EVENT_HEADER_SENT:
|
||||
Log->println("HTTP_EVENT_HEADER_SENT");
|
||||
break;
|
||||
case HTTP_EVENT_ON_HEADER:
|
||||
Log->println("HTTP_EVENT_ON_HEADER");
|
||||
break;
|
||||
case HTTP_EVENT_ON_DATA:
|
||||
Log->println("HTTP_EVENT_ON_DATA");
|
||||
break;
|
||||
case HTTP_EVENT_ON_FINISH:
|
||||
Log->println("HTTP_EVENT_ON_FINISH");
|
||||
break;
|
||||
case HTTP_EVENT_DISCONNECTED:
|
||||
Log->println("HTTP_EVENT_DISCONNECTED");
|
||||
break;
|
||||
case HTTP_EVENT_REDIRECT:
|
||||
Log->println("HTTP_EVENT_REDIRECT");
|
||||
break;
|
||||
switch (evt->event_id)
|
||||
{
|
||||
case HTTP_EVENT_ERROR:
|
||||
Log->println("HTTP_EVENT_ERROR");
|
||||
break;
|
||||
case HTTP_EVENT_ON_CONNECTED:
|
||||
Log->println("HTTP_EVENT_ON_CONNECTED");
|
||||
break;
|
||||
case HTTP_EVENT_HEADER_SENT:
|
||||
Log->println("HTTP_EVENT_HEADER_SENT");
|
||||
break;
|
||||
case HTTP_EVENT_ON_HEADER:
|
||||
Log->println("HTTP_EVENT_ON_HEADER");
|
||||
break;
|
||||
case HTTP_EVENT_ON_DATA:
|
||||
Log->println("HTTP_EVENT_ON_DATA");
|
||||
break;
|
||||
case HTTP_EVENT_ON_FINISH:
|
||||
Log->println("HTTP_EVENT_ON_FINISH");
|
||||
break;
|
||||
case HTTP_EVENT_DISCONNECTED:
|
||||
Log->println("HTTP_EVENT_DISCONNECTED");
|
||||
break;
|
||||
case HTTP_EVENT_REDIRECT:
|
||||
Log->println("HTTP_EVENT_REDIRECT");
|
||||
break;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
@@ -315,14 +332,16 @@ void otaTask(void *pvParameter)
|
||||
preferences->putString(preference_ota_main_url, "");
|
||||
}
|
||||
Log->println("Starting OTA task");
|
||||
esp_http_client_config_t config = {
|
||||
esp_http_client_config_t config =
|
||||
{
|
||||
.url = updateUrl.c_str(),
|
||||
.event_handler = _http_event_handler,
|
||||
.crt_bundle_attach = esp_crt_bundle_attach,
|
||||
.keep_alive_enable = true,
|
||||
};
|
||||
|
||||
esp_https_ota_config_t ota_config = {
|
||||
esp_https_ota_config_t ota_config =
|
||||
{
|
||||
.http_config = &config,
|
||||
};
|
||||
Log->print(F("Attempting to download update from "));
|
||||
@@ -334,19 +353,23 @@ void otaTask(void *pvParameter)
|
||||
while (retryCount <= retryMax)
|
||||
{
|
||||
esp_err_t ret = esp_https_ota(&ota_config);
|
||||
if (ret == ESP_OK) {
|
||||
if (ret == ESP_OK)
|
||||
{
|
||||
Log->println("OTA Succeeded, Rebooting...");
|
||||
esp_ota_set_boot_partition(esp_ota_get_next_update_partition(NULL));
|
||||
restartEsp(RestartReason::OTACompleted);
|
||||
break;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
Log->println("Firmware upgrade failed, retrying in 5 seconds");
|
||||
retryCount++;
|
||||
esp_task_wdt_reset();
|
||||
delay(5000);
|
||||
continue;
|
||||
}
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
@@ -359,7 +382,8 @@ void otaTask(void *pvParameter)
|
||||
void setupTasks(bool ota)
|
||||
{
|
||||
// configMAX_PRIORITIES is 25
|
||||
esp_task_wdt_config_t twdt_config = {
|
||||
esp_task_wdt_config_t twdt_config =
|
||||
{
|
||||
.timeout_ms = 300000,
|
||||
.idle_core_mask = 0,
|
||||
.trigger_panic = true,
|
||||
@@ -375,13 +399,13 @@ void setupTasks(bool ota)
|
||||
{
|
||||
xTaskCreatePinnedToCore(networkTask, "ntw", preferences->getInt(preference_task_size_network, NETWORK_TASK_SIZE), NULL, 3, &networkTaskHandle, 1);
|
||||
esp_task_wdt_add(networkTaskHandle);
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
if(!network->isApOpen())
|
||||
{
|
||||
xTaskCreatePinnedToCore(nukiTask, "nuki", preferences->getInt(preference_task_size_nuki, NUKI_TASK_SIZE), NULL, 2, &nukiTaskHandle, 0);
|
||||
esp_task_wdt_add(nukiTaskHandle);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,13 +416,13 @@ void setup()
|
||||
Serial.begin(115200);
|
||||
Log = &Serial;
|
||||
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
stdout = funopen(NULL, NULL, &write_fn, NULL, NULL);
|
||||
static char linebuf[1024];
|
||||
setvbuf(stdout, linebuf, _IOLBF, sizeof(linebuf));
|
||||
esp_rom_install_channel_putc(1, &ets_putc_handler);
|
||||
//ets_install_putc1(&ets_putc_handler);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
preferences = new Preferences();
|
||||
preferences->begin("nukihub", false);
|
||||
@@ -408,24 +432,36 @@ void setup()
|
||||
|
||||
initializeRestartReason();
|
||||
|
||||
if((partitionType==1 && preferences->getString(preference_ota_updater_url, "").length() > 0) || (partitionType==2 && preferences->getString(preference_ota_main_url, "").length() > 0)) doOta = true;
|
||||
if((partitionType==1 && preferences->getString(preference_ota_updater_url, "").length() > 0) || (partitionType==2 && preferences->getString(preference_ota_main_url, "").length() > 0))
|
||||
{
|
||||
doOta = true;
|
||||
}
|
||||
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
if(preferences->getBool(preference_enable_bootloop_reset, false))
|
||||
{
|
||||
bootloopDetection();
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef NUKI_HUB_UPDATER
|
||||
#ifdef NUKI_HUB_UPDATER
|
||||
Log->print(F("Nuki Hub OTA version "));
|
||||
Log->println(NUKI_HUB_VERSION);
|
||||
Log->print(F("Nuki Hub OTA build "));
|
||||
Log->println();
|
||||
|
||||
if(preferences->getString(preference_updater_version, "") != NUKI_HUB_VERSION) preferences->putString(preference_updater_version, NUKI_HUB_VERSION);
|
||||
if(preferences->getString(preference_updater_build, "") != NUKI_HUB_BUILD) preferences->putString(preference_updater_build, NUKI_HUB_BUILD);
|
||||
if(preferences->getString(preference_updater_date, "") != NUKI_HUB_DATE) preferences->putString(preference_updater_date, NUKI_HUB_DATE);
|
||||
if(preferences->getString(preference_updater_version, "") != NUKI_HUB_VERSION)
|
||||
{
|
||||
preferences->putString(preference_updater_version, NUKI_HUB_VERSION);
|
||||
}
|
||||
if(preferences->getString(preference_updater_build, "") != NUKI_HUB_BUILD)
|
||||
{
|
||||
preferences->putString(preference_updater_build, NUKI_HUB_BUILD);
|
||||
}
|
||||
if(preferences->getString(preference_updater_date, "") != NUKI_HUB_DATE)
|
||||
{
|
||||
preferences->putString(preference_updater_date, NUKI_HUB_DATE);
|
||||
}
|
||||
|
||||
network = new NukiNetwork(preferences);
|
||||
network->initialize();
|
||||
@@ -436,9 +472,12 @@ void setup()
|
||||
webCfgServer = new WebCfgServer(network, preferences, network->networkDeviceType() == NetworkDeviceType::WiFi, partitionType, psychicServer);
|
||||
webCfgServer->initialize();
|
||||
psychicServer->listen(80);
|
||||
psychicServer->onNotFound([](PsychicRequest* request) { return request->redirect("/"); });
|
||||
psychicServer->onNotFound([](PsychicRequest* request)
|
||||
{
|
||||
return request->redirect("/");
|
||||
});
|
||||
}
|
||||
#else
|
||||
#else
|
||||
Log->print(F("Nuki Hub version "));
|
||||
Log->println(NUKI_HUB_VERSION);
|
||||
Log->print(F("Nuki Hub build "));
|
||||
@@ -466,7 +505,7 @@ void setup()
|
||||
|
||||
network = new NukiNetwork(preferences, gpio, mqttLockPath, CharBuffer::get(), buffer_size);
|
||||
network->initialize();
|
||||
|
||||
|
||||
lockEnabled = preferences->getBool(preference_lock_enabled);
|
||||
openerEnabled = preferences->getBool(preference_opener_enabled);
|
||||
|
||||
@@ -477,7 +516,7 @@ void setup()
|
||||
lockEnabled = false;
|
||||
openerEnabled = false;
|
||||
}
|
||||
|
||||
|
||||
bleScanner = new BleScanner::Scanner();
|
||||
// Scan interval and window according to Nuki recommendations:
|
||||
// https://developer.nuki.io/t/bluetooth-specification-questions/1109/27
|
||||
@@ -522,10 +561,13 @@ void setup()
|
||||
{
|
||||
webCfgServer = new WebCfgServer(nuki, nukiOpener, network, gpio, preferences, network->networkDeviceType() == NetworkDeviceType::WiFi, partitionType, psychicServer);
|
||||
webCfgServer->initialize();
|
||||
psychicServer->onNotFound([](PsychicRequest* request) { return request->redirect("/"); });
|
||||
psychicServer->onNotFound([](PsychicRequest* request)
|
||||
{
|
||||
return request->redirect("/");
|
||||
});
|
||||
}
|
||||
/*
|
||||
#ifdef DEBUG_NUKIHUB
|
||||
#ifdef DEBUG_NUKIHUB
|
||||
else psychicServer->onNotFound([](PsychicRequest* request) { return request->redirect("/webserial"); });
|
||||
|
||||
if(preferences->getBool(preference_webserial_enabled, false))
|
||||
@@ -534,21 +576,27 @@ void setup()
|
||||
WebSerial.begin(asyncServer);
|
||||
WebSerial.setBuffer(1024);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if(doOta) setupTasks(true);
|
||||
else setupTasks(false);
|
||||
if(doOta)
|
||||
{
|
||||
setupTasks(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
setupTasks(false);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_NUKIHUB
|
||||
#ifdef DEBUG_NUKIHUB
|
||||
Log->print("Task Name\tStatus\tPrio\tHWM\tTask\tAffinity\n");
|
||||
char stats_buffer[1024];
|
||||
vTaskList(stats_buffer);
|
||||
Log->println(stats_buffer);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
||||
@@ -7,44 +7,44 @@ RTC_NOINIT_ATTR bool criticalEthFailure;
|
||||
extern char WiFi_fallbackDetect[14];
|
||||
|
||||
EthernetDevice::EthernetDevice(const String& hostname, Preferences* preferences, const IPConfiguration* ipConfiguration, const std::string& deviceName, uint8_t phy_addr, int power, int mdc, int mdio, eth_phy_type_t ethtype, eth_clock_mode_t clock_mode)
|
||||
: NetworkDevice(hostname, ipConfiguration),
|
||||
_deviceName(deviceName),
|
||||
_phy_addr(phy_addr),
|
||||
_power(power),
|
||||
_mdc(mdc),
|
||||
_mdio(mdio),
|
||||
_type(ethtype),
|
||||
_clock_mode(clock_mode),
|
||||
_useSpi(false),
|
||||
_preferences(preferences)
|
||||
: NetworkDevice(hostname, ipConfiguration),
|
||||
_deviceName(deviceName),
|
||||
_phy_addr(phy_addr),
|
||||
_power(power),
|
||||
_mdc(mdc),
|
||||
_mdio(mdio),
|
||||
_type(ethtype),
|
||||
_clock_mode(clock_mode),
|
||||
_useSpi(false),
|
||||
_preferences(preferences)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
EthernetDevice::EthernetDevice(const String &hostname,
|
||||
Preferences *preferences,
|
||||
const IPConfiguration *ipConfiguration,
|
||||
const std::string &deviceName,
|
||||
uint8_t phy_addr,
|
||||
int cs,
|
||||
int irq,
|
||||
int rst,
|
||||
int spi_sck,
|
||||
int spi_miso,
|
||||
int spi_mosi,
|
||||
eth_phy_type_t ethtype)
|
||||
: NetworkDevice(hostname, ipConfiguration),
|
||||
_deviceName(deviceName),
|
||||
_phy_addr(phy_addr),
|
||||
_cs(cs),
|
||||
_irq(irq),
|
||||
_rst(rst),
|
||||
_spi_sck(spi_sck),
|
||||
_spi_miso(spi_miso),
|
||||
_spi_mosi(spi_mosi),
|
||||
_type(ethtype),
|
||||
_useSpi(true),
|
||||
_preferences(preferences)
|
||||
Preferences *preferences,
|
||||
const IPConfiguration *ipConfiguration,
|
||||
const std::string &deviceName,
|
||||
uint8_t phy_addr,
|
||||
int cs,
|
||||
int irq,
|
||||
int rst,
|
||||
int spi_sck,
|
||||
int spi_miso,
|
||||
int spi_mosi,
|
||||
eth_phy_type_t ethtype)
|
||||
: NetworkDevice(hostname, ipConfiguration),
|
||||
_deviceName(deviceName),
|
||||
_phy_addr(phy_addr),
|
||||
_cs(cs),
|
||||
_irq(irq),
|
||||
_rst(rst),
|
||||
_spi_sck(spi_sck),
|
||||
_spi_miso(spi_miso),
|
||||
_spi_mosi(spi_mosi),
|
||||
_type(ethtype),
|
||||
_useSpi(true),
|
||||
_preferences(preferences)
|
||||
{
|
||||
init();
|
||||
}
|
||||
@@ -78,7 +78,7 @@ void EthernetDevice::initialize()
|
||||
_hardwareInitialized = ETH.begin(_type, _phy_addr, _cs, _irq, _rst, SPI);
|
||||
criticalEthFailure = false;
|
||||
}
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
else
|
||||
{
|
||||
Log->println(F("Use RMII"));
|
||||
@@ -90,7 +90,7 @@ void EthernetDevice::initialize()
|
||||
_checkIpTs = (esp_timer_get_time() / 1000) + 2000;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if(_hardwareInitialized)
|
||||
{
|
||||
@@ -138,55 +138,56 @@ void EthernetDevice::update()
|
||||
|
||||
void EthernetDevice::onNetworkEvent(arduino_event_id_t event, arduino_event_info_t info)
|
||||
{
|
||||
switch (event) {
|
||||
case ARDUINO_EVENT_ETH_START:
|
||||
Log->println("ETH Started");
|
||||
ETH.setHostname(_hostname.c_str());
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_CONNECTED:
|
||||
Log->println("ETH Connected");
|
||||
if(!localIP().equals("0.0.0.0"))
|
||||
{
|
||||
_connected = true;
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_GOT_IP:
|
||||
Log->printf("ETH Got IP: '%s'\n", esp_netif_get_desc(info.got_ip.esp_netif));
|
||||
Log->println(ETH);
|
||||
|
||||
// For RMII devices, this check is handled in the update() method.
|
||||
if(_useSpi && !_ipConfiguration->dhcpEnabled() && _ipConfiguration->ipAddress() != ETH.localIP())
|
||||
{
|
||||
Log->printf("Static IP not used, retrying to set static IP");
|
||||
ETH.config(_ipConfiguration->ipAddress(), _ipConfiguration->defaultGateway(), _ipConfiguration->subnet(), _ipConfiguration->dnsServer());
|
||||
ETH.begin(_type, _phy_addr, _cs, _irq, _rst, SPI);
|
||||
}
|
||||
|
||||
switch (event)
|
||||
{
|
||||
case ARDUINO_EVENT_ETH_START:
|
||||
Log->println("ETH Started");
|
||||
ETH.setHostname(_hostname.c_str());
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_CONNECTED:
|
||||
Log->println("ETH Connected");
|
||||
if(!localIP().equals("0.0.0.0"))
|
||||
{
|
||||
_connected = true;
|
||||
if(_preferences->getBool(preference_ntw_reconfigure, false))
|
||||
{
|
||||
_preferences->putBool(preference_ntw_reconfigure, false);
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_LOST_IP:
|
||||
Log->println("ETH Lost IP");
|
||||
_connected = false;
|
||||
onDisconnected();
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_DISCONNECTED:
|
||||
Log->println("ETH Disconnected");
|
||||
_connected = false;
|
||||
onDisconnected();
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_STOP:
|
||||
Log->println("ETH Stopped");
|
||||
_connected = false;
|
||||
onDisconnected();
|
||||
break;
|
||||
default:
|
||||
Log->print("ETH Event: ");
|
||||
Log->println(event);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_GOT_IP:
|
||||
Log->printf("ETH Got IP: '%s'\n", esp_netif_get_desc(info.got_ip.esp_netif));
|
||||
Log->println(ETH);
|
||||
|
||||
// For RMII devices, this check is handled in the update() method.
|
||||
if(_useSpi && !_ipConfiguration->dhcpEnabled() && _ipConfiguration->ipAddress() != ETH.localIP())
|
||||
{
|
||||
Log->printf("Static IP not used, retrying to set static IP");
|
||||
ETH.config(_ipConfiguration->ipAddress(), _ipConfiguration->defaultGateway(), _ipConfiguration->subnet(), _ipConfiguration->dnsServer());
|
||||
ETH.begin(_type, _phy_addr, _cs, _irq, _rst, SPI);
|
||||
}
|
||||
|
||||
_connected = true;
|
||||
if(_preferences->getBool(preference_ntw_reconfigure, false))
|
||||
{
|
||||
_preferences->putBool(preference_ntw_reconfigure, false);
|
||||
}
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_LOST_IP:
|
||||
Log->println("ETH Lost IP");
|
||||
_connected = false;
|
||||
onDisconnected();
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_DISCONNECTED:
|
||||
Log->println("ETH Disconnected");
|
||||
_connected = false;
|
||||
onDisconnected();
|
||||
break;
|
||||
case ARDUINO_EVENT_ETH_STOP:
|
||||
Log->println("ETH Stopped");
|
||||
_connected = false;
|
||||
onDisconnected();
|
||||
break;
|
||||
default:
|
||||
Log->print("ETH Event: ");
|
||||
Log->println(event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +213,10 @@ bool EthernetDevice::isApOpen()
|
||||
|
||||
void EthernetDevice::onDisconnected()
|
||||
{
|
||||
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000)) restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000))
|
||||
{
|
||||
restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||
}
|
||||
}
|
||||
|
||||
int8_t EthernetDevice::signalStrength()
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "../Logger.h"
|
||||
|
||||
IPConfiguration::IPConfiguration(Preferences *preferences)
|
||||
: _preferences(preferences)
|
||||
: _preferences(preferences)
|
||||
{
|
||||
if(!dhcpEnabled() && _preferences->getString(preference_ip_address, "").length() <= 0)
|
||||
{
|
||||
@@ -23,10 +23,14 @@ IPConfiguration::IPConfiguration(Preferences *preferences)
|
||||
}
|
||||
else
|
||||
{
|
||||
Log->print(F("IP address: ")); Log->print(ipAddress());
|
||||
Log->print(F(", Subnet: ")); Log->print(subnet());
|
||||
Log->print(F(", Gateway: ")); Log->print(defaultGateway());
|
||||
Log->print(F(", DNS: ")); Log->println(dnsServer());
|
||||
Log->print(F("IP address: "));
|
||||
Log->print(ipAddress());
|
||||
Log->print(F(", Subnet: "));
|
||||
Log->print(subnet());
|
||||
Log->print(F(", Gateway: "));
|
||||
Log->print(defaultGateway());
|
||||
Log->print(F(", DNS: "));
|
||||
Log->println(dnsServer());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
#include "../RestartReason.h"
|
||||
|
||||
WifiDevice::WifiDevice(const String& hostname, Preferences* preferences, const IPConfiguration* ipConfiguration)
|
||||
: NetworkDevice(hostname, ipConfiguration),
|
||||
_preferences(preferences)
|
||||
: NetworkDevice(hostname, ipConfiguration),
|
||||
_preferences(preferences)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -52,10 +52,10 @@ void WifiDevice::initialize()
|
||||
for (int i = 0; i < _foundNetworks; i++)
|
||||
{
|
||||
Log->println(String(F("SSID ")) + WiFi.SSID(i) + String(F(" found with RSSI: ")) +
|
||||
String(WiFi.RSSI(i)) + String(F("(")) +
|
||||
String(constrain((100.0 + WiFi.RSSI(i)) * 2, 0, 100)) +
|
||||
String(F(" %) and BSSID: ")) + WiFi.BSSIDstr(i) +
|
||||
String(F(" and channel: ")) + String(WiFi.channel(i)));
|
||||
String(WiFi.RSSI(i)) + String(F("(")) +
|
||||
String(constrain((100.0 + WiFi.RSSI(i)) * 2, 0, 100)) +
|
||||
String(F(" %) and BSSID: ")) + WiFi.BSSIDstr(i) +
|
||||
String(F(" and channel: ")) + String(WiFi.channel(i)));
|
||||
}
|
||||
|
||||
if (_connectOnScanDone && _foundNetworks > 0)
|
||||
@@ -78,11 +78,13 @@ void WifiDevice::initialize()
|
||||
_preferences->putBool(preference_wifi_converted, true);
|
||||
|
||||
wifi_config_t wifi_cfg;
|
||||
if(esp_wifi_get_config(WIFI_IF_STA, &wifi_cfg) != ESP_OK) {
|
||||
if(esp_wifi_get_config(WIFI_IF_STA, &wifi_cfg) != ESP_OK)
|
||||
{
|
||||
Log->println("Failed to get Wi-Fi configuration in RAM");
|
||||
}
|
||||
|
||||
if (esp_wifi_set_storage(WIFI_STORAGE_FLASH) != ESP_OK) {
|
||||
if (esp_wifi_set_storage(WIFI_STORAGE_FLASH) != ESP_OK)
|
||||
{
|
||||
Log->println("Failed to set storage Wi-Fi");
|
||||
}
|
||||
|
||||
@@ -107,7 +109,8 @@ void WifiDevice::initialize()
|
||||
memset(wifi_cfg.sta.ssid, 0, sizeof(wifi_cfg.sta.ssid));
|
||||
memset(wifi_cfg.sta.password, 0, sizeof(wifi_cfg.sta.password));
|
||||
|
||||
if (esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg) != ESP_OK) {
|
||||
if (esp_wifi_set_config(WIFI_IF_STA, &wifi_cfg) != ESP_OK)
|
||||
{
|
||||
Log->println("Failed to clear NVS Wi-Fi configuration");
|
||||
}
|
||||
|
||||
@@ -159,7 +162,7 @@ void WifiDevice::initialize()
|
||||
|
||||
void WifiDevice::scan(bool passive, bool async)
|
||||
{
|
||||
if(!_connecting)
|
||||
if(!_connecting)
|
||||
{
|
||||
WiFi.scanDelete();
|
||||
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
|
||||
@@ -210,10 +213,10 @@ bool WifiDevice::connect()
|
||||
if (ssid == WiFi.SSID(i))
|
||||
{
|
||||
Log->println(String(F("Saved SSID ")) + ssid + String(F(" found with RSSI: ")) +
|
||||
String(WiFi.RSSI(i)) + String(F("(")) +
|
||||
String(constrain((100.0 + WiFi.RSSI(i)) * 2, 0, 100)) +
|
||||
String(F(" %) and BSSID: ")) + WiFi.BSSIDstr(i) +
|
||||
String(F(" and channel: ")) + String(WiFi.channel(i)));
|
||||
String(WiFi.RSSI(i)) + String(F("(")) +
|
||||
String(constrain((100.0 + WiFi.RSSI(i)) * 2, 0, 100)) +
|
||||
String(F(" %) and BSSID: ")) + WiFi.BSSIDstr(i) +
|
||||
String(F(" and channel: ")) + String(WiFi.channel(i)));
|
||||
if (bestConnection == -1)
|
||||
{
|
||||
bestConnection = i;
|
||||
@@ -232,7 +235,10 @@ bool WifiDevice::connect()
|
||||
{
|
||||
Log->print("No network found with SSID: ");
|
||||
Log->println(ssid);
|
||||
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000)) restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000))
|
||||
{
|
||||
restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||
}
|
||||
_connectOnScanDone = true;
|
||||
_openAP = false;
|
||||
scan(false, true);
|
||||
@@ -243,42 +249,42 @@ bool WifiDevice::connect()
|
||||
_connecting = true;
|
||||
esp_wifi_scan_stop();
|
||||
Log->println(String(F("Trying to connect to SSID ")) + ssid + String(F(" found with RSSI: ")) +
|
||||
String(WiFi.RSSI(bestConnection)) + String(F("(")) +
|
||||
String(constrain((100.0 + WiFi.RSSI(bestConnection)) * 2, 0, 100)) +
|
||||
String(F(" %) and BSSID: ")) + WiFi.BSSIDstr(bestConnection) +
|
||||
String(F(" and channel: ")) + String(WiFi.channel(bestConnection)));
|
||||
|
||||
|
||||
String(WiFi.RSSI(bestConnection)) + String(F("(")) +
|
||||
String(constrain((100.0 + WiFi.RSSI(bestConnection)) * 2, 0, 100)) +
|
||||
String(F(" %) and BSSID: ")) + WiFi.BSSIDstr(bestConnection) +
|
||||
String(F(" and channel: ")) + String(WiFi.channel(bestConnection)));
|
||||
|
||||
|
||||
if(!_ipConfiguration->dhcpEnabled())
|
||||
{
|
||||
WiFi.config(_ipConfiguration->ipAddress(), _ipConfiguration->dnsServer(), _ipConfiguration->defaultGateway(), _ipConfiguration->subnet());
|
||||
}
|
||||
|
||||
|
||||
WiFi.begin(ssid, pass);
|
||||
auto status = WiFi.waitForConnectResult(10000);
|
||||
|
||||
|
||||
switch (status)
|
||||
{
|
||||
case WL_CONNECTED:
|
||||
case WL_CONNECTED:
|
||||
Log->println("WiFi connected");
|
||||
break;
|
||||
case WL_NO_SSID_AVAIL:
|
||||
case WL_NO_SSID_AVAIL:
|
||||
Log->println("WiFi SSID not available");
|
||||
break;
|
||||
case WL_CONNECT_FAILED:
|
||||
case WL_CONNECT_FAILED:
|
||||
Log->println("WiFi connection failed");
|
||||
break;
|
||||
case WL_IDLE_STATUS:
|
||||
case WL_IDLE_STATUS:
|
||||
Log->println("WiFi changing status");
|
||||
break;
|
||||
case WL_DISCONNECTED:
|
||||
case WL_DISCONNECTED:
|
||||
Log->println("WiFi disconnected");
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
Log->println("WiFi timeout");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (status != WL_CONNECTED)
|
||||
{
|
||||
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000))
|
||||
@@ -326,7 +332,7 @@ bool WifiDevice::isConnected()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -350,12 +356,12 @@ void WifiDevice::onDisconnected()
|
||||
_connecting = true;
|
||||
String ssid = _preferences->getString(preference_wifi_ssid, "");
|
||||
String pass = _preferences->getString(preference_wifi_pass, "");
|
||||
|
||||
|
||||
if(!_ipConfiguration->dhcpEnabled())
|
||||
{
|
||||
WiFi.config(_ipConfiguration->ipAddress(), _ipConfiguration->dnsServer(), _ipConfiguration->defaultGateway(), _ipConfiguration->subnet());
|
||||
}
|
||||
|
||||
|
||||
WiFi.begin(ssid, pass);
|
||||
|
||||
int loop = 0;
|
||||
@@ -371,26 +377,29 @@ void WifiDevice::onDisconnected()
|
||||
|
||||
if(!isConnected())
|
||||
{
|
||||
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000)) restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||
if(_preferences->getBool(preference_restart_on_disconnect, false) && ((esp_timer_get_time() / 1000) > 60000))
|
||||
{
|
||||
restartEsp(RestartReason::RestartOnDisconnectWatchdog);
|
||||
}
|
||||
|
||||
WiFi.disconnect(true);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
delay(500);
|
||||
WiFi.disconnect(true);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.disconnect();
|
||||
delay(500);
|
||||
|
||||
wifi_mode_t wifiMode;
|
||||
esp_wifi_get_mode(&wifiMode);
|
||||
wifi_mode_t wifiMode;
|
||||
esp_wifi_get_mode(&wifiMode);
|
||||
|
||||
while (wifiMode != WIFI_MODE_STA || WiFi.status() == WL_CONNECTED)
|
||||
{
|
||||
delay(500);
|
||||
Log->println(F("Waiting for WiFi mode change or disconnection."));
|
||||
esp_wifi_get_mode(&wifiMode);
|
||||
}
|
||||
while (wifiMode != WIFI_MODE_STA || WiFi.status() == WL_CONNECTED)
|
||||
{
|
||||
delay(500);
|
||||
Log->println(F("Waiting for WiFi mode change or disconnection."));
|
||||
esp_wifi_get_mode(&wifiMode);
|
||||
}
|
||||
|
||||
_connectOnScanDone = true;
|
||||
_openAP = false;
|
||||
scan(false, true);
|
||||
_connectOnScanDone = true;
|
||||
_openAP = false;
|
||||
scan(false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,153 +13,153 @@ NetworkDevice *NetworkDeviceInstantiator::Create(NetworkDeviceType networkDevice
|
||||
|
||||
switch (networkDeviceType)
|
||||
{
|
||||
case NetworkDeviceType::W5500:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "Generic W5500",
|
||||
ETH_PHY_ADDR_W5500,
|
||||
ETH_PHY_CS_GENERIC_W5500,
|
||||
ETH_PHY_IRQ_GENERIC_W5500,
|
||||
ETH_PHY_RST_GENERIC_W5500,
|
||||
ETH_PHY_SPI_SCK_GENERIC_W5500,
|
||||
ETH_PHY_SPI_MISO_GENERIC_W5500,
|
||||
ETH_PHY_SPI_MOSI_GENERIC_W5500,
|
||||
ETH_PHY_W5500);
|
||||
break;
|
||||
case NetworkDeviceType::W5500M5:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "M5Stack Atom POE",
|
||||
ETH_PHY_ADDR_W5500,
|
||||
ETH_PHY_CS_M5_W5500,
|
||||
ETH_PHY_IRQ_M5_W5500,
|
||||
ETH_PHY_RST_M5_W5500,
|
||||
ETH_PHY_SPI_SCK_M5_W5500,
|
||||
ETH_PHY_SPI_MISO_M5_W5500,
|
||||
ETH_PHY_SPI_MOSI_M5_W5500,
|
||||
ETH_PHY_W5500);
|
||||
break;
|
||||
case NetworkDeviceType::W5500M5S3:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "M5Stack Atom POE S3",
|
||||
ETH_PHY_ADDR_W5500,
|
||||
ETH_PHY_CS_M5_W5500_S3,
|
||||
ETH_PHY_IRQ_M5_W5500,
|
||||
ETH_PHY_RST_M5_W5500,
|
||||
ETH_PHY_SPI_SCK_M5_W5500_S3,
|
||||
ETH_PHY_SPI_MISO_M5_W5500_S3,
|
||||
ETH_PHY_SPI_MOSI_M5_W5500_S3,
|
||||
ETH_PHY_W5500);
|
||||
break;
|
||||
case NetworkDeviceType::ETH01_Evo:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "ETH01-Evo",
|
||||
ETH_PHY_ADDR_ETH01EVO,
|
||||
ETH_PHY_CS_ETH01EVO,
|
||||
ETH_PHY_IRQ_ETH01EVO,
|
||||
ETH_PHY_RST_ETH01EVO,
|
||||
ETH_PHY_SPI_SCK_ETH01EVO,
|
||||
ETH_PHY_SPI_MISO_ETH01EVO,
|
||||
ETH_PHY_SPI_MOSI_ETH01EVO,
|
||||
ETH_PHY_TYPE_DM9051);
|
||||
break;
|
||||
case NetworkDeviceType::M5STACK_PoESP32_Unit:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "M5STACK PoESP32 Unit",
|
||||
ETH_PHY_ADDR_W5500,
|
||||
ETH_PHY_CS_M5_W5500,
|
||||
ETH_PHY_IRQ_M5_W5500,
|
||||
ETH_PHY_RST_M5_W5500,
|
||||
ETH_PHY_SPI_SCK_M5_W5500,
|
||||
ETH_PHY_SPI_MISO_M5_W5500,
|
||||
ETH_PHY_SPI_MOSI_M5_W5500,
|
||||
ETH_PHY_W5500);
|
||||
break;
|
||||
case NetworkDeviceType::CUSTOM:
|
||||
case NetworkDeviceType::W5500:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "Generic W5500",
|
||||
ETH_PHY_ADDR_W5500,
|
||||
ETH_PHY_CS_GENERIC_W5500,
|
||||
ETH_PHY_IRQ_GENERIC_W5500,
|
||||
ETH_PHY_RST_GENERIC_W5500,
|
||||
ETH_PHY_SPI_SCK_GENERIC_W5500,
|
||||
ETH_PHY_SPI_MISO_GENERIC_W5500,
|
||||
ETH_PHY_SPI_MOSI_GENERIC_W5500,
|
||||
ETH_PHY_W5500);
|
||||
break;
|
||||
case NetworkDeviceType::W5500M5:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "M5Stack Atom POE",
|
||||
ETH_PHY_ADDR_W5500,
|
||||
ETH_PHY_CS_M5_W5500,
|
||||
ETH_PHY_IRQ_M5_W5500,
|
||||
ETH_PHY_RST_M5_W5500,
|
||||
ETH_PHY_SPI_SCK_M5_W5500,
|
||||
ETH_PHY_SPI_MISO_M5_W5500,
|
||||
ETH_PHY_SPI_MOSI_M5_W5500,
|
||||
ETH_PHY_W5500);
|
||||
break;
|
||||
case NetworkDeviceType::W5500M5S3:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "M5Stack Atom POE S3",
|
||||
ETH_PHY_ADDR_W5500,
|
||||
ETH_PHY_CS_M5_W5500_S3,
|
||||
ETH_PHY_IRQ_M5_W5500,
|
||||
ETH_PHY_RST_M5_W5500,
|
||||
ETH_PHY_SPI_SCK_M5_W5500_S3,
|
||||
ETH_PHY_SPI_MISO_M5_W5500_S3,
|
||||
ETH_PHY_SPI_MOSI_M5_W5500_S3,
|
||||
ETH_PHY_W5500);
|
||||
break;
|
||||
case NetworkDeviceType::ETH01_Evo:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "ETH01-Evo",
|
||||
ETH_PHY_ADDR_ETH01EVO,
|
||||
ETH_PHY_CS_ETH01EVO,
|
||||
ETH_PHY_IRQ_ETH01EVO,
|
||||
ETH_PHY_RST_ETH01EVO,
|
||||
ETH_PHY_SPI_SCK_ETH01EVO,
|
||||
ETH_PHY_SPI_MISO_ETH01EVO,
|
||||
ETH_PHY_SPI_MOSI_ETH01EVO,
|
||||
ETH_PHY_TYPE_DM9051);
|
||||
break;
|
||||
case NetworkDeviceType::M5STACK_PoESP32_Unit:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "M5STACK PoESP32 Unit",
|
||||
ETH_PHY_ADDR_W5500,
|
||||
ETH_PHY_CS_M5_W5500,
|
||||
ETH_PHY_IRQ_M5_W5500,
|
||||
ETH_PHY_RST_M5_W5500,
|
||||
ETH_PHY_SPI_SCK_M5_W5500,
|
||||
ETH_PHY_SPI_MISO_M5_W5500,
|
||||
ETH_PHY_SPI_MOSI_M5_W5500,
|
||||
ETH_PHY_W5500);
|
||||
break;
|
||||
case NetworkDeviceType::CUSTOM:
|
||||
{
|
||||
int custPHY = preferences->getInt(preference_network_custom_phy, 0);
|
||||
|
||||
if(custPHY >= 1 && custPHY <= 3)
|
||||
{
|
||||
int custPHY = preferences->getInt(preference_network_custom_phy, 0);
|
||||
std::string custName;
|
||||
eth_phy_type_t custEthtype;
|
||||
|
||||
if(custPHY >= 1 && custPHY <= 3)
|
||||
switch(custPHY)
|
||||
{
|
||||
std::string custName;
|
||||
eth_phy_type_t custEthtype;
|
||||
|
||||
switch(custPHY)
|
||||
{
|
||||
case 1:
|
||||
custName = "Custom (W5500)";
|
||||
custEthtype = ETH_PHY_W5500;
|
||||
break;
|
||||
case 2:
|
||||
custName = "Custom (DN9051)";
|
||||
custEthtype = ETH_PHY_DM9051;
|
||||
break;
|
||||
case 3:
|
||||
custName = "Custom (KSZ8851SNL)";
|
||||
custEthtype = ETH_PHY_KSZ8851;
|
||||
break;
|
||||
default:
|
||||
custName = "Custom (W5500)";
|
||||
custEthtype = ETH_PHY_W5500;
|
||||
break;
|
||||
}
|
||||
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, custName,
|
||||
preferences->getInt(preference_network_custom_addr, -1),
|
||||
preferences->getInt(preference_network_custom_cs, -1),
|
||||
preferences->getInt(preference_network_custom_irq, -1),
|
||||
preferences->getInt(preference_network_custom_rst, -1),
|
||||
preferences->getInt(preference_network_custom_sck, -1),
|
||||
preferences->getInt(preference_network_custom_miso, -1),
|
||||
preferences->getInt(preference_network_custom_mosi, -1),
|
||||
custEthtype);
|
||||
}
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32)
|
||||
else if(custPHY >= 4 && custPHY <= 9)
|
||||
{
|
||||
int custCLKpref = preferences->getInt(preference_network_custom_clk, 0);
|
||||
|
||||
std::string custName = NetworkUtil::GetCustomEthernetDeviceName(custPHY);
|
||||
eth_phy_type_t custEthtype = NetworkUtil::GetCustomEthernetType(custPHY);
|
||||
eth_clock_mode_t custCLK = NetworkUtil::GetCustomClock(custCLKpref);
|
||||
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, custName, preferences->getInt(preference_network_custom_addr, -1), preferences->getInt(preference_network_custom_pwr, -1), preferences->getInt(preference_network_custom_mdc, -1), preferences->getInt(preference_network_custom_mdio, -1), custEthtype, custCLK);
|
||||
}
|
||||
#endif
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
||||
else
|
||||
{
|
||||
device = new WifiDevice(hostname, preferences, ipConfiguration);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32)
|
||||
case NetworkDeviceType::Olimex_LAN8720:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "Olimex (LAN8720)", ETH_PHY_ADDR_LAN8720, 12, ETH_PHY_MDC_LAN8720, ETH_PHY_MDIO_LAN8720, ETH_PHY_TYPE_LAN8720, ETH_CLOCK_GPIO17_OUT);
|
||||
break;
|
||||
case NetworkDeviceType::WT32_LAN8720:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "WT32-ETH01", 1, 16);
|
||||
break;
|
||||
case NetworkDeviceType::GL_S10:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "GL-S10", 1, 5, ETH_PHY_MDC_LAN8720, ETH_PHY_MDIO_LAN8720, ETH_PHY_IP101, ETH_CLOCK_GPIO0_IN);
|
||||
break;
|
||||
case NetworkDeviceType::LilyGO_T_ETH_POE:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "LilyGO T-ETH-POE", 0, -1, ETH_PHY_MDC_LAN8720, ETH_PHY_MDIO_LAN8720, ETH_PHY_TYPE_LAN8720, ETH_CLOCK_GPIO17_OUT);
|
||||
break;
|
||||
#endif
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
||||
case NetworkDeviceType::WiFi:
|
||||
device = new WifiDevice(hostname, preferences, ipConfiguration);
|
||||
break;
|
||||
default:
|
||||
device = new WifiDevice(hostname, preferences, ipConfiguration);
|
||||
break;
|
||||
#else
|
||||
case 1:
|
||||
custName = "Custom (W5500)";
|
||||
custEthtype = ETH_PHY_W5500;
|
||||
break;
|
||||
case 2:
|
||||
custName = "Custom (DN9051)";
|
||||
custEthtype = ETH_PHY_DM9051;
|
||||
break;
|
||||
case 3:
|
||||
custName = "Custom (KSZ8851SNL)";
|
||||
custEthtype = ETH_PHY_KSZ8851;
|
||||
break;
|
||||
default:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "Custom (W5500)",
|
||||
preferences->getInt(preference_network_custom_addr, -1),
|
||||
preferences->getInt(preference_network_custom_cs, -1),
|
||||
preferences->getInt(preference_network_custom_irq, -1),
|
||||
preferences->getInt(preference_network_custom_rst, -1),
|
||||
preferences->getInt(preference_network_custom_sck, -1),
|
||||
preferences->getInt(preference_network_custom_miso, -1),
|
||||
preferences->getInt(preference_network_custom_mosi, -1),
|
||||
ETH_PHY_W5500);
|
||||
break;
|
||||
custName = "Custom (W5500)";
|
||||
custEthtype = ETH_PHY_W5500;
|
||||
break;
|
||||
}
|
||||
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, custName,
|
||||
preferences->getInt(preference_network_custom_addr, -1),
|
||||
preferences->getInt(preference_network_custom_cs, -1),
|
||||
preferences->getInt(preference_network_custom_irq, -1),
|
||||
preferences->getInt(preference_network_custom_rst, -1),
|
||||
preferences->getInt(preference_network_custom_sck, -1),
|
||||
preferences->getInt(preference_network_custom_miso, -1),
|
||||
preferences->getInt(preference_network_custom_mosi, -1),
|
||||
custEthtype);
|
||||
}
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32)
|
||||
else if(custPHY >= 4 && custPHY <= 9)
|
||||
{
|
||||
int custCLKpref = preferences->getInt(preference_network_custom_clk, 0);
|
||||
|
||||
std::string custName = NetworkUtil::GetCustomEthernetDeviceName(custPHY);
|
||||
eth_phy_type_t custEthtype = NetworkUtil::GetCustomEthernetType(custPHY);
|
||||
eth_clock_mode_t custCLK = NetworkUtil::GetCustomClock(custCLKpref);
|
||||
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, custName, preferences->getInt(preference_network_custom_addr, -1), preferences->getInt(preference_network_custom_pwr, -1), preferences->getInt(preference_network_custom_mdc, -1), preferences->getInt(preference_network_custom_mdio, -1), custEthtype, custCLK);
|
||||
}
|
||||
#endif
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
||||
else
|
||||
{
|
||||
device = new WifiDevice(hostname, preferences, ipConfiguration);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32)
|
||||
case NetworkDeviceType::Olimex_LAN8720:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "Olimex (LAN8720)", ETH_PHY_ADDR_LAN8720, 12, ETH_PHY_MDC_LAN8720, ETH_PHY_MDIO_LAN8720, ETH_PHY_TYPE_LAN8720, ETH_CLOCK_GPIO17_OUT);
|
||||
break;
|
||||
case NetworkDeviceType::WT32_LAN8720:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "WT32-ETH01", 1, 16);
|
||||
break;
|
||||
case NetworkDeviceType::GL_S10:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "GL-S10", 1, 5, ETH_PHY_MDC_LAN8720, ETH_PHY_MDIO_LAN8720, ETH_PHY_IP101, ETH_CLOCK_GPIO0_IN);
|
||||
break;
|
||||
case NetworkDeviceType::LilyGO_T_ETH_POE:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "LilyGO T-ETH-POE", 0, -1, ETH_PHY_MDC_LAN8720, ETH_PHY_MDIO_LAN8720, ETH_PHY_TYPE_LAN8720, ETH_CLOCK_GPIO17_OUT);
|
||||
break;
|
||||
#endif
|
||||
#ifndef CONFIG_IDF_TARGET_ESP32H2
|
||||
case NetworkDeviceType::WiFi:
|
||||
device = new WifiDevice(hostname, preferences, ipConfiguration);
|
||||
break;
|
||||
default:
|
||||
device = new WifiDevice(hostname, preferences, ipConfiguration);
|
||||
break;
|
||||
#else
|
||||
default:
|
||||
device = new EthernetDevice(hostname, preferences, ipConfiguration, "Custom (W5500)",
|
||||
preferences->getInt(preference_network_custom_addr, -1),
|
||||
preferences->getInt(preference_network_custom_cs, -1),
|
||||
preferences->getInt(preference_network_custom_irq, -1),
|
||||
preferences->getInt(preference_network_custom_rst, -1),
|
||||
preferences->getInt(preference_network_custom_sck, -1),
|
||||
preferences->getInt(preference_network_custom_miso, -1),
|
||||
preferences->getInt(preference_network_custom_mosi, -1),
|
||||
ETH_PHY_W5500);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -6,50 +6,50 @@ NetworkDeviceType NetworkUtil::GetDeviceTypeFromPreference(int hardwareDetect, i
|
||||
{
|
||||
switch (hardwareDetect)
|
||||
{
|
||||
case 1:
|
||||
case 1:
|
||||
return NetworkDeviceType::WiFi;
|
||||
break;
|
||||
case 2:
|
||||
return NetworkDeviceType::W5500;
|
||||
break;
|
||||
case 3:
|
||||
return NetworkDeviceType::W5500M5;
|
||||
break;
|
||||
case 4:
|
||||
return NetworkDeviceType::Olimex_LAN8720;
|
||||
break;
|
||||
case 5:
|
||||
return NetworkDeviceType::WT32_LAN8720;
|
||||
break;
|
||||
case 6:
|
||||
return NetworkDeviceType::M5STACK_PoESP32_Unit;
|
||||
break;
|
||||
case 7:
|
||||
return NetworkDeviceType::LilyGO_T_ETH_POE;
|
||||
break;
|
||||
case 8:
|
||||
return NetworkDeviceType::GL_S10;
|
||||
break;
|
||||
case 9:
|
||||
return NetworkDeviceType::ETH01_Evo;
|
||||
break;
|
||||
case 10:
|
||||
return NetworkDeviceType::W5500M5S3;
|
||||
break;
|
||||
case 11:
|
||||
if(customPhy> 0)
|
||||
{
|
||||
return NetworkDeviceType::CUSTOM;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NetworkDeviceType::WiFi;
|
||||
break;
|
||||
case 2:
|
||||
return NetworkDeviceType::W5500;
|
||||
break;
|
||||
case 3:
|
||||
return NetworkDeviceType::W5500M5;
|
||||
break;
|
||||
case 4:
|
||||
return NetworkDeviceType::Olimex_LAN8720;
|
||||
break;
|
||||
case 5:
|
||||
return NetworkDeviceType::WT32_LAN8720;
|
||||
break;
|
||||
case 6:
|
||||
return NetworkDeviceType::M5STACK_PoESP32_Unit;
|
||||
break;
|
||||
case 7:
|
||||
return NetworkDeviceType::LilyGO_T_ETH_POE;
|
||||
break;
|
||||
case 8:
|
||||
return NetworkDeviceType::GL_S10;
|
||||
break;
|
||||
case 9:
|
||||
return NetworkDeviceType::ETH01_Evo;
|
||||
break;
|
||||
case 10:
|
||||
return NetworkDeviceType::W5500M5S3;
|
||||
break;
|
||||
case 11:
|
||||
if(customPhy> 0)
|
||||
{
|
||||
return NetworkDeviceType::CUSTOM;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NetworkDeviceType::WiFi;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Log->println(F("Unknown hardware selected, falling back to Wi-Fi."));
|
||||
return NetworkDeviceType::WiFi;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Log->println(F("Unknown hardware selected, falling back to Wi-Fi."));
|
||||
return NetworkDeviceType::WiFi;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,20 +57,20 @@ std::string NetworkUtil::GetCustomEthernetDeviceName(int custPHY)
|
||||
{
|
||||
switch(custPHY)
|
||||
{
|
||||
case 4:
|
||||
return "Custom (LAN8720)";
|
||||
case 5:
|
||||
return"Custom (RTL8201)";
|
||||
case 6:
|
||||
return "Custom (TLK110)";
|
||||
case 7:
|
||||
return "Custom (DP83848)";
|
||||
case 8:
|
||||
return "Custom (KSZ8041)";
|
||||
case 9:
|
||||
return "Custom (KSZ8081)";
|
||||
default:
|
||||
return"Custom (LAN8720)";
|
||||
case 4:
|
||||
return "Custom (LAN8720)";
|
||||
case 5:
|
||||
return"Custom (RTL8201)";
|
||||
case 6:
|
||||
return "Custom (TLK110)";
|
||||
case 7:
|
||||
return "Custom (DP83848)";
|
||||
case 8:
|
||||
return "Custom (KSZ8041)";
|
||||
case 9:
|
||||
return "Custom (KSZ8081)";
|
||||
default:
|
||||
return"Custom (LAN8720)";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,27 +79,27 @@ eth_phy_type_t NetworkUtil::GetCustomEthernetType(int custPHY)
|
||||
{
|
||||
switch(custPHY)
|
||||
{
|
||||
case 4:
|
||||
return ETH_PHY_TYPE_LAN8720;
|
||||
break;
|
||||
case 5:
|
||||
return ETH_PHY_RTL8201;
|
||||
break;
|
||||
case 6:
|
||||
return ETH_PHY_TLK110;
|
||||
break;
|
||||
case 7:
|
||||
return ETH_PHY_DP83848;
|
||||
break;
|
||||
case 8:
|
||||
return ETH_PHY_KSZ8041;
|
||||
break;
|
||||
case 9:
|
||||
return ETH_PHY_KSZ8081;
|
||||
break;
|
||||
default:
|
||||
return ETH_PHY_TYPE_LAN8720;
|
||||
break;
|
||||
case 4:
|
||||
return ETH_PHY_TYPE_LAN8720;
|
||||
break;
|
||||
case 5:
|
||||
return ETH_PHY_RTL8201;
|
||||
break;
|
||||
case 6:
|
||||
return ETH_PHY_TLK110;
|
||||
break;
|
||||
case 7:
|
||||
return ETH_PHY_DP83848;
|
||||
break;
|
||||
case 8:
|
||||
return ETH_PHY_KSZ8041;
|
||||
break;
|
||||
case 9:
|
||||
return ETH_PHY_KSZ8081;
|
||||
break;
|
||||
default:
|
||||
return ETH_PHY_TYPE_LAN8720;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,18 +107,18 @@ eth_clock_mode_t NetworkUtil::GetCustomClock(int custCLKpref)
|
||||
{
|
||||
switch(custCLKpref)
|
||||
{
|
||||
case 0:
|
||||
return ETH_CLOCK_GPIO0_IN;
|
||||
break;
|
||||
case 2:
|
||||
return ETH_CLOCK_GPIO16_OUT;
|
||||
break;
|
||||
case 3:
|
||||
return ETH_CLOCK_GPIO17_OUT;
|
||||
break;
|
||||
default:
|
||||
return ETH_CLOCK_GPIO17_OUT;
|
||||
break;
|
||||
case 0:
|
||||
return ETH_CLOCK_GPIO0_IN;
|
||||
break;
|
||||
case 2:
|
||||
return ETH_CLOCK_GPIO16_OUT;
|
||||
break;
|
||||
case 3:
|
||||
return ETH_CLOCK_GPIO17_OUT;
|
||||
break;
|
||||
default:
|
||||
return ETH_CLOCK_GPIO17_OUT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user