Skip to content

Commit

Permalink
esp32 lock-app mdns server start at connectivity change (#7723)
Browse files Browse the repository at this point in the history
  • Loading branch information
DamKast authored and pull[bot] committed Jun 24, 2021
1 parent 678e007 commit 6593069
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/lock-app/esp32/main/DeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "esp_log.h"
#include <app/common/gen/attribute-id.h>
#include <app/common/gen/cluster-id.h>
#include <app/server/Mdns.h>
#include <support/CodeUtils.h>

static const char * TAG = "lock-devicecallbacks";
Expand All @@ -51,6 +52,18 @@ void DeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_
case DeviceEventType::kSessionEstablished:
OnSessionEstablished(event);
break;

case DeviceEventType::kInterfaceIpAddressChanged:
if ((event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV4_Assigned) ||
(event->InterfaceIpAddressChanged.Type == InterfaceIpChangeType::kIpV6_Assigned))
{
// MDNS server restart on any ip assignment: if link local ipv6 is configured, that
// will not trigger a 'internet connectivity change' as there is no internet
// connectivity. MDNS still wants to refresh its listening interfaces to include the
// newly selected address.
chip::app::Mdns::StartServer();
}
break;
}

ESP_LOGI(TAG, "Current free heap: %d\n", heap_caps_get_free_size(MALLOC_CAP_8BIT));
Expand Down Expand Up @@ -80,6 +93,7 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event
if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established)
{
ESP_LOGI(TAG, "Server ready at: %s:%d", event->InternetConnectivityChange.address, CHIP_PORT);
chip::app::Mdns::StartServer();
}
else if (event->InternetConnectivityChange.IPv4 == kConnectivity_Lost)
{
Expand All @@ -88,6 +102,7 @@ void DeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event
if (event->InternetConnectivityChange.IPv6 == kConnectivity_Established)
{
ESP_LOGI(TAG, "IPv6 Server ready...");
chip::app::Mdns::StartServer();
}
else if (event->InternetConnectivityChange.IPv6 == kConnectivity_Lost)
{
Expand Down

0 comments on commit 6593069

Please sign in to comment.