Skip to content

Conversation

@AdrianSoundy
Copy link
Member

@AdrianSoundy AdrianSoundy commented Mar 14, 2025

Description

This has been an issue since the IDF changed from TCPIP adapters to the ESP_NETIF interface.
The problem is the ESP_NETIF starts the DHCP when the WIFI connects overriding the static IP settings.

This change updates IP addresses in ESP_NETIF by call esp_netif_set_ip_info() for Ethernet & Wireless networks.
Also tidies up code by moving common code to new file NF_ESP32_Network.cpp

Also fixes issue where network stops working on starting a VS debug session.

Motivation and Context

How Has This Been Tested?

  • Some testing was done at the time these changes where done.
    Further testing should be done to confirm chnage is working correctly.
  • Reported working as expected by community members.

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dev Containers (changes related with Dev Containers, has no impact on code or features)
  • Dependencies/declarations (update dependencies or assembly declarations and changes associated, has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).

Summary by CodeRabbit

  • New Features

    • Enhanced ESP32 networking with static IP configuration support for Ethernet and Wi-Fi station interfaces.
    • Introduced new utilities for retrieving and applying network configuration blocks by index.
    • Added ESP32-specific adapter configuration handling, including DHCP and DNS management.
  • Refactor

    • Replaced error handling in Ethernet initialization to prevent aborts on recoverable errors.
    • Removed redundant network interface waiting loops for improved initialization efficiency.
  • Documentation

    • Added declarations for new network configuration and interface mapping functions in ESP32 network headers.

@nfbot nfbot changed the title Update IP addresses in ESP_NETIF to stop static addresses being overwritten. Update IP addresses in ESP_NETIF to stop static addresses being overwritten Mar 14, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 14, 2025

Walkthrough

This update integrates new ESP32 network configuration functionality. A new source file is added to the ESP32 networking build list and implements functions to retrieve network configuration blocks, configure network settings, and apply settings by index. The Ethernet event handler now applies static IP configuration upon connection. The wireless initialization applies static IP configuration for the Wi-Fi station interface. The Ethernet code replaces error aborts with non-aborting checks. The LWIP sockets driver is extended with an ESP32-specific network configuration update method. Corresponding header declarations are added.

Changes

File(s) Change Summary
targets/ESP32/.../CMakeLists.txt Added NF_ESP32_Network.cpp to the ESP32 networking source files list.
targets/ESP32/_Network/NF_ESP32_Ethernet.cpp Replaced ESP_ERROR_CHECK with ESP_ERROR_CHECK_WITHOUT_ABORT in Ethernet initialization to avoid aborting on errors.
targets/ESP32/_Network/NF_ESP32_Network.cpp
targets/ESP32/_include/NF_ESP32_Network.h
Added new networking utility functions: NF_ESP32_GetEspNetif, NF_ESP32_Wait_NetNumber, NF_ESP32_GetNetworkConfigBlock, and NF_ESP32_ConfigureNetworkByConfigIndex with declarations.
targets/ESP32/_Network/NF_ESP32_Wireless.cpp Removed NF_ESP32_Wait_NetNumber function; added call to NF_ESP32_ConfigureNetworkByConfigIndex for Wi-Fi station interface in initialization with error logging.
targets/ESP32/_common/targetHAL_Network.cpp Added call to NF_ESP32_ConfigureNetworkByConfigIndex in Ethernet event handler on ETHERNET_EVENT_CONNECTED before posting availability.
src/PAL/Lwip/lwIP_Sockets.cpp Added ESP32-specific implementation of LWIP_SOCKETS_Driver::UpdateAdapterConfiguration using ESP-IDF APIs for DHCP, DNS, MAC, and IP updates; original implementation unchanged for other platforms.

Assessment against linked issues

