Skip to content

Commit

Permalink
Fix ethernet commissioning for esp32 (#25876)
Browse files Browse the repository at this point in the history
  • Loading branch information
PSONALl authored and pull[bot] committed Oct 17, 2023
1 parent 56186d6 commit 1778276
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
5 changes: 4 additions & 1 deletion docs/guides/esp32/build_app_and_commission.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ $ out/debug/chip-tool pairing onnetwork 12345 20202021

Note: In order to commission an ethernet device, from all-clusters-app enable
these config options: select `ESP32-Ethernet-Kit` under `Demo->Device Type` and
select `On-Network` rendezvous mode under `Demo->Rendezvous Mode`
select `On-Network` rendezvous mode under `Demo->Rendezvous Mode`. Currently
default ethernet board supported is IP101, if you want to use other types of
ethernet board then override the current implementation under
`ConnectivityManagerImpl::InitEthernet`

#### Commissioning Parameters

Expand Down
3 changes: 3 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
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 for all Ethernet boards)
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
51 changes: 51 additions & 0 deletions src/platform/ESP32/NetworkCommissioningDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,57 @@ 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) override
{
if (exhausted)
{
return false;
}
exhausted = true;
memcpy(item.networkID, interfaceName, interfaceNameLen);
item.networkIDLen = interfaceNameLen;
item.connected = true;
return true;
}
void Release() override { delete this; }
~EthernetNetworkIterator() = default;

uint8_t interfaceName[kMaxNetworkIDLen];
uint8_t interfaceNameLen = 0;
bool exhausted = false;

private:
ESPEthernetDriver * mDriver;
};

// BaseDriver
NetworkIterator * GetNetworks() override { return new EthernetNetworkIterator(this); }
uint8_t GetMaxNetworks() { return 1; }
CHIP_ERROR Init(NetworkStatusChangeCallback * networkStatusChangeCallback)
{
// TODO: This method can be implemented if Ethernet is used along with Wifi/Thread.
return CHIP_NO_ERROR;
}
void Shutdown()
{
// TODO: This method can be implemented if Ethernet is used along with Wifi/Thread.
}

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

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

0 comments on commit 1778276

Please sign in to comment.