Skip to content

WiFiGeneric: add fallback Network‑event typedefs (ESP32‑C6 fix) #11266

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

OneNeutrino
Copy link

@OneNeutrino OneNeutrino commented Apr 21, 2025

Description

ESP32-C6 builds using Arduino Core v3.x can fail when WiFiGeneric.h is included before NetworkEvents.h (e.g., if WiFi.h is included directly without Network.h or ETH.h first). This leaves network event types like NetworkEventCb and arduino_event_id_t undefined. Projects like ESPresense can encounter this scenario.

This patch adds minimal, compatible fallback typedefs directly within <WiFiGeneric.h>, guarded by #if ESP_ARDUINO_VERSION_MAJOR >= 3. These fallbacks ensure the types have some definition known to the preprocessor when the #define aliases (like #define WiFiEventCb NetworkEventCb) are encountered, regardless of whether <NetworkEvents.h> was included first.

This prevents the "not declared" errors and ensures wider compatibility for projects compiling against Core v3.x, especially on newer targets like the C6, with no effect on other chips/cores where <NetworkEvents.h> is included normally.

Additional Context (PlatformIO Users)

Based on feedback from @me-no-dev, it's important to note that the Arduino-ESP32 core team no longer officially supports the standard PlatformIO espressif32 platform package.

Users encountering general build failures (like "Error: This board doesn't support arduino framework!") when trying to use Arduino Core v3.x with PlatformIO, especially for newer chips (C6, S3, C3, etc.), are advised to switch to the community-maintained pioarduino platform package: https://github.com/pioarduino/platform-espressif32

This specific PR addresses the typedef issue within the Arduino core files themselves, which is relevant regardless of the PlatformIO platform used, but the pioarduino package is the recommended way to use the latest Arduino cores within the PlatformIO ecosystem.

// COMPATIBILITY SHIM for ESP32‑C6 / Arduino‑Core v3.x
// If the NetworkEvent typedefs are not visible at this point,
// provide minimal stand‑ins so the compilation succeeds.
Copy link
Contributor

github-actions bot commented Apr 21, 2025

Warnings
⚠️

Some issues found for the commit messages in this PR:

  • the commit message "Update WiFiGeneric.h":
    • summary looks empty
    • type/action looks empty

Please fix these commit messages - here are some basic tips:

  • follow Conventional Commits style
  • correct format of commit message should be: <type/action>(<scope/component>): <summary>, for example fix(esp32): Fixed startup timeout issue
  • allowed types are: change,ci,docs,feat,fix,refactor,remove,revert,test
  • sufficiently descriptive message summary should be between 10 to 72 characters and start with upper case letter
  • avoid Jira references in commit messages (unavailable/irrelevant for our customers)

TIP: Install pre-commit hooks and run this check when committing (uses the Conventional Precommit Linter).

👋 Hello OneNeutrino, we appreciate your contribution to this project!


📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more.

🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project.

Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- Resolve all warnings (⚠️ ) before requesting a review from human reviewers - they will appreciate it.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against ae3e15b

@CLAassistant
Copy link

CLAassistant commented Apr 21, 2025

CLA assistant check
All committers have signed the CLA.

@lucasssvaz lucasssvaz requested a review from me-no-dev April 21, 2025 14:57
@lucasssvaz lucasssvaz added the Area: Libraries Issue is related to Library support. label Apr 21, 2025
@lucasssvaz
Copy link
Collaborator

@OneNeutrino Why not just change the include order ?

Can you give an example where this might be an issue ?

@OneNeutrino
Copy link
Author

Thanks for the review, @lucasssvaz !

While ensuring Network.h is included before the WiFiEventCb defines within WiFiGeneric.h might seem sufficient, the core issue arises when other compilation units (like application .cpp files or other libraries) include <WiFi.h> or <WiFiGeneric.h> without having previously included "Network.h".

In those cases, the preprocessor hits the #define WiFiEventCb NetworkEventCb line inside WiFiGeneric.h before NetworkEventCb has been defined (because the definition lives in Network.h/NetworkEvents.h, which haven't been included yet in that specific compilation unit). This leads to the " 'NetworkEventCb' has not been declared" errors.

