-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IDF v4 Ethernet/Network Fixes #4526
base: main
Are you sure you want to change the base?
Conversation
This requires Tasmota based on v4.4.6. The tests with Tasmota on v4.4.4 were very buggy. This should also improve Ethernet on builds against IDF v3 as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice to see soemone else tackle network code. 😄
While working on ESP-NOW sync I've made quite a few improvements in network logic including fix for detecting Eth disconnect.
I did choose to embrace Arduino events instead.
@@ -169,6 +169,12 @@ int getSignalQuality(int rssi) | |||
return quality; | |||
} | |||
|
|||
#if ESP_IDF_VERSION_MAJOR >= 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went the other way around:
#if defined(ESP8266)
#define ARDUINO_EVENT_WIFI_AP_STADISCONNECTED WIFI_EVENT_SOFTAPMODE_STADISCONNECTED
#define ARDUINO_EVENT_WIFI_AP_STACONNECTED WIFI_EVENT_SOFTAPMODE_STACONNECTED
#define ARDUINO_EVENT_WIFI_STA_GOT_IP WIFI_EVENT_STAMODE_GOT_IP
#define ARDUINO_EVENT_WIFI_STA_CONNECTED WIFI_EVENT_STAMODE_CONNECTED
#define ARDUINO_EVENT_WIFI_STA_DISCONNECTED WIFI_EVENT_STAMODE_DISCONNECTED
#elif defined(ARDUINO_ARCH_ESP32) && !defined(ESP_ARDUINO_VERSION_MAJOR) //ESP_IDF_VERSION_MAJOR==3
// not strictly IDF v3 but Arduino core related
#define ARDUINO_EVENT_WIFI_AP_STADISCONNECTED SYSTEM_EVENT_AP_STADISCONNECTED
#define ARDUINO_EVENT_WIFI_AP_STACONNECTED SYSTEM_EVENT_AP_STACONNECTED
#define ARDUINO_EVENT_WIFI_STA_LOST_IP SYSTEM_EVENT_STA_LOST_IP
#define ARDUINO_EVENT_WIFI_STA_GOT_IP SYSTEM_EVENT_STA_GOT_IP
#define ARDUINO_EVENT_WIFI_STA_CONNECTED SYSTEM_EVENT_STA_CONNECTED
#define ARDUINO_EVENT_WIFI_STA_DISCONNECTED SYSTEM_EVENT_STA_DISCONNECTED
#define ARDUINO_EVENT_WIFI_AP_START SYSTEM_EVENT_AP_START
#define ARDUINO_EVENT_WIFI_AP_STOP SYSTEM_EVENT_AP_STOP
#define ARDUINO_EVENT_WIFI_SCAN_DONE SYSTEM_EVENT_SCAN_DONE
#define ARDUINO_EVENT_ETH_START SYSTEM_EVENT_ETH_START
#define ARDUINO_EVENT_ETH_CONNECTED SYSTEM_EVENT_ETH_CONNECTED
#define ARDUINO_EVENT_ETH_DISCONNECTED SYSTEM_EVENT_ETH_DISCONNECTED
#endif
@coderabbitai review |
✅ Actions performedReview triggered.
|
WalkthroughThe changes update the handling of Ethernet events in the network code. In network.cpp, new event definitions for Ethernet are introduced, and the WiFiEvent function is extended to manage Ethernet events—particularly modifying the action for SYSTEM_EVENT_ETH_GOT_IP and removing some debug output. In wled.cpp, the handleConnection() method now prints a URL with the local IP and prints a distinct message if the connection is via Ethernet, disconnecting WiFi in that case. Changes
Sequence Diagram(s)sequenceDiagram
participant EVT as Event Trigger
participant WF as WiFiEvent handler
participant NW as Network System
EVT->>WF: Network event (e.g., ETH_GOT_IP)
WF->>NW: Check if Ethernet is active
alt Ethernet active and AP inactive
NW-->>WF: Ethernet connected
WF->>NW: Disconnect WiFi
else Both connections active
NW-->>WF: Log message: 'WiFi remains active'
end
sequenceDiagram
participant SYS as System
participant CON as handleConnection()
participant NET as Network Check
SYS->>CON: Connection established
CON->>NET: Determine connection type
alt Connection is Ethernet
NET-->>CON: Ethernet detected
CON->>SYS: Print "Connected! IP address: http://" + IP + " via Ethernet (disabling WiFi)"
CON->>SYS: Disconnect WiFi
else Connection is WiFi
NET-->>CON: WiFi detected
CON->>SYS: Print "Connected! IP address: http://" + IP + " via WiFi"
end
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
wled00/network.cpp (2)
172-177
: Consider using a more comprehensive event mapping approach.The current approach only maps Ethernet events for IDF v4. Consider using a more comprehensive approach that handles all events across different ESP versions and architectures.
Based on past review feedback, consider using this more comprehensive approach:
-#if ESP_IDF_VERSION_MAJOR >= 4 - #define SYSTEM_EVENT_ETH_CONNECTED ARDUINO_EVENT_ETH_CONNECTED - #define SYSTEM_EVENT_ETH_DISCONNECTED ARDUINO_EVENT_ETH_DISCONNECTED - #define SYSTEM_EVENT_ETH_START ARDUINO_EVENT_ETH_START - #define SYSTEM_EVENT_ETH_GOT_IP ARDUINO_EVENT_ETH_GOT_IP -#endif +#if defined(ESP8266) + #define ARDUINO_EVENT_WIFI_AP_STADISCONNECTED WIFI_EVENT_SOFTAPMODE_STADISCONNECTED + #define ARDUINO_EVENT_WIFI_AP_STACONNECTED WIFI_EVENT_SOFTAPMODE_STACONNECTED + #define ARDUINO_EVENT_WIFI_STA_GOT_IP WIFI_EVENT_STAMODE_GOT_IP + #define ARDUINO_EVENT_WIFI_STA_CONNECTED WIFI_EVENT_STAMODE_CONNECTED + #define ARDUINO_EVENT_WIFI_STA_DISCONNECTED WIFI_EVENT_STAMODE_DISCONNECTED +#elif defined(ARDUINO_ARCH_ESP32) && !defined(ESP_ARDUINO_VERSION_MAJOR) + #define ARDUINO_EVENT_WIFI_AP_STADISCONNECTED SYSTEM_EVENT_AP_STADISCONNECTED + #define ARDUINO_EVENT_WIFI_AP_STACONNECTED SYSTEM_EVENT_AP_STACONNECTED + #define ARDUINO_EVENT_WIFI_STA_LOST_IP SYSTEM_EVENT_STA_LOST_IP + #define ARDUINO_EVENT_WIFI_STA_GOT_IP SYSTEM_EVENT_STA_GOT_IP + #define ARDUINO_EVENT_WIFI_STA_CONNECTED SYSTEM_EVENT_STA_CONNECTED + #define ARDUINO_EVENT_WIFI_STA_DISCONNECTED SYSTEM_EVENT_STA_DISCONNECTED + #define ARDUINO_EVENT_WIFI_AP_START SYSTEM_EVENT_AP_START + #define ARDUINO_EVENT_WIFI_AP_STOP SYSTEM_EVENT_AP_STOP + #define ARDUINO_EVENT_WIFI_SCAN_DONE SYSTEM_EVENT_SCAN_DONE + #define ARDUINO_EVENT_ETH_START SYSTEM_EVENT_ETH_START + #define ARDUINO_EVENT_ETH_CONNECTED SYSTEM_EVENT_ETH_CONNECTED + #define ARDUINO_EVENT_ETH_DISCONNECTED SYSTEM_EVENT_ETH_DISCONNECTED +#endif
187-198
: LGTM! Consider adding error handling for WiFi disconnect.The logic for managing WiFi/Ethernet coexistence is well-implemented. However, consider adding error handling for the WiFi disconnect operation.
Consider adding error handling:
case SYSTEM_EVENT_ETH_GOT_IP: if (Network.isEthernet()) { if (!apActive) { DEBUG_PRINTLN(F("WiFi Connected *and* ETH Connected. Disabling WIFi")); - WiFi.disconnect(true); + if (!WiFi.disconnect(true)) { + DEBUG_PRINTLN(F("Failed to disconnect WiFi")); + } } else { DEBUG_PRINTLN(F("WiFi Connected *and* ETH Connected. Leaving AP WiFi active")); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
wled00/network.cpp
(2 hunks)wled00/wled.cpp
(1 hunks)
🔇 Additional comments (1)
wled00/wled.cpp (1)
1013-1023
: LGTM! Clear and informative connection status output.The changes improve user experience by:
- Adding HTTP URL prefix for easy copy-paste
- Clearly indicating the connection type (Ethernet/WiFi)
- Properly handling WiFi/Ethernet coexistence
IDF v4 moves from SYSTEM_EVENT_WIFI_STA_GOT_IP to ARDUINO_EVENT_WIFI_STA_GOT_IP (for example)
Also some improvements to disable WiFi when Ethernet is connected, which ensures things like Art-Net and DDP use the Ethernet connection when present.
Summary by CodeRabbit