esp-idf/examples/network/sta2eth
David Cermak cce9a80aee fix(sta2eth): Check for null `netif` before starting/stopping DHCP server
Fixes a potential null pointer dereference in `esp_netif` when PPP mode is enabled.
In the Ethernet event handler, `esp_netif_dhcps_start()` and `esp_netif_dhcps_stop()`
are now only called if `netif` is non-null (in provisioning mode when
the actual TCP/IP stack from IDF is used, in work mode the `netif` is
null, since the trafic is simply forwarded between wireless and wired
networks without TCP/IP stack involved)

Closes https://github.com/espressif/esp-idf/issues/14816
2024-11-07 17:48:59 +01:00
..
main fix(sta2eth): Check for null `netif` before starting/stopping DHCP server 2024-11-07 17:48:59 +01:00
CMakeLists.txt
README.md fix(sta2eth): Document security considerations in sta2eth example 2024-11-07 10:24:54 +01:00
sdkconfig.defaults
sdkconfig.defaults.esp32s2
sdkconfig.defaults.esp32s3

README.md

Supported Targets ESP32 ESP32-C2 ESP32-C3 ESP32-C5 ESP32-C6 ESP32-C61 ESP32-S2 ESP32-S3

WiFi station to "Wired" interface L2 forwarder

(See the README.md file in the upper level 'examples' directory for more information about examples.)

This example aims to demonstrate 1-1 bridge using WiFi station and one of these interfaces (so called wired in this example)

  • Ethernet (supported for all targets)
  • USB acting as NCM device (supported for ESP32-S2 and ESP32-S3)

It also allows for reconfiguring WiFi settings using a virtual network in the Ethernet. The reconfiguration mode is initialized if the WiFi settings are not available, connection fails or manually by long pressing the Boot button (GPIO0). It is possible to configure WiFi settings (SSID and password) in a browser on a hostname "http://wifi.settings" or using unified provisioning.

Note: This page is intended solely for initial setup and is not recommended for production use, as it lacks any security measures—data is transmitted in plain text over HTTP. For secure, production-grade configuration, we recommend using the default option: unified provisioning.

How to use example

This example could be used to bring wireless connectivity to devices that support only Ethernet (or USB Ethernet implemented as NCM device). This example also supports runtime configuration of WiFi settings by means of a webpage or unified provisioning.

Hardware Required

Any board with either Ethernet of USB-OTG supported.

Configure the project

Open the project configuration menu (idf.py menuconfig).

In the Example Configuration menu choose the provisioning method:

  • EXAMPLE_WIFI_CONFIGURATION_MANUAL for manual configuration using a webpage
  • EXAMPLE_WIFI_CONFIGURATION_PROVISIONING for standard provisioning over the virtual USB network

To provision the device using IDF provisioning tools (if EXAMPLE_WIFI_CONFIGURATION_PROVISIONING is selected) you can use idf provisioning utility with transport set to softap:

esp-idf/tools/esp_prov$ python esp_prov.py --transport httpd ...

Please refer to the provisioning documentation and esp_prov script documentation for more details.

Build, Flash, and Run

Build the project and flash it to the board, then run monitor tool to view serial output:

idf.py -p PORT build flash monitor

(Replace PORT with the name of the serial port to use.)

(To exit the serial monitor, type Ctrl-].)

See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.

Example Output

After the flashing you should see the output at idf monitor:

(note that this is the output of USB configuration)

I (1740) example_sta2wired: Wi-Fi STA connected
I (1740) example_sta2wired: WiFi station connected successfully
W (1750) TinyUSB: The device's configuration descriptor is not provided by user, using default.
W (1760) TinyUSB: The device's string descriptor is not provided by user, using default.
W (1770) TinyUSB: The device's device descriptor is not provided by user, using default.
I (1770) wifi:AP's beacon interval = 102400 us, DTIM period = 1
I (1780) tusb_desc:
┌─────────────────────────────────┐
│  USB Device Descriptor Summary  │
├───────────────────┬─────────────┤
│bDeviceClass       │ 239         │
├───────────────────┼─────────────┤
│bDeviceSubClass    │ 2           │
├───────────────────┼─────────────┤
│bDeviceProtocol    │ 1           │
├───────────────────┼─────────────┤
│bMaxPacketSize0    │ 64          │
├───────────────────┼─────────────┤
│idVendor           │ 0x303a      │
├───────────────────┼─────────────┤
│idProduct          │ 0x4002      │
├───────────────────┼─────────────┤
│bcdDevice          │ 0x100       │
├───────────────────┼─────────────┤
│iManufacturer      │ 0x1         │
├───────────────────┼─────────────┤
│iProduct           │ 0x2         │
├───────────────────┼─────────────┤
│iSerialNumber      │ 0x3         │
├───────────────────┼─────────────┤
│bNumConfigurations │ 0x1         │
└───────────────────┴─────────────┘
I (915) TinyUSB: TinyUSB Driver installed