Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/NetworkModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ void NetworkModule::loadSettings()
length = 0; // will update by write
knx.bau().propertyValueWrite(OT_IP_PARAMETER, 0, PID_FRIENDLY_NAME, elements, 1, friendlyNameWrite, 0);
}
// propertyValueRead() allocated friendlyNameRead via new[] -> free it.
if (friendlyNameRead != nullptr)
delete[] friendlyNameRead;
}

if (_useStaticIP)
Expand Down Expand Up @@ -236,8 +239,22 @@ void NetworkModule::esp32NetworkEvent(CALLBACK_EVENT event)
break;
case ARDUINO_EVENT_ETH_GOT_IP:
case ARDUINO_EVENT_WIFI_STA_GOT_IP:
{
IPAddress ip = localIP();
logDebugP("Event: Got IP");
controlKnxIp(true);
// Rebind multicast only on real IP change (avoid heap churn on lease renew).
if (ip != _boundIp)
{
controlKnxIp(false);
controlKnxIp(true);
_boundIp = ip;
}
break;
}
case ARDUINO_EVENT_ETH_LOST_IP:
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
logDebugP("Event: Lost IP");
controlKnxIp(false);
break;
case ARDUINO_EVENT_ETH_DISCONNECTED:
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
Expand Down Expand Up @@ -427,6 +444,11 @@ void NetworkModule::checkLinkStatus()

// Get current network state
bool establishedState = established();

// Keep KNX-IP datalink in lockstep with link/IP (idempotent). Recovers the
// case where GOT_IP doesn't re-fire after a link flap -> datalink stuck off.
controlKnxIp(establishedState);

bool newLinkState;
if (establishedState)
newLinkState = true;
Expand Down
1 change: 1 addition & 0 deletions src/NetworkModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class NetworkModule : public OpenKNX::Module
IPAddress _staticSubnetMask;
IPAddress _staticGatewayIP;
IPAddress _staticNameServerIP;
IPAddress _boundIp; // last IP the KNX multicast socket was bound to (rebind only on change)

#ifdef ARDUINO_ARCH_ESP32
bool espConnected = false;
Expand Down