### Joiner Initialization Example Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/openthread/openthread_core.rst Basic setup sequence for initializing the Joiner role. ```arduino OThread.begin(false); OThread.setChannel(15); OThread.networkInterfaceUp(); ``` -------------------------------- ### Sensor Start and UDP Setup Source: https://github.com/espressif/arduino-esp32/blob/master/libraries/OpenThread/examples/CLI/UDP/README.md Commands to start the Thread interface and initialize the UDP socket on the sensor. ```text ifconfig up thread start udp close udp open udp bind :: 5050 ``` -------------------------------- ### Start Joiner Example Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/openthread/openthread_core.rst Initiates the joiner process and enables the Thread stack upon success. ```arduino otError err = OThread.startJoiner("J01NME"); if (err == OT_ERROR_NONE) { OThread.start(); // enable Thread with provisioned dataset } else { Serial.printf("Join failed: %d\r\n", err); } ``` -------------------------------- ### ESP32 Matter OnOff Plugin: Setup Functionality Source: https://github.com/espressif/arduino-esp32/blob/master/libraries/Matter/examples/MatterOnOffPlugin/README.md The setup() function initializes hardware, Wi-Fi, the Preferences library for state persistence, and the Matter plugin endpoint. It registers a callback function and starts the Matter stack. ```cpp // Initializes hardware (button, relay/LED pin), configures Wi-Fi (if needed), initializes Preferences library, // sets up the Matter plugin endpoint with the last saved state (defaults to OFF if not previously saved), // registers the callback function, and starts the Matter stack. ``` -------------------------------- ### Minimal UDP Receiver Setup Source: https://github.com/espressif/arduino-esp32/blob/master/libraries/OpenThread/Multicasting.md A minimal example for setting up a UDP receiver using the native API. ```cpp beginMulticast(ff03::1, 7) ``` -------------------------------- ### Example Log Output Source: https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/WiFiScanTime/README.md This is a sample log output from the WiFiScanTime example, showing the setup completion, scan start and end times, number of networks found, and details for each network. ```log Setup done Scan start Scan done, elapsed time: 4960 ms 17 networks found Nr | SSID | RSSI | CH | Encryption 1 | IoTNetwork | -62 | 1 | WPA2 2 | WiFiSSID | -62 | 1 | WPA2-EAP 3 | B3A7992 | -63 | 6 | WPA+WPA2 4 | WiFi | -63 | 6 | WPA3 5 | IoTNetwork2 | -64 | 11 | WPA2+WPA3 ... ``` -------------------------------- ### Basic OpenThread Setup with Classes API Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/openthread/openthread.rst Initializes the OpenThread stack with an explicit dataset and starts the network interface. ```arduino #include void setup() { Serial.begin(115200); // Initialize stack without auto-loading NVS dataset (see begin(true) vs begin(false) above) OpenThread::begin(false); while (!OThread) { delay(100); } DataSet dataset; dataset.initNew(); dataset.setNetworkName("MyThreadNetwork"); dataset.setChannel(15); OThread.commitDataSet(dataset); OThread.networkInterfaceUp(); OThread.start(); OpenThread::otPrintNetworkInformation(Serial); } ``` -------------------------------- ### Configure Joiner Pre-settings Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/openthread/openthread_core.rst Example of pre-configuring channel and PAN ID before starting the Joiner state machine. ```arduino OThread.begin(false); // stack up, no DataSet OThread.setChannel(15); // pre-pick channel OThread.setPanId(0xFFFF); // pre-pick PAN uint8_t xp[8] = {0x11,0x11,0x11,0x11,0x22,0x22,0x22,0x22}; OThread.setExtendedPanId(xp); OThread.networkInterfaceUp(); otError err = OThread.startJoiner("J01NME"); // run Joiner state machine if (err == OT_ERROR_NONE) { OThread.start(); // enable Thread with provisioned dataset } ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/guides/docs_contributing.rst Installs necessary packages for building the documentation. Ensure you are in a virtual environment if required. ```shell pip install -r requirements.txt ``` -------------------------------- ### GPIO Input and Output Example Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/gpio.rst A complete example demonstrating how to configure a button as an input with pullup and an LED as an output to toggle state. ```arduino #define LED 12 #define BUTTON 2 uint8_t stateLED = 0; void setup() { pinMode(LED, OUTPUT); pinMode(BUTTON,INPUT_PULLUP); } void loop() { if(!digitalRead(BUTTON)){ stateLED = stateLED^1; digitalWrite(LED,stateLED); } } ``` -------------------------------- ### Initialize and Start Thread Node Source: https://github.com/espressif/arduino-esp32/blob/master/libraries/OpenThread/examples/Native/SimpleThreadNetwork/RouterNode/README.md Demonstrates the sequence for starting the OpenThread stack, committing the network key, and bringing up the interface. ```cpp // 1) Start stack without NVS dataset. threadChildNode.begin(false); // 2) Commit ONLY the network key (must match Leader). dataset.clear(); dataset.setNetworkKey(networkKey); threadChildNode.commitDataSet(dataset); threadChildNode.networkInterfaceUp(); threadChildNode.start(); // 3) loop(): print active dataset + runtime addresses every 5 s ``` -------------------------------- ### Initialize and Start OpenThread Network Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/openthread/openthread_core.rst Demonstrates initializing a new dataset or starting an existing one. ```arduino if (OThread.hasActiveDataset()) { OThread.networkInterfaceUp(); OThread.start(); } else { DataSet dataset; dataset.initNew(); dataset.setNetworkName("MyThreadNetwork"); dataset.setChannel(15); OThread.commitDataSet(dataset); OThread.networkInterfaceUp(); OThread.start(); } ``` -------------------------------- ### MatterThermostat Example (Arduino) Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/matter/ep_thermostat.rst An example implementation of a thermostat using the Matter protocol within the Arduino ESP32 environment. This example demonstrates how to integrate and utilize the thermostat functionalities in a practical application. ```arduino #include "../libraries/Matter/examples/MatterThermostat/MatterThermostat.ino" ``` -------------------------------- ### Arduino setup() and loop() in ESP-IDF Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/esp-idf_component.rst This C++ code demonstrates the basic structure for using the Arduino `setup()` and `loop()` functions within an ESP-IDF project. It includes the necessary Arduino header and initializes serial communication in `setup()`. ```cpp //file: main.cpp #include "Arduino.h" void setup(){ Serial.begin(115200); while(!Serial){ ; // wait for serial port to connect } } ``` -------------------------------- ### Initialize Device with begin Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/esp_video.rst Opens the device at the specified path and requests MMAP buffers. ```cpp bool begin(const char *path, size_t buf_count = 2); ``` -------------------------------- ### Get Installed Open Limit Lift Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/matter/ep_window_covering.rst Gets the local open limit for lift motor calibration. ```arduino uint16_t getInstalledOpenLimitLift(); ``` -------------------------------- ### CLI Callback Setup Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/openthread/openthread_cli.rst Includes necessary headers for implementing response callbacks. ```arduino #include #include ``` -------------------------------- ### Network Setup Failure Output Source: https://github.com/espressif/arduino-esp32/blob/master/libraries/OpenThread/examples/Native/CoAP/CoAP_Light_Switch/light/README.md Example of the serial output when the network setup fails and triggers a retry. ```text === CoAP Light (server) === Forming Thread network... Waiting for attach......... Attach timeout. Network setup failed, retrying in 2s... ``` -------------------------------- ### Preferences Initialization and Data Storage Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/tutorials/preferences.rst Illustrates a real-world example of initializing Preferences, checking for first-time run, setting factory defaults, and retrieving runtime values. ```APIDOC ## Preferences Initialization and Setup ### Description This example demonstrates how to initialize the Preferences library, check if it's the first run, set factory default values if necessary, and then load the operational parameters. ### Method POST /setup (Conceptual, actual implementation uses library functions) ### Endpoint N/A (Library functions) ### Parameters None directly for this setup block, relies on library functions. ### Request Example ```arduino #include #define RW_MODE false #define RO_MODE true Preferences stcPrefs; void setup() { stcPrefs.begin("STCPrefs", RO_MODE); // Open namespace in RO mode. bool tpInit = stcPrefs.isKey("nvsInit"); // Check if initialized. if (tpInit == false) { stcPrefs.end(); stcPrefs.begin("STCPrefs", RW_MODE); // Reopen in RW mode. // Set factory defaults stcPrefs.putUChar("curBright", 10); stcPrefs.putString("talChan", "one"); stcPrefs.putLong("talMax", -220226); stcPrefs.putBool("ctMde", true); stcPrefs.putBool("nvsInit", true); // Mark as initialized. stcPrefs.end(); stcPrefs.begin("STCPrefs", RO_MODE); // Reopen in RO mode. } // Retrieve operational parameters currentBrightness = stcPrefs.getUChar("curBright"); tChannel = stcPrefs.getString("talChan"); tChanMax = stcPrefs.getLong("talMax"); ctMode = stcPrefs.getBool("ctMde"); stcPrefs.end(); // Close namespace. } ``` ### Response #### Success Response (200) - **Initialization**: Preferences namespace is opened, potentially initialized with defaults, and runtime values are loaded. #### Response Example ``` // No direct response, values are loaded into global variables. ``` ``` -------------------------------- ### IrDA Mode Two Board Example (Arduino) Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/serial.rst Demonstrates IrDA communication between two separate ESP32 boards. This example is useful for wireless IrDA communication setups. ```arduino #include "esp32-hal-uart.h" #define RXD0 16 #define TXD0 17 void setup() { Serial.begin(115200); Serial.println("IrDA Mode Two Board Demo"); // Initialize UART0 for IrDA uart_config_t uart_config = { .baud_rate = 115200, .data_bits = UART_DATA_8_BITS, .parity = UART_PARITY_DISABLE, .stop_bits = UART_STOP_BITS_1, .flow_control = UART_HW_FLOWCTRL_DISABLE, .rx_full_thresh = 10, .use_ref_tick = false }; esp_err_t ret = uart_param_config(UART_NUM_0, &uart_config); if (ret != ESP_OK) { Serial.printf("Failed to config UART: 0x%x\n", ret); } ret = uart_set_pin(UART_NUM_0, TXD0, RXD0, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE); if (ret != ESP_OK) { Serial.printf("Failed to set UART pins: 0x%x\n", ret); } ret = uart_driver_install(UART_NUM_0, 1024, 0, 0, NULL, 0); if (ret != ESP_OK) { Serial.printf("Failed to install UART driver: 0x%x\n", ret); } // Enable IrDA mode ret = uart_enable_irda_mode(UART_NUM_0); if (ret != ESP_OK) { Serial.printf("Failed to enable IrDA mode: 0x%x\n", ret); } Serial.println("IrDA mode enabled. Type characters to send."); } void loop() { int len = 0; uint8_t buf[128]; // Read from Serial monitor and send via IrDA if (Serial.available()) { len = Serial.readBytes(buf, sizeof(buf)); if (len > 0) { Serial.printf("Sending %d bytes: ", len); for (int i = 0; i < len; i++) { Serial.printf("%c", buf[i]); } Serial.println(); uart_write_bytes(UART_NUM_0, (const char *)buf, len); } } // Read from IrDA and print to Serial monitor len = uart_read_bytes(UART_NUM_0, buf, sizeof(buf), 20 / portTICK_PERIOD_MS); if (len > 0) { Serial.printf("Received %d bytes: ", len); for (int i = 0; i < len; i++) { Serial.printf("%c", buf[i]); } Serial.println(); } delay(10); } ``` -------------------------------- ### begin() Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/matter/ep_window_covering.rst Initializes the Matter window covering endpoint with optional initial positions, covering type, and calibration. ```APIDOC ## begin() ### Description Initializes the Matter window covering endpoint. Matter semantics apply: 0 = fully open, 100 = fully closed. ### Parameters - **liftPercent** (uint8_t) - Optional - Initial lift percentage (0-100, default: 0) - **tiltPercent** (uint8_t) - Optional - Initial tilt percentage (0-100, default: 0) - **coveringType** (WindowCoveringType_t) - Optional - Type of window covering (default: ROLLERSHADE) - **liftCalibration** (PositionCalibration*) - Optional - Local motor range for lift - **tiltCalibration** (PositionCalibration*) - Optional - Local motor range for tilt ### Returns - **bool** - Returns true if successful, false otherwise. ``` -------------------------------- ### SDMMC Test Example - Arduino Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/sdmmc.rst This example demonstrates how to use the SD_MMC library to interact with an SD card using the SDMMC interface. It covers basic file operations and setup. ```arduino #include "FS.h" #include "SD_MMC.h" void setup() { Serial.begin(115200); if(!SD_MMC.begin()){ Serial.println("SDMMC Mount Failed"); return; } uint8_t cardType = SD_MMC.cardType(); switch(cardType){ case 0: Serial.println(""); break; case 1: Serial.println("Card type: MMC"); break; case 2: Serial.println("Card type: SDSC"); break; case 3: Serial.println("Card type: SDHC/SDXC"); break; default: Serial.println("Unknown card"); } uint64_t cardSize = SD_MMC.cardSize() / (1024 * 1024); Serial.printf("Approx. card size: %llu MB\n", cardSize); // List files File root = SD.open("/"); File file = root.openNextFile(); while(file){ Serial.print(" FILE: "); Serial.println(file.name()); file = root.openNextFile(); } Serial.println("Done."); } void loop() { // put your main code here, to run repeatedly: } ``` -------------------------------- ### GET /wifi/scan Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/wifi.rst Starts a network scan to find available Wi-Fi access points. ```APIDOC ## GET /wifi/scan ### Description Initiates a scan for available Wi-Fi networks. ### Method GET ### Endpoint /wifi/scan ### Parameters #### Query Parameters - **async** (bool) - Optional - Perform scan asynchronously. - **show_hidden** (bool) - Optional - Include hidden SSIDs. ### Response #### Success Response (200) - **count** (int16_t) - The number of networks found. ``` -------------------------------- ### Multicast Receiver Setup Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/openthread/openthread_udp.rst Example of defining a realm-local multicast address for UDP reception. ```arduino OThreadUDP otUdp; const uint8_t realmLocalBytes[16] = {0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; IPAddress realmLocalAllNodes(IPv6, realmLocalBytes); // ff03::1 ``` -------------------------------- ### begin() Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/preferences.rst Opens non-volatile storage with a given namespace name from an NVS partition. ```APIDOC ## bool begin(const char * name, bool readOnly=false, const char* partition_label=NULL) ### Description Opens non-volatile storage with a given namespace name from an NVS partition. ### Parameters - **name** (const char *) - Required - Namespace name. Maximum length is 15 characters. - **readOnly** (bool) - Optional - If false, opens in read-write mode. If true, opens in read-only mode. Defaults to false. - **partition_label** (const char *) - Optional - Name of the NVS partition. Defaults to "nvs". ### Returns - **bool** - Returns true if the namespace was opened successfully; false otherwise. ``` -------------------------------- ### ledcFade: Setup and Start LEDC Fade Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/ledc.rst Sets up and initiates a PWM fade operation on an LEDC pin. It requires the pin, start duty cycle, target duty cycle, and maximum fade time. Returns true if the fade is configured and started successfully, false otherwise. ```arduino bool ledcFade(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms); ``` -------------------------------- ### Joiner-based Commissioning Setup Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/openthread/openthread.rst Initializes the stack on a new device to perform over-the-air commissioning using a PSKd. ```arduino #include const char PSKD[] = "J01NME"; void setup() { Serial.begin(115200); OThread.begin(false); // stack up, no DataSet OThread.setChannel(15); // optional channel hint OThread.networkInterfaceUp(); // IPv6 must be up ``` -------------------------------- ### Use CLI Helper Functions Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/openthread/openthread_cli.rst Demonstrates initializing OpenThread and using helper functions to execute commands and retrieve network state. ```arduino #include #include #include void setup() { Serial.begin(115200); // Initialize OpenThread OpenThread::begin(); while (!OThread) { delay(100); } // Initialize CLI OThreadCLI.begin(); while (!OThreadCLI) { delay(100); } // Get network state char resp[256]; if (otGetRespCmd("state", resp)) { Serial.printf("Thread state: %s\r\n", resp); } // Set network name ot_cmd_return_t errorInfo; if (otExecCommand("networkname", "MyThreadNetwork", &errorInfo)) { Serial.println("Network name set"); } else { Serial.printf("Error: %s\r\n", errorInfo.errorMessage.c_str()); } // Set channel if (otExecCommand("channel", "15", NULL)) { Serial.println("Channel set"); } // Bring interface up if (otExecCommand("ifconfig", "up", NULL)) { Serial.println("Interface up"); } // Print IP addresses otPrintRespCLI("ipaddr", Serial, 5000); } ``` -------------------------------- ### Example Log Output for FTM Responder Source: https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/FTM/FTM_Responder/README.md This section shows the expected log output when the Wi-Fi FTM Responder example is running. It includes boot information and confirmation of the FTM Responder service starting. ```text Build:Oct 25 2019 rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT) SPIWP:0xee mode:DIO, clock div:1 load:0x3ffe6100,len:0x4b0 load:0x4004c000,len:0xa6c load:0x40050000,len:0x25c4 entry 0x4004c198 Starting SoftAP with FTM Responder support ``` -------------------------------- ### Commissioner Role Usage Example Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/openthread/openthread_core.rst Demonstrates how to start the commissioner role and add a joiner on an attached device. ```arduino // Already attached to the network at this point // (networkInterfaceUp() + start() completed earlier). otError err = OThread.startCommissioner(); if (err == OT_ERROR_NONE) { OThread.addJoiner("J01NME", // PSKd 120); // window: 120 s (accepts any joiner) } ``` -------------------------------- ### Initial Network Provisioning CLI Commands Source: https://github.com/espressif/arduino-esp32/blob/master/libraries/OpenThread/examples/CLI/UDP/udp_sensor_collector/README.md Commands used on the first boot to provision the network with a fixed dataset. ```text thread stop ifconfig down dataset clear dataset init new dataset networkname ESP_OT_SENSORS dataset channel 15 dataset panid 0xabcf dataset extpanid ce010000deadc0de dataset networkkey 102030405060708090a0b0c0d0e0f002 dataset meshlocalprefix fdde:ad00:beef:0:: dataset activetimestamp 1 dataset commit active ifconfig up thread start udp close udp open ipmaddr add ff03::abcd udp bind :: 5050 ``` -------------------------------- ### ESPVideoClass begin (MIPI-CSI) Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/esp_video.rst Initializes MIPI-CSI and ISP subsystems. ```cpp bool begin(const ESPVideoCSIConfigClass &config); ``` -------------------------------- ### Implement app_main for Arduino-ESP32 Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/esp-idf_component.rst Demonstrates how to initialize the Arduino environment within an ESP-IDF app_main function. This approach replaces the standard setup and loop functions with a custom entry point. ```cpp #include "Arduino.h" extern "C" void app_main() { initArduino(); Serial.begin(115200); while(!Serial){ ; } while(true){ Serial.println("loop"); } } ``` -------------------------------- ### Initialize Thread Network and CoAP Server Source: https://github.com/espressif/arduino-esp32/blob/master/libraries/OpenThread/examples/Native/CoAP/CoAP_SimpleGet/server/README.md Configures the Thread dataset and starts the CoAP server with a registered GET handler. ```cpp // 1) Form the Thread network and wait for Leader attach. DataSet ds; ds.initNew(); ds.setNetworkName("ESP_OT_CoAP_Demo"); ds.setChannel(CHANNEL); ds.setPanId(PAN_ID); ds.setExtendedPanId(EXTPANID); ds.setNetworkKey(NETKEY); OThread.commitDataSet(ds); OThread.networkInterfaceUp(); OThread.start(); // 2) Register GET handler and start CoAP. OThreadCoAPServer.on("hello", OT_COAP_METHOD_GET, onHello); OThreadCoAPServer.begin(); // onHello() sends OT_COAP_RESP_OK + "Hello from CoAP!" ``` -------------------------------- ### Initialize and Configure MatterColorLight Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/matter/ep_color_light.rst Demonstrates the instantiation and initialization of the MatterColorLight endpoint. The begin method sets the initial power state and color parameters. ```arduino MatterColorLight light; light.begin(true, {0, 254, 254}); ``` -------------------------------- ### Wait for Serial Port Readiness Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/serial.rst This example demonstrates how to wait for a Serial port to be ready before starting communication, using a loop and delay. ```arduino Serial1.begin(115200); while (!Serial1) { delay(10); // Wait for Serial1 to be ready } ``` -------------------------------- ### begin Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/i2s.rst Initializes the I2S driver. This function requires prior configuration of pins using setPins() or PDM pin-setup functions. ```APIDOC ## begin ### Description Initializes the I2S driver. Before calling ``begin()``, choose which pins you want to use with ``setPins()`` or the PDM pin-setup functions. ### Signature ```cpp bool begin(i2s_mode_t mode, uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slot_mode_t ch, int8_t slot_mask = -1, i2s_role_t role = I2S_ROLE_MASTER) ``` ### Parameters * **mode** (i2s_mode_t) - Required - One of the above-mentioned operation modes, for example ``I2S_MODE_STD``. * **rate** (uint32_t) - Required - The sampling rate in Hz, for example ``16000``. * **bits_cfg** (i2s_data_bit_width_t) - Required - The number of bits in a channel sample, for example ``I2S_DATA_BIT_WIDTH_16BIT``. * **ch** (i2s_slot_mode_t) - Required - The slot mode, for example ``I2S_SLOT_MODE_STEREO``. * **slot_mask** (int8_t) - Optional - Selects which slot(s) to use (see `Slot Mask`_ section). Defaults to ``-1`` (library default: LEFT for mono TX/RX, BOTH for stereo). For stereo RX, the library always forces BOTH regardless of this value. * **role** (i2s_role_t) - Optional - The I2S role. Use ``I2S_ROLE_MASTER`` (default) to generate clock and word-select signals, or ``I2S_ROLE_SLAVE`` to receive them from an external master. ### Returns * ``true`` on success. * ``false`` on failure. An error message will be printed if the correct log level is set. ``` -------------------------------- ### Initialize and Start Thread Joiner Source: https://github.com/espressif/arduino-esp32/blob/master/libraries/OpenThread/examples/Native/ThreadCommissioning/JoinerNode/README.md Configures the node without a local dataset, sets the channel, and initiates the commissioning process using a PSKd. ```cpp // 1) Stack up with NO local dataset. threadJoinerNode.begin(false); #if THREAD_CHANNEL threadJoinerNode.setChannel(THREAD_CHANNEL); // optional channel hint #endif threadJoinerNode.networkInterfaceUp(); // 2) Run Joiner commissioning (Thread must NOT be enabled yet). otError err = threadJoinerNode.startJoiner("J01NME", JOIN_TIMEOUT_MS); if (err == OT_ERROR_NONE) { threadJoinerNode.start(); // enable Thread with new dataset } // 3) loop(): print role, RLOC, learned network key, addresses every 5 s ``` -------------------------------- ### Configure ESP32 Timer Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/timer.rst Initializes and configures a hardware timer on the ESP32. After successful setup, the timer automatically starts. It takes the desired frequency in Hz as input. ```arduino hw_timer_t * timerBegin(uint32_t frequency); ``` -------------------------------- ### ConsoleFS Example: File System CLI Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/console.rst This example provides a command-line interface (CLI) for interacting with the LittleFS file system. It supports common file operations like 'ls', 'cat', 'rm', 'mkdir', 'write', and 'df'. ```arduino #include "../libraries/Console/examples/ConsoleFS/ConsoleFS.ino" ``` -------------------------------- ### Example Serial Monitor Output Source: https://github.com/espressif/arduino-esp32/blob/master/libraries/ESP32/examples/HFP_HCI_Audio_I2S/README.md This output confirms that the I2S interface has started and is capturing audio from the microphone, indicated by the ADC peak values. A peak near zero suggests a potential issue. ```text I2S started: mSBC fs=16000 Hz ADC peak: 20480 drop: 0 ADC peak: 20614 drop: 0 ``` -------------------------------- ### ESPVideoClass begin (DVP) Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/esp_video.rst Initializes the DVP video device. ```cpp bool begin(const ESPVideoDVPConfigClass &config); ``` -------------------------------- ### Example CI Configuration (ci.yml) Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/contributing.rst This YAML file defines the configuration for the CI system, specifying how test suites and sketches are handled. It includes options for multi-device setups, required configurations, target platforms, tags, and library dependencies. ```yaml multi_device: device0: ap device1: client platforms: qemu: false wokwi: false requires: - CONFIG_SOC_WIFI_SUPPORTED=y ``` -------------------------------- ### ledcFadeWithInterrupt: Setup LEDC Fade with Interrupt Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/ledc.rst Configures and starts a PWM fade with an interrupt callback. It includes pin, duty cycles, fade time, and a user-defined function to be called upon interrupt. Returns true on success, false on failure. ```arduino bool ledcFadeWithInterrupt(uint8_t pin, uint32_t start_duty, uint32_t target_duty, int max_fade_time_ms, void (*userFunc)(void)); ``` -------------------------------- ### Initialize Preferences Namespace Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/tutorials/preferences.rst Demonstrates how to declare a Preferences object and open a namespace in read-write mode. ```arduino Preferences mySketchPrefs; mySketchPrefs.begin("myPrefs", false); ``` -------------------------------- ### Handle Specific Wi-Fi Station IP Event (Arduino ESP32) Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/network.rst This example shows how to handle a specific Wi-Fi Station IP address acquisition event in Arduino ESP32. It defines a callback function 'onWiFiEvent' that is triggered only for ARDUINO_EVENT_WIFI_STA_GOT_IP. The function extracts and prints the IP address, gateway, and subnet information. The setup initializes the network and registers this specific event handler. ```arduino #include "Network.h" #include "WiFi.h" void onWiFiEvent(arduino_event_id_t event, arduino_event_info_t info) { if (event == ARDUINO_EVENT_WIFI_STA_GOT_IP) { IPAddress ip = IPAddress(info.got_ip.ip_info.ip.addr); IPAddress gateway = IPAddress(info.got_ip.ip_info.gw.addr); IPAddress subnet = IPAddress(info.got_ip.ip_info.netmask.addr); Serial.println("WiFi Connected!"); Serial.print("IP: "); Serial.println(ip); Serial.print("Gateway: "); Serial.println(gateway); Serial.print("Subnet: "); Serial.println(subnet); } } void setup() { Network.begin(); Network.onEvent(onWiFiEvent, ARDUINO_EVENT_WIFI_STA_GOT_IP); WiFi.STA.begin(); WiFi.STA.connect("ssid", "password"); } ``` -------------------------------- ### Initialize and Configure Switch Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/matter/ep_generic_switch.rst Methods to initialize the switch endpoint and examples of common configurations. ```arduino bool begin(uint32_t featureFlags = FEATURE_SIMPLE, uint8_t multiPressMax = 5); ``` ```arduino // Simple short-click button (default) mySwitch.begin(); // Full gesture support (long press + multi-press up to 5 clicks) mySwitch.begin(MatterGenericSwitch::FEATURE_ALL, 5); ``` -------------------------------- ### Bash Script for Installing Pre-commit Hooks Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/contributing.rst Commands to install pre-commit hooks for local development. This includes installing dependencies and running the hooks manually or automatically on commit. ```bash pip install -U -r tools/pre-commit/requirements.txt ``` ```bash pre-commit run ``` ```bash pre-commit run codespell ``` ```bash pre-commit install ``` -------------------------------- ### ESPVideoClass::begin (DVP) Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/esp_video.rst Initializes the DVP video device. ```APIDOC ## bool begin(const ESPVideoDVPConfigClass &config) ### Description Initializes the DVP video device and reserves necessary pins. ### Parameters - **config** (ESPVideoDVPConfigClass) - Required - DVP configuration object ### Returns - **bool** - Returns true if initialization succeeded. ``` -------------------------------- ### Get Covering Type Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/matter/ep_window_covering.rst Gets the current window covering type. ```arduino WindowCoveringType_t getCoveringType(); ``` -------------------------------- ### Get Tilt Percentage Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/matter/ep_window_covering.rst Gets the current tilt percentage (0-100). ```arduino uint8_t getTiltPercentage(); ``` -------------------------------- ### ESPVideoClass::begin (MIPI-CSI) Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/esp_video.rst Initializes the MIPI-CSI and ISP subsystems. ```APIDOC ## bool begin(const ESPVideoCSIConfigClass &config) ### Description Initializes MIPI-CSI and ISP, reserves pins, and stores configuration. ### Parameters - **config** (ESPVideoCSIConfigClass) - Required - CSI configuration object ### Returns - **bool** - Returns true if initialization succeeded. ``` -------------------------------- ### Get Lift Position Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/matter/ep_window_covering.rst Gets the current lift position in percent100ths. ```arduino uint16_t getCurrentLiftPercent100ths(); ``` -------------------------------- ### Get Analog Output Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/zigbee/ep_analog.rst Gets the current analog output value. ```APIDOC ## GET /espressif/arduino-esp32/getAnalogOutput ### Description Gets the current analog output value. ### Method GET ### Endpoint /espressif/arduino-esp32/getAnalogOutput ### Response #### Success Response (200) - **analogOutput** (float) - The current analog output value. #### Response Example ```json { "analogOutput": 0.5 } ``` ``` -------------------------------- ### Manage Multiple Network Interfaces Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/network.rst Demonstrates how to initialize both Ethernet and WiFi interfaces and set a default network interface based on connectivity status. ```arduino #include "Network.h" #include "WiFi.h" #include "ETH.h" void setup() { Network.begin(); ETH.begin(ETH_PHY_TYPE, ETH_PHY_ADDR, ETH_PHY_MDC, ETH_PHY_MDIO, ETH_PHY_POWER, ETH_CLK_MODE); WiFi.STA.begin(); WiFi.STA.connect("ssid", "password"); while (!ETH.connected() && WiFi.STA.status() != WL_CONNECTED) { delay(500); } if (ETH.connected()) { Network.setDefaultInterface(ETH); Serial.println("Using Ethernet"); } else if (WiFi.STA.status() == WL_CONNECTED) { Network.setDefaultInterface(WiFi.STA); Serial.println("Using WiFi"); } } ``` -------------------------------- ### Arduino Example Header Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/contributing.rst Standard header for Arduino ESP32 example files. It includes the example name, license information, and a brief description of the software's distribution terms. ```arduino /* Wi-Fi FTM Initiator Arduino Example This example code is in the Public Domain (or CC0 licensed, at your option.) Unless required by applicable law or agreed to in writing, this software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ ``` -------------------------------- ### Joiner and Commissioner Setup Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/openthread/openthread.rst Demonstrates how to join a network as a joiner and how to configure a device as a commissioner to accept new joiners. ```arduino otError err = OThread.startJoiner(PSKD); if (err == OT_ERROR_NONE) { OThread.start(); // enable Thread with provisioned dataset Serial.println("Joined network!"); } else { Serial.printf("Joiner error: %d\r\n", err); } } ``` ```arduino #include void setup() { Serial.begin(115200); // ... bring up the device as Leader (DataSet + commitDataSet + start) ... // Wait until the device is attached while (OThread.otGetDeviceRole() == OT_ROLE_DETACHED || OThread.otGetDeviceRole() == OT_ROLE_DISABLED) { delay(100); } // Become the Commissioner and accept any joiner with PSKd "J01NME" if (OThread.startCommissioner() == OT_ERROR_NONE) { OThread.addJoiner("J01NME", 120); // window: 120 s (any joiner) } } ``` -------------------------------- ### Get Tilt Calibration Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/matter/ep_window_covering.rst Gets the local tilt motor calibration range. ```arduino PositionCalibration getTiltCalibration(); ``` -------------------------------- ### Peripheral Begin Function Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/usb.rst Function to start the USB peripheral with default configuration. ```APIDOC ## Begin Function ### Description Initializes and starts the USB peripheral using its default configuration. ### Function #### `bool begin();` ##### Description Starts the USB peripheral. ##### Returns - (bool) True if the peripheral started successfully, false otherwise. ``` -------------------------------- ### Get Lift Calibration Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/matter/ep_window_covering.rst Gets the local lift motor calibration range. ```arduino PositionCalibration getLiftCalibration(); ``` -------------------------------- ### ESPVideoCSIConfigClass Initialization Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/esp_video.rst Constructors and begin method for MIPI-CSI configuration. ```cpp ESPVideoCSIConfigClass(); ESPVideoCSIConfigClass(const ESPVideoCSIConfigClass &config); bool begin(const ESPVideoCamConfigClass &config, bool dont_init_ldo = false); ``` -------------------------------- ### Get Current Tilt Percent100ths Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/matter/ep_window_covering.rst Gets the current tilt position in percent100ths. ```arduino uint16_t getCurrentTiltPercent100ths(); ``` -------------------------------- ### UDP Setup Sequence Source: https://github.com/espressif/arduino-esp32/blob/master/libraries/OpenThread/examples/CLI/UDP/README.md Commands to initialize a UDP socket and join a multicast group. ```text udp close udp open ipmaddr add ff03::abcd udp bind :: 5050 ``` -------------------------------- ### Get Tilt Position Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/matter/ep_window_covering.rst Gets the current tilt position as an absolute value. ```arduino uint16_t getTiltPosition(); ``` -------------------------------- ### Basic UDP Echo Example Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/openthread/openthread_udp.rst Demonstrates initializing the Thread network and performing a UDP echo loop. ```arduino #include #include // ff02::1 = link-local all-nodes multicast const uint8_t serverBytes[16] = {0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; IPAddress server(IPv6, serverBytes); OThreadUDP otUdp; void setup() { Serial.begin(115200); // Bring up Thread (using a DataSet, or via the Joiner role). OThread.begin(false); // ... configure dataset and call commitDataSet(), then // networkInterfaceUp() + start(); or, for a Joiner device, // networkInterfaceUp() + startJoiner() + start() on success. OThread.networkInterfaceUp(); OThread.start(); // Bind a UDP socket on port 7, any IPv6 local address. otUdp.begin(7); } void loop() { // Send "Hello" to the link-local all-nodes group, port 7. otUdp.beginPacket(server, 7); otUdp.write((const uint8_t *)"Hello", 5); otUdp.endPacket(); // Drain any pending datagrams. while (int n = otUdp.parsePacket()) { char buf[64]; int r = otUdp.read(buf, sizeof(buf) - 1); buf[r] = 0; Serial.printf("From [%s]:%u -> '%s'\r\n", otUdp.remoteIP().toString().c_str(), otUdp.remotePort(), buf); } delay(1000); } ``` -------------------------------- ### MIPI-CSI Capture Example Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/esp_video.rst Example implementation for MIPI-CSI camera capture on ESP32-P4. ```cpp .. literalinclude:: ../../../libraries/ESP_Video/examples/mipi_csi_camera/mipi_csi_camera.ino :language: cpp ``` -------------------------------- ### Commit and Start Network Source: https://github.com/espressif/arduino-esp32/blob/master/libraries/OpenThread/examples/CLI/SimpleCLI/README.md Commits the active dataset and starts the Thread stack. ```text dataset commit active ifconfig up thread start ``` -------------------------------- ### Configure CoAPS Client and Server Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/openthread/openthread_coap.rst Demonstrates initializing a secure CoAP client with PSK and setting up a secure server with a resource handler. ```arduino OThreadCoAPSecureClient client; client.setPSK(psk, pskLen, "client1"); client.connect(serverIp); client.setConfirmable(true); client.setContentFormat(OT_COAP_FORMAT_JSON); int code = client.PUT("fan/speed", "{\"speed\":75}"); client.disconnect(); OThreadCoAPSecureServer.setPSK(psk, pskLen, "server1"); OThreadCoAPSecureServer.on("status", OT_COAP_METHOD_GET, onStatus); OThreadCoAPSecureServer.begin(); ``` -------------------------------- ### Start Interactive Console Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/openthread/openthread_cli.rst Starts an interactive console task for CLI access. ```arduino void startConsole(Stream &otStream, bool echoback = true, const char *prompt = "ot> "); ``` ```arduino OThreadCLI.startConsole(Serial, true, "ot> "); ``` -------------------------------- ### Initialize Thread Network (Leader) Source: https://github.com/espressif/arduino-esp32/blob/master/libraries/OpenThread/examples/CLI/SimpleCLI/README.md Workflow to set up a new Thread network as a leader. ```text dataset init new dataset networkname MyNetwork dataset channel 15 dataset networkkey 00112233445566778899aabbccddeeff dataset commit active ifconfig up thread start ``` -------------------------------- ### CI Configuration for Arduino ESP32 Example Testing Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/contributing.rst Example of a `ci.yml` file used to specify hardware requirements for testing Arduino ESP32 examples, ensuring tests run only on compatible targets. ```yaml requires: - CONFIG_SOC_WIFI_SUPPORTED=y ``` -------------------------------- ### ESPVideoDVPConfigClass::begin Source: https://github.com/espressif/arduino-esp32/blob/master/docs/en/api/esp_video.rst Initializes the DVP configuration including SCCB settings, pins, and XCLK frequency. ```APIDOC ## bool begin(const ESPVideoCamConfigClass &config, const ESPVideoDVPPinsConfigClass &dvp_pin, uint32_t xclk_freq) ### Description Combines SCCB settings, DVP pins, and XCLK frequency into a single configuration instance. ### Parameters - **config** (ESPVideoCamConfigClass) - Required - Base camera / SCCB configuration - **dvp_pin** (ESPVideoDVPPinsConfigClass) - Required - DVP data, sync, and clock pin mapping - **xclk_freq** (uint32_t) - Required - Sensor external clock (XCLK) frequency in Hz ### Returns - **bool** - Returns true on success. ```