Objective Addressed Explanation
Wifi Static IP assignment does not work (Issue #1087) Static IP configuration applied via new network config functions and invoked during Wi-Fi and Ethernet initialization.

Suggested labels

Platform: ESP32

Suggested reviewers

  • josesimoes

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 183cc5c and f1da0d4.

📒 Files selected for processing (1)
  • src/PAL/Lwip/lwIP_Sockets.cpp (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/PAL/Lwip/lwIP_Sockets.cpp
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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
Contributor

@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: 3

🧹 Nitpick comments (2)
targets/ESP32/_Network/NF_ESP32_Ethernet.cpp (1)

222-223: Implementation looks good for configuring static addresses

The new code addresses the PR objective by calling NF_ESP32_ConfigureNetworkByIndex to configure static IP addresses before starting the Ethernet driver, which should prevent them from being overwritten by DHCP.

Consider adding error logging here similar to what's in the Wireless implementation for consistency:

- ESP_ERROR_CHECK(NF_ESP32_ConfigureNetworkByIndex(IDF_ETH_DEF, eth_netif));
+ esp_err_t ec = NF_ESP32_ConfigureNetworkByIndex(IDF_ETH_DEF, eth_netif);
+ if (ec != ESP_OK) 
+ {               
+     ESP_LOGE(TAG, "Unable to configure Ethernet - result %d", ec);
+ }
targets/ESP32/_Network/NF_ESP32_Network.cpp (1)

38-42: Improve error handling in default case

The comment "can't reach here" is misleading since the default case can be reached with an invalid network interface number. Consider logging the invalid number and returning an error code.

default:
-   // can't reach here
-   HAL_AssertEx();
+   // Invalid network interface number
+   DEBUG_PRINT("Invalid network interface number: %d\n", num);
+   return -1;
    break;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6492d91 and d150ff7.

📒 Files selected for processing (5)
  • targets/ESP32/_Network/CMakeLists.txt (1 hunks)
  • targets/ESP32/_Network/NF_ESP32_Ethernet.cpp (1 hunks)
  • targets/ESP32/_Network/NF_ESP32_Network.cpp (1 hunks)
  • targets/ESP32/_Network/NF_ESP32_Wireless.cpp (2 hunks)
  • targets/ESP32/_include/NF_ESP32_Network.h (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: nf-interpreter (Check_Code_Style)
  • GitHub Check: nf-interpreter (Check_Build_Options)
  • GitHub Check: nf-interpreter (Nightly build) (Check_Build_Options)
🔇 Additional comments (6)
targets/ESP32/_Network/CMakeLists.txt (1)

14-14: Correctly adds the new network file to the build

This change properly adds the new NF_ESP32_Network.cpp file to the build, aligning with the PR objective of moving common code into a dedicated file.

targets/ESP32/_include/NF_ESP32_Network.h (1)

63-65: New function declarations look good

These new function declarations support the PR objective by providing proper interfaces for retrieving network configuration blocks and applying network settings to prevent static addresses from being overwritten.

targets/ESP32/_Network/NF_ESP32_Wireless.cpp (2)

115-118: Helper function implementation looks good

This new function provides a clean, dedicated way to configure the Wi-Fi station with the correct network index.


163-169: Error handling for network configuration looks good

This implementation properly checks for errors when configuring the Wi-Fi station and logs them appropriately, helping with debugging if there are issues with static IP configuration.

targets/ESP32/_Network/NF_ESP32_Network.cpp (2)

55-69: Memory allocation handling is well implemented

The function properly checks for memory allocation failures and configuration retrieval errors, returning NULL in both cases. This allows the caller to handle errors appropriately.


103-118: Proper memory management in NF_ESP32_ConfigureNetworkByIndex

The function correctly frees the allocated memory for the network configuration block after use, which prevents memory leaks.

@AdrianSoundy
Copy link
Member Author

@alberk8 Are you able to test this is working OK.
I did this change a while ago and got distracted with something else so PR was never raised. This has now been rebased with current version and should still be OK. I am currently away so can't complete it for a couple of weeks.

Copy link
Contributor

@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: 1

♻️ Duplicate comments (2)
targets/ESP32/_Network/NF_ESP32_Network.cpp (2)

11-53: 🛠️ Refactor suggestion

Add a timeout for the infinite loop in NF_ESP32_Wait_NetNumber.
At present, if the requested interface is never created, the loop can block indefinitely. Consider implementing a max retry count or timeout to prevent the application from hanging.

 int NF_ESP32_Wait_NetNumber(int num)
 {
     esp_netif_t *espNetif = nullptr;
+    const int maxRetries = 1500; // e.g. 1500 * 20ms = 30 seconds
+    int retryCount = 0;

     while (true)
     {
         // ...
         if (espNetif != NULL)
         {
             break;
         }

         vTaskDelay(20 / portTICK_PERIOD_MS);
+        if (++retryCount >= maxRetries)
+        {
+            return -1; // Indicate failure
+        }
     }

     return espNetif->lwip_netif->num;
 }

74-101: 🛠️ Refactor suggestion

Use official DHCP APIs rather than manipulating netIf->flags.
Disabling DHCP by modifying netIf->flags directly can be fragile. The ESP-IDF recommends using esp_netif_dhcpc_stop() or esp_netif_dhcpc_start() for robust DHCP control. Additionally, if enableDHCP is true, you may want to explicitly enable the DHCP client.

bool enableDHCP = (config->StartupAddressMode == AddressMode_DHCP);

// If DHCP is enabled, start the DHCP client
+if (enableDHCP) {
+    ec = esp_netif_dhcpc_start(netIf);
+    if (ec != ESP_OK && ec != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED) {
+        return ec;
+    }
+} else {
    // Set static addresses
    if (config->IPv4Address != 0)
    {
        ip_info.ip.addr = config->IPv4Address;
        ip_info.netmask.addr = config->IPv4NetMask;
        ip_info.gw.addr = config->IPv4GatewayAddress;

        ec = esp_netif_set_ip_info(netIf, &ip_info);

-       netIf->flags = (esp_netif_flags_t)(netIf->flags & ~ESP_NETIF_DHCP_CLIENT);
+       // Stop DHCP client if configured for static IP
+       esp_err_t dhcpStop = esp_netif_dhcpc_stop(netIf);
+       if (dhcpStop != ESP_OK && dhcpStop != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED)
+       {
+           return dhcpStop;
+       }
    }
}
🧹 Nitpick comments (2)
targets/ESP32/_Network/NF_ESP32_Wireless.cpp (1)

163-169: Revisit the 'ignore any errors' comment.
Although the inline comment states to ignore errors, the code does log errors when ec != ESP_OK. If these unexpected failures need follow-up actions (e.g. disabling further Wi-Fi initialization steps or reverting to DHCP), you might consider more robust handling instead of continuing with partial configuration.

targets/ESP32/_Network/NF_ESP32_Network.cpp (1)

103-118: Validate the final result after configuration.
This function retrieves a network configuration block, applies it, and frees the block. Consider logging or confirming that the new IP configuration is successfully set. Adding a short verification step (like another esp_netif_get_ip_info() call) could help catch subtle runtime issues.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d150ff7 and 4a069e5.

📒 Files selected for processing (3)
  • targets/ESP32/_Network/NF_ESP32_Network.cpp (1 hunks)
  • targets/ESP32/_Network/NF_ESP32_Wireless.cpp (2 hunks)
  • targets/ESP32/_include/NF_ESP32_Network.h (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • targets/ESP32/_include/NF_ESP32_Network.h
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: nf-interpreter (Check_Code_Style)
  • GitHub Check: nf-interpreter (Nightly build) (Check_Build_Options)
  • GitHub Check: nf-interpreter (Check_Build_Options)
🔇 Additional comments (1)
targets/ESP32/_Network/NF_ESP32_Wireless.cpp (1)

115-118:

❓ Verification inconclusive

Consider explicit handling of station mode checks.
While this function successfully delegates configuration to NF_ESP32_ConfigureNetworkByIndex, ensure that the caller only invokes it if the device is indeed in station mode. If future code calls this outside station mode contexts, it might lead to unexpected results or error logs.

Would you like to verify that this function is only called for station interfaces by searching the codebase for its invocations and ensuring the associated logic?


🏁 Script executed:

#!/bin/bash
rg -A 4 "NF_ESP32_ConfigureNetworkStation"

Length of output: 828


Action: Confirm Explicit Station Mode Validation for NF_ESP32_ConfigureNetworkStation

We verified that the only identifiable invocation of this function is made with a variable named wifiStaNetif in targets/ESP32/_Network/NF_ESP32_Wireless.cpp, suggesting that it is intended for station mode configurations. However, there is no explicit check within the function (or immediately before its invocation) that confirms the provided interface indeed belongs to station mode. To guard against potential misuse from future changes, please consider adding an explicit validation step—either here or at the caller—to ensure that the function is only used with station interfaces.

  • File under review: targets/ESP32/_Network/NF_ESP32_Wireless.cpp
  • Identified call site: Invocation using wifiStaNetif without an accompanying station mode check

@AdrianSoundy
Copy link
Member Author

There are some useful suggestions coming out of coderabbitai for existing code but I don't have time at the moment to follow them up. I can do that once I am back from holiday.

Copy link
Contributor

@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

♻️ Duplicate comments (2)
targets/ESP32/_Network/NF_ESP32_Network.cpp (2)

95-96: ⚠️ Potential issue

Handle DHCP enablement as previously recommended.

This logic assigns enableDHCP but never starts the DHCP client. A past comment already addressed this omission. When enableDHCP is true, ensure you invoke esp_netif_dhcpc_start() to enable the DHCP client.

Consider applying the following diff:

 bool enableDHCP = (config->StartupAddressMode == AddressMode_DHCP);

+ if (enableDHCP)
+ {
+     ec = esp_netif_dhcpc_start(netIf);
+     if (ec != ESP_OK && ec != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED)
+     {
+         return ec;
+     }
+ }

107-107: ⚠️ Potential issue

Avoid direct flag manipulation to stop DHCP, as previously advised.

This line is still directly modifying netIf->flags to disable the DHCP client. Per the ESP-IDF guidelines, use esp_netif_dhcpc_stop(netIf) instead to improve reliability and forward compatibility.

Example fix:

- netIf->flags = (esp_netif_flags_t)(netIf->flags & ~ESP_NETIF_DHCP_CLIENT);
+ ec = esp_netif_dhcpc_stop(netIf);
+ // It's okay if DHCP was already stopped
+ if (ec != ESP_OK && ec != ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED)
+ {
+     return ec;
+ }
🧹 Nitpick comments (1)
targets/ESP32/_Network/NF_ESP32_Network.cpp (1)

98-106: Validate static address settings to avoid invalid configurations.

If a static IP is required (enableDHCP == false) yet config->IPv4Address is 0, no valid IP info gets applied. Consider warning or handling this edge case to prevent silently misconfigured interfaces.

Example approach:

 bool enableDHCP = (config->StartupAddressMode == AddressMode_DHCP);

 // Set static addresses
 if (config->IPv4Address != 0)
 {
+    // Optionally validate these addresses before applying
     ip_info.ip.addr = config->IPv4Address;
     ip_info.netmask.addr = config->IPv4NetMask;
     ip_info.gw.addr = config->IPv4GatewayAddress;
 }
+else if (!enableDHCP)
+{
+    // Log warning or handle the scenario where the user specified static mode
+    // but didn't provide valid static IP data
+    // e.g. ESP_LOGW("NF_ESP32_Network", "No static IP configured in static mode");
+}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4a069e5 and 1a1aea9.

📒 Files selected for processing (1)
  • targets/ESP32/_Network/NF_ESP32_Network.cpp (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: nf-interpreter (Check_Code_Style)
  • GitHub Check: nf-interpreter (Nightly build) (Check_Build_Options)
  • GitHub Check: nf-interpreter (Check_Build_Options)

@alberk8
Copy link
Contributor

alberk8 commented Mar 16, 2025

@AdrianSoundy , I have tested on ESP32 with WIFI and it still using Router DHCP IP. The output shows the static IP that is set but checking with the router interface it shows that the actual IP is 192.168.1.97, it does not seems to respond to ping.

 bool isConnected = false;

 IPConfiguration ipconfig = new IPConfiguration("192.168.1.153", "255.255.255.0", "192.168.1.1", new string[] { "192.168.1.1" });

 isConnected = WifiNetworkHelper.ConnectFixAddress(_ssid, _password, ipconfig, WifiReconnectionKind.Automatic, requiresDateTime: true, token: cancelToken.Token);

 Console.WriteLine("Connected to Wifi: " + isConnected + " Date: " + DateTime.UtcNow.ToString());
 if (isConnected)
 {
     var networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0];
     var ipAddress = networkInterface.IPv4Address.ToString();
     Debug.WriteLine("IP Address: " + ipAddress);
 }

Output
Connected to Wifi: True Date: 01/01/1970 00:17:32
IP Address: 192.168.1.153

@networkfusion
Copy link
Member

@AdrianSoundy , I have tested on ESP32 with WIFI and it still using Router DHCP IP. The output shows the static IP that is set but checking with the router interface it shows that the actual IP is 192.168.1.97, it does not seems to respond to ping.

 bool isConnected = false;

 IPConfiguration ipconfig = new IPConfiguration("192.168.1.153", "255.255.255.0", "192.168.1.1", new string[] { "192.168.1.1" });

 isConnected = WifiNetworkHelper.ConnectFixAddress(_ssid, _password, ipconfig, WifiReconnectionKind.Automatic, requiresDateTime: true, token: cancelToken.Token);

 Console.WriteLine("Connected to Wifi: " + isConnected + " Date: " + DateTime.UtcNow.ToString());
 if (isConnected)
 {
     var networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0];
     var ipAddress = networkInterface.IPv4Address.ToString();
     Debug.WriteLine("IP Address: " + ipAddress);
 }

Output Connected to Wifi: True Date: 01/01/1970 00:17:32 IP Address: 192.168.1.153

It is possible that the router is caching the IP for the default 24 hour period, and it is not forcing it?!

@alberk8
Copy link
Contributor

alberk8 commented Mar 17, 2025

No, I reboot everything and the ESP32 in question was not not connected to the router for more than 3 days.

@AdrianSoundy
Copy link
Member Author

AdrianSoundy commented Mar 17, 2025

No, I reboot everything and the ESP32 in question was not connected to the router for more than 3 days.

Thanks for testing. I can't look at this until I am back in NZ around 30th March. Currently in Australia.
I know I did do some testing and it seemed to be working.

Copy link
Member

@josesimoes josesimoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wait for Adrian to get a chance to test this again.

AdrianSoundy and others added 2 commits July 22, 2025 11:15
Copy link
Contributor

@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: 4

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6261fb2 and dd07729.

📒 Files selected for processing (6)
  • src/PAL/Lwip/lwIP_Sockets.cpp (3 hunks)
  • targets/ESP32/_Network/NF_ESP32_Ethernet.cpp (2 hunks)
  • targets/ESP32/_Network/NF_ESP32_Network.cpp (1 hunks)
  • targets/ESP32/_Network/NF_ESP32_Wireless.cpp (1 hunks)
  • targets/ESP32/_common/targetHAL_Network.cpp (1 hunks)
  • targets/ESP32/_include/NF_ESP32_Network.h (1 hunks)
🧬 Code Graph Analysis (1)
targets/ESP32/_common/targetHAL_Network.cpp (1)
targets/ESP32/_Network/NF_ESP32_Network.cpp (2)
  • NF_ESP32_ConfigureNetworkByConfigIndex (97-113)
  • NF_ESP32_ConfigureNetworkByConfigIndex (97-97)
🚧 Files skipped from review as they are similar to previous changes (4)
  • targets/ESP32/_Network/NF_ESP32_Ethernet.cpp
  • targets/ESP32/_Network/NF_ESP32_Wireless.cpp
  • targets/ESP32/_Network/NF_ESP32_Network.cpp
  • targets/ESP32/_include/NF_ESP32_Network.h
🧰 Additional context used
🧬 Code Graph Analysis (1)
targets/ESP32/_common/targetHAL_Network.cpp (1)
targets/ESP32/_Network/NF_ESP32_Network.cpp (2)
  • NF_ESP32_ConfigureNetworkByConfigIndex (97-113)
  • NF_ESP32_ConfigureNetworkByConfigIndex (97-97)
🔇 Additional comments (2)
src/PAL/Lwip/lwIP_Sockets.cpp (2)

1453-1454: Verify ESP-IDF API for DHCP flag management

I didn’t find any esp_netif_set_* or DHCP-related helper in the local codebase to safely enable the DHCP client flag. Directly writing to espNetif->flags (lines 1453–1454 and 1487) bypasses ESP-IDF’s abstraction and may break on upstream changes. Please:

  • Check the ESP-IDF documentation (for the version the project depends on) to see if there’s an official API for managing DHCP client flags.
  • If no public API exists, add a comment here explaining why direct struct access is necessary and note the ESP-IDF version dependency.
  • Apply the same change (comment or API call) at line 1487.

1413-1417: No additional edge-case handling required for NF_ESP32_GetEspNetif

The helper in targets/ESP32/_Network/NF_ESP32_Network.cpp simply returns the stored esp_netif_t* from either netif_get_client_data(netif) (when LWIP_ESP_NETIF_DATA is set) or netif->state otherwise. In ESP-IDF each network interface type—STA, AP, Ethernet, Thread—attaches its own esp_netif pointer via one of these two mechanisms. Therefore, this function inherently supports all current interface types without further branching.

@AdrianSoundy AdrianSoundy changed the title Update IP addresses in ESP_NETIF to stop static addresses being overwritten Fix Static addresses not working after change to ESP_NETIF and network not running with VS debugger Jul 22, 2025
@AdrianSoundy
Copy link
Member Author

@alberk8
@josesimoes
This should be complete now can you have a look

@AdrianSoundy AdrianSoundy added Platform: ESP32 Everything related specifically with ESP32 platform and removed ⚠️ DO NOT MERGE ⚠️ labels Jul 22, 2025
Copy link
Member

@josesimoes josesimoes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@josesimoes josesimoes merged commit d69c9c3 into nanoframework:main Jul 23, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Platform: ESP32 Everything related specifically with ESP32 platform Type: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wifi Static IP assignment does not work

6 participants