The shim approach guarantees that minimal, compatible fallback definitions for these event types are always present before WiFiGeneric.h defines its aliases, regardless of the include order in the specific .cpp file being compiled. This makes the fix robust for downstream projects like ESPresense 1, which includes <WiFi.h> in many places (often indirectly via src/main.h) and triggers these errors when built for the C6 target using Arduino Core v3.x.

This ensures compatibility without requiring users to audit and modify include orders throughout their entire codebase.

@me-no-dev
Copy link
Member

Please provide minimal example sketch to demonstrate the issue you are trying to fix

@OneNeutrino
Copy link
Author

@me-no-dev

Here's a minimal example sketch and platformio.ini to demonstrate the issue this PR addresses:

Minimal_C6_Event_Test.ino:

#include <Arduino.h>
#include <WiFi.h> // Include WiFi first

WiFiClass WiFi; // Use WiFi object

// Dummy handler to potentially use event types
void WiFiEventHandler(arduino_event_id_t event) {
Serial.printf("[WiFi-event] event: %d\n", event);
}

void setup() {
Serial.begin(115200);
Serial.println("Minimal ESP32-C6 Network Event Type Test");
// WiFi.mode(WIFI_STA);
}

void loop() {
delay(1000);
}

platformio.ini:

[env:esp32c6_minimal_test]
platform = espressif32@>=6.0.0 ; Use official platform V6+ (Arduino Core v3+)
board = esp32-c6-devkitc-1 ; Or any other ESP32-C6 board
framework = arduino
monitor_speed = 115200

The Problem:
When compiling this sketch for an ESP32-C6 target using espressif32@>=6.0.0 (which uses Arduino Core v3.x), compilation fails with errors like:

  • error: 'NetworkEventCb' has not been declared
  • error: 'arduino_event_id_t' has not been declared
  • ... and other related event type errors originating from within WiFiGeneric.h.

This occurs because:

  1. The sketch includes <WiFi.h> directly, without having included <Network.h> or <ETH.h> first.
  2. <WiFi.h> includes <WiFiGeneric.h>.
  3. Inside <WiFiGeneric.h>, preprocessor directives like #define WiFiEventCb NetworkEventCb are encountered before the definition of NetworkEventCb (which resides in <NetworkEvents.h>, typically included via <Network.h>) is visible in this specific compilation unit.

While ensuring <Network.h> is included first in user code is a solution, libraries or other .cpp files might include <WiFi.h> directly, triggering this failure. Projects like ESPresense hit this when building for the C6 target.

The Fix:
This PR adds minimal, compatible fallback typedefs for these event types directly within <WiFiGeneric.h>, guarded by #if ESP_ARDUINO_VERSION_MAJOR >= 3. These fallbacks ensure that the types have some definition known to the preprocessor when the #define aliases are encountered, regardless of whether <Network.h> was included first, thus preventing the "not declared" errors and ensuring wider compatibility for projects compiling against Core v3.x, especially on newer targets like the C6.

@me-no-dev
Copy link
Member

  1. Commenting out WiFiClass WiFi; // Use WiFi object makes the sketch compile (it should be commented, because WiFi is already defined in WiFi.h)
  2. PlatformIO is no longer supported (because they do not support us anymore). Please switch to pioarduino if you want to be able to compile with the latest core versions

@me-no-dev me-no-dev added the Resolution: Unable to reproduce With given information issue is unable to reproduce label Apr 22, 2025
@OneNeutrino
Copy link
Author

@me-no-dev,
Regarding the WiFiClass WiFi; in the minimal example sketch - you're right, that was an oversight in the example and isn't needed as WiFi.h typically provides the instance. I'll remove it from the PR description for clarity.
The information about PlatformIO support is crucial, thank you very much for clarifying the situation. This explains the difficulties encountered when trying to build for C6 targets with Arduino core v3 using the standard platform = espressif32.
Based on your recommendation, I'm now switching to use the pioarduino platform package 1 as the way forward for compiling with the latest cores in PlatformIO.
Appreciate the guidance!

@me-no-dev
Copy link
Member

@OneNeutrino given that you now use pioarduino and latest cores, can you still encounter an error? If so, can you provide a new example so we can also reproduce it?

@OneNeutrino
Copy link
Author

OneNeutrino commented Apr 22, 2025

