ESP Protocols

repository·master·Indexed 43 days ago

https://github.com/espressif/esp-protocols

A collection of specialized protocol components for the ESP-IDF framework, covering networking, connectivity, and command-line utilities. Includes an ASIO port for asynchronous I/O operations and a Modem Simulator component that extends ESP-AT with PPP server capabilities to turn an ESP32 into a Wi-Fi modem.

Tokens
53.1K
Snippets
112
Records
265
Agent score
55%

What's inside ESP Protocols

  1. Overview of the Brokerless MQTT Example

    master

    The Brokerless MQTT Example demonstrates how to run two independent MQTT brokers (using the mosquitto component) on two separate ESP32 devices and synchronize them over a peer-to-peer (P2P) connection. This allows MQTT connectivity between two private networks without requiring a central cloud broker.

    Key Concepts

    • Dual Brokers: Each ESP32 acts as a local MQTT server for its own IoT network (served via Wi-Fi SoftAP).
    • P2P Synchronization: The two brokers are synchronized as if they were a single network. Messages published on one broker are automatically forwarded to the other.
    • NAT Traversal: The connection uses either libjuice (ICE-UDP) or esp-webRTC to establish a direct connection between devices located behind different NATs.
  2. Overview of the Ethernet Gateway Example

    master

    The Ethernet gateway example demonstrates how to initialize a single Ethernet interface on an ESP device and run a DHCP server on it. In this role, the ESP acts as a gateway for a downstream subnet connected via Ethernet cable, rather than acting as a Wi-Fi access point.

    Key Functionality:

    • DHCP Server: Automatically assigns IP addresses to connected Ethernet devices.
    • Static IP: The ESP uses a static IP on the Ethernet interface (default 192.168.5.1).
    • Configurable IP Pool: You can define the range of addresses assigned to clients (default: 192.168.5.2 - 192.168.5.100).
    • DNS Support: Optional configuration of primary and backup DNS servers for DHCP clients.

    Supported Targets: ESP32, ESP32-C2, ESP32-C3, ESP32-C6, ESP32-S2, ESP32-S3.

  3. Overview of available ESP-Protocols components

    master

    The esp-protocols repository contains several specialized protocol components. Key components include:

    • Connectivity & Networking:

      • esp_modem: Modem support.
      • mDNS: Multicast DNS implementation.
      • esp_websocket_client: WebSocket client.
      • esp_mqtt_cxx: C++ wrapper for MQTT.
      • mosquitto: Mosquitto MQTT client.
      • esp_dns: DNS support.
      • freertos_tcp: TCP implementation for FreeRTOS.
      • libwebsockets: WebSocket library.
      • libsrtp: Secure Real-time Transport Protocol.
      • ASIO port: Asynchronous I/O port.
      • sock-utils: Socket helper utilities.
    • Console & Command Line Tools:

      • console_simple_init: Simple console initialization.
      • console_cmd_ping: Ping command for console.
      • console_cmd_ifconfig: ifconfig command for console.
      • console_cmd_wifi: WiFi management command for console.
      • console_cmd_mqtt: MQTT command for console.
    • Other Protocols & Wrappers:

      • eppp_link: ESP PPP Link.
      • mbedtls_cxx: C++ wrapper for mbedTLS.
  4. Overview of Modem Power Saving Mode (PSM) synchronization

    master

    This example demonstrates how to implement Power Saving Mode (PSM) using a SIM70XX modem in conjunction with ESP32 sleep modes (Deep Sleep and Light Sleep).

    Core Logic:

    1. The example enables PSM on the SIM70XX modem.
    2. It attempts to synchronize the modem's sleep cycle with the ESP32.
    3. When the modem wakes up from PSM sleep, it triggers the ESP32 to wake up.
    4. While the modem is awake, the ESP32 enters light sleep to conserve power.

    Supported Hardware:

    • Modems: SIM70XX series (tested on SIM7080).
    • Microcontrollers: ESP32, ESP32-S2, and ESP32-S3.
  5. Overview of Ethernet gateway + Wi-Fi STA example

    master

    This example demonstrates how to initialize two network interfaces simultaneously on an ESP32 device to bridge a wired local network with a wireless upstream connection:

    1. Ethernet Interface (Gateway Role): Acts as a DHCP server on the wired port (not a Wi-Fi AP). It provides network access to connected wired devices, typically in a specific IP range (e.g., 192.168.5.x).
    2. Wi-Fi Interface (Station/STA Role): Connects to an external Wi-Fi access point to provide upstream internet connectivity.

    Key Capabilities:

    • DHCP Server: Automatically assigns IP addresses to wired devices.
    • NAPT (Network Address Port Translation): If enabled, allows routing traffic from the Ethernet network through the Wi-Fi STA connection.
    • Automatic DNS Sync: If enabled, the Ethernet gateway automatically updates its DNS settings with the DNS servers obtained by the Wi-Fi STA.
    • Network Bridging: Facilitates traffic flow between the two interfaces.
  6. Overview of the Ethernet gateway + Wi-Fi AP example

    master

    This example demonstrates how to initialize two network interfaces simultaneously on an ESP32 device to act as a multi-interface router:

    1. Ethernet Gateway: A wired interface acting as a DHCP server (e.g., in the 192.168.5.x range).
    2. Wi-Fi Access Point (AP): A wireless interface acting as an AP with its own DHCP server (e.g., in the 192.168.4.x range).

    Both interfaces provide independent network access to connected devices via DHCP. If NAPT (Network Address Port Translation) is enabled in the LWIP configuration, the ESP can route traffic between the Ethernet and Wi-Fi interfaces.

  7. Overview of Socket Utilities component

    master

    The sock_utils component provides simplified implementations of common socket-related utilities by leveraging lwIP and esp_netif. It is primarily designed to facilitate the porting of Linux-based libraries to ESP32 platforms.

    Key characteristics:

    • Uses lwIP and esp_netif under the hood.
    • Useful for libraries where performance and memory constraints are secondary to compatibility.
    • Many functions are limited to IPv4.
  8. Overview of ESP PPP Link (eppp_link)

    master

    The eppp_link component is a general-purpose connectivity engine designed to establish a connection between two microcontrollers: one acting as a PPP server and the other as a PPP client.

    It is primarily used to extend network connectivity over physical serial connections. A common use case is creating a WiFi connectivity gateway where a WiFi-capable chip (the "SLAVE" or communication coprocessor) acts as the PPP server, and a non-WiFi chip (the "HOST" or main microcontroller) acts as the PPP client to gain internet access.

    Key Features

    • Network Interface Modes: Supports Standard PPP Mode (for IP negotiation) or a simplified TUN Mode (for faster data transfer on non-UART transports).
    • Transport Layers: Supports UART, SPI, SDIO, and Ethernet.
    • Logical Channels: Supports multiplexing multiple custom data streams (e.g., 802.11 frames) over the same transport layer when enabled.
  9. Overview of the net_connect component

    master

    The net_connect component provides a unified interface for implementing common network connection methods on ESP32 boards. It supports multiple interfaces simultaneously, allowing the connection phase to block until all selected interfaces have acquired IP addresses. You can also choose to disable all interfaces to skip the connection phase entirely.

    Supported connection methods include:

    • WiFi: For standard wireless networking.
    • Ethernet: For wired connections (supports Espressif Ethernet Kit, SPI ethernet devices, or OpenCores Ethernet MAC for QEMU).
    • Thread: For IEEE802.15.4 native radio or OpenThread RCP.
    • PPP (Point-to-Point Protocol): Creates an IP tunnel over Serial (UART or USB CDC) to a counterpart device like a Linux machine running pppd.