Skip to content

Commit

Permalink
Fix ethernet commissioning for esp32
Browse files Browse the repository at this point in the history
  • Loading branch information
PSONALl committed Mar 30, 2023
1 parent a27bc8c commit 3ca49ff
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/platform/esp32/common/Esp32AppServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ namespace {
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
app::Clusters::NetworkCommissioning::Instance
sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::ESPWiFiDriver::GetInstance()));
#elif CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
static app::Clusters::NetworkCommissioning::Instance
sEthernetNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::ESPEthernetDriver::GetInstance()));
#endif

#if CONFIG_TEST_EVENT_TRIGGER_ENABLED
Expand Down Expand Up @@ -108,6 +111,8 @@ void Esp32AppServer::Init(AppDelegate * sAppDelegate)

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
sWiFiNetworkCommissioningInstance.Init();
#elif CHIP_DEVICE_CONFIG_ENABLE_ETHERNET
sEthernetNetworkCommissioningInstance.Init();
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
if (chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned() &&
Expand Down
2 changes: 2 additions & 0 deletions src/platform/ESP32/ConnectivityManagerImpl_Ethernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ namespace DeviceLayer {

CHIP_ERROR ConnectivityManagerImpl::InitEthernet()
{
// Initialize TCP/IP network interface (should be called only once in application)
ESP_ERROR_CHECK(esp_netif_init());
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
esp_netif_t * eth_netif = esp_netif_new(&cfg);

Expand Down
29 changes: 29 additions & 0 deletions src/platform/ESP32/NetworkCommissioningDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,35 @@ class ESPWiFiDriver final : public WiFiDriver
uint16_t mLastDisconnectedReason;
};

class ESPEthernetDriver final : public EthernetDriver
{
public:
class EthernetNetworkIterator final : public NetworkIterator
{
public:
EthernetNetworkIterator(ESPEthernetDriver * aDriver) : mDriver(aDriver) {}
size_t Count() { return 1; }
bool Next(Network & item) { return true; }
void Release() override { delete this; }
~EthernetNetworkIterator() = default;

private:
ESPEthernetDriver * mDriver;
};

// BaseDriver
NetworkIterator * GetNetworks() override { return new EthernetNetworkIterator(this); }
uint8_t GetMaxNetworks() { return 1; }
CHIP_ERROR Init(NetworkStatusChangeCallback * networkStatusChangeCallback) { return CHIP_NO_ERROR; }
void Shutdown() {}

static ESPEthernetDriver & GetInstance()
{
static ESPEthernetDriver instance;
return instance;
}
};

} // namespace NetworkCommissioning
} // namespace DeviceLayer
} // namespace chip

0 comments on commit 3ca49ff

Please sign in to comment.