@me-no-dev
Thanks for the follow-up and the suggestion to try pioarduino.

I switched the platform in my platformio.ini:

[env:esp32c6]
# platform = [email protected]
# platform_packages =
#   framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.17
platform = pioarduino
board = esp32-c6-devkitc-1
board_build.flash_mode = dio
upload_speed = 921600
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
build_flags =
    -DARDUINO_USB_CDC_ON_BOOT=1
    -D MQTT_MAX_PACKET_SIZE=1024
    -D MQTT_MAX_TRANSFER_SIZE=1024
    -DASYNC_TCP_SSL_ENABLED=0
    -D LOG_LEVEL=DEBUG
    -D MQTT_DISABLE_ENCRYPTION
    -D ESP32
lib_deps =
    https://github.com/ESPresense/ESPAsyncWebServer.git
    https://github.com/ESPresense/qrcode.git
    ESP Async WebServer
    PubSubClient
    ArduinoJson
    Preferences
    Update
build_type = debug

Unfortunately, the build still fails with the same type of compilation errors as when using the standard espressif32 platform with its default Arduino Core v3:

In file included from C:/Users/Stark/.platformio/packages/framework-arduinoespressif32@src-6738aaddd9fb901216d5f60e093380b6/libraries/WiFi/src/WiFiGeneric.h:33,
                 from C:/Users/Stark/.platformio/packages/framework-arduinoespressif32@src-6738aaddd9fb901216d5f60e093380b6/libraries/WiFi/src/WiFiSTA.h:28,
                 from C:/Users/Stark/.platformio/packages/framework-arduinoespressif32@src-6738aaddd9fb901216d5f60e093380b6/libraries/WiFi/src/WiFi.h:32,
                 from lib/ESPAsyncWebServer/src/ESPAsyncWebServer.h:40,
                 from lib/ESPAsyncWebServer/src/AsyncWebSocket.h:32,
                 from lib/ESPAsyncWebServer/src/AsyncWebSocket.cpp:30:
C:/Users/Stark/.platformio/packages/framework-arduinoespressif32@src-6738aaddd9fb901216d5f60e093380b6/libraries/Ethernet/src/ETH.h:154:42: error: expected class-name before '{' token
  154 | class EthernetNetworkInterface : public NetworkInterface {
      |                                          ^~~~~~~~~~~~~~~~
C:/Users/Stark/.platformio/packages/framework-arduinoespressif32@src-6738aaddd9fb901216d5f60e093380b6/libraries/Ethernet/src/ETH.h:254:3: error: 'network_event_handle_t' does not name a type; did you mean 'network_prov_event_handler_t'?
  254 |   network_event_handle_t _network_event_handle;
      |   ^~~~~~~~~~~~~~~~~~~~~~
      |   network_prov_event_handler_t

... and many similar errors related to networking classes and types in WiFiGeneric.h, ETH.h, etc.

This confirms what others have found (e.g., in ESPresense Issue #1270: Support for ESP32-C6):

  1. The ESP32-C6 requires Arduino Core v3.x (based on ESP-IDF v5.1+).
  2. The ESPresense codebase (and its dependencies like the pinned version of ESPAsyncWebServer) relies heavily on networking APIs (like NetworkInterface, network_event_handle_t, etc.) from Arduino Core v2.x.
  3. These APIs were significantly changed or removed in Core v3.x, causing these compilation errors.
  4. While the pioarduino platform successfully provides the Core v3 build environment within PlatformIO (thank you for that!), it cannot fix the underlying code incompatibility within ESPresense itself.

The project needs code-level updates to adapt to the Arduino Core v3 API changes before it can compile successfully for the ESP32-C6.

For completeness, I also confirmed that forcing the standard espressif32 platform to use Core v2.0.17 with the C6 board definition fails during PlatformIO's setup phase with KeyError: 'toolchain-riscv32-esp', which seems to be another known symptom related to the standard platform's handling of C6/Core v2 combinations.

It looks like the path forward requires code modifications within ESPresense to achieve Core v3 compatibility. Issue #1270 seems to be the main place tracking C6 support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Libraries Issue is related to Library support. Resolution: Unable to reproduce With given information issue is unable to reproduce
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants