esp-idf/examples/common_components/protocol_examples_common
jgujarathi e411e43b4b fix(examples) : Common component's wifi disconnect handler should ignore roaming disconnect
- Common component's wifi disconnect handler should ignore roaming disconnect (WIFI_REASON_ROAMING)
  as connect gets issued internally in these cases.
2024-09-11 11:39:43 +08:00
..
include fix(common_components): unregister event handler if wifi disconnect and stop reconnecting 2024-07-22 15:56:55 +08:00
addr_from_stdin.c lwip: Support IPv6 only mode 2023-02-27 08:53:34 +01:00
CMakeLists.txt fix(examples): Make esp_eth public dependency of protocol_examples_comon 2024-01-22 21:51:37 +08:00
connect.c feat(examples): Add PPP to common connection component 2023-10-30 14:50:00 +01:00
console_cmd.c CI: Improve common test methods 2022-07-15 14:21:34 +08:00
eth_connect.c feat(eth) configure eth mac using esp_read_mac 2024-05-23 16:41:26 +08:00
Kconfig.projbuild fix(esp_eth): fixed default GPIO to match new ver. of P4 devboard 2024-08-08 18:11:38 +02:00
ppp_connect.c feat(examples): Add PPP to common connection component 2023-10-30 14:50:00 +01:00
protocol_examples_utils.c examples/protocols: Added URI encoding/decoding feature 2023-01-25 17:47:14 +05:30
README.md feat(examples): Add PPP to common connection component 2023-10-30 14:50:00 +01:00
stdin_out.c refactor(uart_vfs): Move uart implementation of vfs to esp_driver_uart 2023-12-15 17:14:55 +08:00
wifi_connect.c fix(examples) : Common component's wifi disconnect handler should ignore roaming disconnect 2024-09-11 11:39:43 +08:00

protocol_example_connect

This component implements the most common connection methods for ESP32 boards. It should be used mainly in examples of ESP-IDF to demonstrate functionality of network protocols and other libraries, that need the connection step as a prerequisite.

How to use this component

Choose the preferred interface (WiFi, Ethernet, PPPoS) to connect to the network and configure the interface.

It is possible to enable multiple interfaces simultaneously making the connection phase to block until all the chosen interfaces acquire IP addresses. It is also possible to disable all interfaces, skipping the connection phase altogether.

WiFi

Choose WiFi connection method (for chipsets that support it) and configure basic WiFi connection properties:

  • WiFi SSID
  • WiFI password
  • Maximum connection retry (connection would be aborted if it doesn't succeed after specified number of retries)
  • WiFi scan method (including RSSI and authorization mode threshold)

Ethernet

Choose Ethernet connection if your board supports it. The most common settings is using Espressif Ethernet Kit, which is also the recommended HW for this selection. You can also select an SPI ethernet device (if your chipset doesn't support internal EMAC or if you prefer). It is also possible to use OpenCores Ethernet MAC if you're running the example under QEMU.

PPP

Point to point connection method creates a simple IP tunnel to the counterpart device (running PPP server), typically a Linux machine with pppd service. We currently support only PPP over Serial (using UART or USB CDC). This is useful for simple testing of networking layers, but with some additional configuration on the server side, we could simulate standard model of internet connectivity. The PPP server could be also represented by a cellular modem device with pre-configured connectivity and already switched to PPP mode (this setup is not very flexible though, so we suggest using a standard modem library implementing commands and modes, e.g. esp_modem ).

Note

Note that if you choose USB device, you have to manually add a dependency on esp_tinyusb component. This step is necessary to keep the protocol_example_connect component simple and dependency free. Please run this command from your project location to add the dependency:

idf.py add-dependency espressif/esp_tinyusb^1

Setup a PPP server

Connect the board using UART or USB and note the device name, which would be typically:

  • /dev/ttyACMx for USB devices
  • /dev/ttyUSBx for UART devices

Run the pppd server:

sudo pppd /dev/ttyACM0 115200 192.168.11.1:192.168.11.2 ms-dns 8.8.8.8 modem local noauth debug nocrtscts nodetach +ipv6

Please update the parameters with the correct serial device, baud rate, IP addresses, DNS server, use +ipv6 if EXAMPLE_CONNECT_IPV6=y.

Connection to outside

In order to access other network endpoints, we have to configure some IP/translation rules. The easiest method is to setup a masquerade of the PPPD created interface (ppp0) to your default networking interface (${ETH0}). Here is an example of such rule:

sudo iptables -t nat -A POSTROUTING -o ${ETH0} -j MASQUERADE
sudo iptables -A FORWARD -i ${ETH0} -o ppp0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i ppp0 -o ${ETH0} -j ACCEPT