Skip to content

Commit 8c5ae3c

Browse files
committed
More fixes
1 parent 2085bbe commit 8c5ae3c

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

libraries/Ethernet/examples/ETH_LAN8720/ETH_LAN8720.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
static bool eth_connected = false;
1818

1919
// WARNING: WiFiEvent is called from a separate FreeRTOS task (thread)!
20-
void WiFiEvent(WiFiEvent_t event)
20+
void onEvent(arduino_event_id_t event)
2121
{
2222
switch (event) {
2323
case ARDUINO_EVENT_ETH_START:

libraries/Ethernet/src/ETH.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,30 @@ static void _eth_event_cb(void* arg, esp_event_base_t event_base, int32_t event_
5959
}
6060
}
6161

62+
static void onEthConnected(arduino_event_id_t event, arduino_event_info_t info)
63+
{
64+
if(event == ARDUINO_EVENT_ETH_CONNECTED){
65+
uint8_t index = 3;
66+
for (int i = 0; i < 3; ++i) {
67+
if(_ethernets[i] != NULL && _ethernets[i]->handle() == info.eth_connected){
68+
index = i;
69+
break;
70+
}
71+
}
72+
if(index == 3){
73+
return;
74+
}
75+
if (Network.getStatusBits() & ETH_WANT_IP6_BIT(index)){
76+
esp_err_t err = esp_netif_create_ip6_linklocal(_ethernets[index]->netif());
77+
if(err != ESP_OK){
78+
log_e("Failed to enable IPv6 Link Local on ETH: [%d] %s", err, esp_err_to_name(err));
79+
} else {
80+
log_v("Enabled IPv6 Link Local on %s", _ethernets[index]->desc());
81+
}
82+
}
83+
}
84+
}
85+
6286
esp_eth_handle_t ETHClass::handle(){
6387
return _eth_handle;
6488
}
@@ -93,15 +117,8 @@ void ETHClass::_onEthEvent(int32_t event_id, void* event_data){
93117

94118
if (event_id == ETHERNET_EVENT_CONNECTED) {
95119
log_v("%s Connected", desc());
96-
if (Network.getStatusBits() & ETH_WANT_IP6_BIT(_eth_index)){
97-
esp_err_t err = esp_netif_create_ip6_linklocal(_esp_netif);
98-
if(err != ESP_OK){
99-
log_e("Failed to enable IPv6 Link Local on ETH: [%d] %s", err, esp_err_to_name(err));
100-
} else {
101-
log_v("Enabled IPv6 Link Local on %s", desc());
102-
}
103-
}
104120
arduino_event.event_id = ARDUINO_EVENT_ETH_CONNECTED;
121+
arduino_event.event_info.eth_connected = handle();
105122
Network.setStatusBits(ETH_CONNECTED_BIT(_eth_index));
106123
} else if (event_id == ETHERNET_EVENT_DISCONNECTED) {
107124
log_v("%s Disconnected", desc());
@@ -310,6 +327,9 @@ bool ETHClass::begin(eth_phy_type_t type, uint8_t phy_addr, int mdc, int mdio, i
310327
if(_pin_power != -1){
311328
if(!perimanSetPinBus(_pin_power, ESP32_BUS_TYPE_ETHERNET_PWR, (void *)(this), -1, -1)){ goto err; }
312329
}
330+
331+
Network.onEvent(onEthConnected, ARDUINO_EVENT_ETH_CONNECTED);
332+
313333
// holds a few milliseconds to let DHCP start and enter into a good state
314334
// FIX ME -- adresses issue https://github.com/espressif/arduino-esp32/issues/5733
315335
delay(50);
@@ -697,6 +717,8 @@ bool ETHClass::beginSPI(eth_phy_type_t type, uint8_t phy_addr, int cs, int irq,
697717
if(!perimanSetPinBus(_pin_rst, ESP32_BUS_TYPE_ETHERNET_SPI, (void *)(this), -1, -1)){ goto err; }
698718
}
699719

720+
Network.onEvent(onEthConnected, ARDUINO_EVENT_ETH_CONNECTED);
721+
700722
return true;
701723

702724
err:

libraries/Networking/src/ESP_Network_Events.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ static const int ETH0_HAS_IP6_BIT = BIT29;
6060
static const int ETH1_HAS_IP6_BIT = BIT30;
6161
static const int ETH2_HAS_IP6_BIT = BIT31;
6262
// Masks
63-
static const int NET_HAS_IP6_GLOBAL_BIT = STA_HAS_IP6_GLOBAL_BIT | ETH0_HAS_IP6_GLOBAL_BIT | ETH1_HAS_IP6_GLOBAL_BIT | ETH2_HAS_IP6_GLOBAL_BIT;
63+
static const int NET_HAS_IP6_GLOBAL_BIT = ETH0_HAS_IP6_GLOBAL_BIT | ETH1_HAS_IP6_GLOBAL_BIT | ETH2_HAS_IP6_GLOBAL_BIT
64+
#if SOC_WIFI_SUPPORTED
65+
| STA_HAS_IP6_GLOBAL_BIT
66+
#endif
67+
;
6468

6569
#define ETH_STARTED_BIT(i) (ETH0_STARTED_BIT << (i))
6670
#define ETH_CONNECTED_BIT(i) (ETH0_CONNECTED_BIT << (i))

libraries/WebServer/examples/WebServer/WebServer.ino

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#include <Arduino.h>
3131
#include <WebServer.h>
32+
#include <WiFi.h>
3233

3334
#include "secrets.h" // add WLAN Credentials in here.
3435

0 commit comments

Comments
 (0)