Skip to content

Conversation

@troyhacks
Copy link
Collaborator

@troyhacks troyhacks commented Mar 3, 2025

Fixes for IDFv4 Ethernet

Summary by CodeRabbit

  • New Features

    • Introduced enhanced Ethernet connection detection with clear status notifications.
    • Improved messaging now informs users when a wired connection is active, automatically disabling Wi‑Fi when appropriate.
  • Refactor

    • Streamlined connection management to simplify the transition between network interfaces, offering clearer and more accurate connectivity feedback.

@coderabbitai
Copy link

coderabbitai bot commented Mar 3, 2025

Walkthrough

This update introduces new Ethernet event definitions and corresponding logic adjustments. In network.cpp, new Ethernet events are defined and handled within the WiFiEvent function, including conditional disconnection of WiFi based on the active state of Ethernet and the access point. In wled.cpp, the handleConnection method is updated to print the local IP without a newline and then differentiate between Ethernet and WiFi connections—disabling WiFi when Ethernet is detected—while streamlining legacy code.

Changes

File(s) Change Summary
wled00/network.cpp Added Ethernet system event definitions (ETH_CONNECTED, ETH_DISCONNECTED, ETH_START, ETH_GOT_IP) and updated WiFiEvent handling with conditional logic.
wled00/wled.cpp Updated handleConnection to print the local IP (without a newline), differentiate between Ethernet and WiFi connections, disable WiFi when Ethernet is active, and removed redundant commented-out code.

Sequence Diagram(s)

sequenceDiagram
    participant ESP as ESP-IDF
    participant Event as WiFiEvent Handler
    participant Logger as Logger
    participant WiFi as WiFi Module

    ESP->>Event: SYSTEM_EVENT_ETH_GOT_IP
    alt Ethernet active & AP inactive
        Event->>WiFi: Invoke WiFi.disconnect()
        Event->>Logger: Log disconnection message
    else Ethernet active & AP active
        Event->>Logger: Log dual connection active message
    else No Ethernet
        Event->>Logger: Log WiFi-only connection status
    end
Loading
sequenceDiagram
    participant WLED as WLED Class
    participant Logger as Logger
    participant WiFi as WiFi Module

    WLED->>Logger: Print local IP (no newline)
    alt Connection is Ethernet
        WLED->>Logger: Log "Ethernet connection, disabling WiFi"
        WLED->>WiFi: Call WiFi.disconnect(true)
    else Connection via WiFi
        WLED->>Logger: Log "Connection via WiFi"
    end
Loading

Poem

Hey there, I'm Bunny, hopping with delight,
New events and logic keep the network light.
Ethernet and WiFi now share the show,
Disconnections and logs make the system flow.
In this garden of code, I skip free and true,
Celebrating change with a joyful "boing" and a leap too!
🐇🌟💻

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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 (1)
wled00/network.cpp (1)

179-190: Improved Ethernet connection handling logic.

The updated ETH_GOT_IP event handler now includes proper detection and management of WiFi and Ethernet coexistence:

  1. It checks if the network is actually using Ethernet
  2. It conditionally disconnects WiFi when Ethernet is connected (unless AP is active)
  3. It provides clear debug messages about the connection state

This approach reduces power consumption and potential conflicts when both connection types are available.

Consider adding a user configurable option to control whether WiFi should be automatically disabled when Ethernet is connected. This would give users flexibility in network setup (e.g., using WiFi as a fallback or for specific services).

 if (Network.isEthernet()) {
   if (!apActive) {
     DEBUG_PRINTLN(F("WiFi Connected *and* ETH Connected. Disabling WIFi"));
+    // Only disconnect if auto-disconnect is enabled (could be a user preference)
+    if (autoDisableWiFi) // New configurable option
     WiFi.disconnect(true);
   } else {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e9d07d6 and 43bbd10.

📒 Files selected for processing (2)
  • wled00/network.cpp (2 hunks)
  • wled00/wled.cpp (1 hunks)
🔇 Additional comments (2)
wled00/network.cpp (1)

164-169: Adding ESP-IDF v4 compatibility for Ethernet events.

These definitions map the ESP-IDF v4 ARDUINO_EVENT_* constants to SYSTEM_EVENT_* constants for Ethernet-related events, ensuring compatibility across different ESP-IDF versions.

wled00/wled.cpp (1)

1373-1381: Improved connection feedback and Ethernet handling.

The updated code now:

  1. Differentiates between Ethernet and WiFi connections in the user output
  2. Disables WiFi when Ethernet is connected (on ESP32 only)
  3. Provides clearer messaging about the active connection type

This implementation aligns with the WiFiEvent handler changes in network.cpp, ensuring consistent behavior.

@troyhacks troyhacks changed the title IDF v4 Ethernet Fixes Ethernet Fixes IDFv4 Mar 3, 2025
@netmindz netmindz merged commit 25c355b into MoonModules:mdev Jun 29, 2025
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants