### Example: Get and Print MAC Address (String version) Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html Demonstrates how to retrieve the MAC address as a String and print it to the serial monitor when connected to Wi-Fi. ```cpp if (WiFi.status() == WL_CONNECTED) { Serial.printf("Connected, mac address: %s\n", WiFi.macAddress().c_str()); } ``` -------------------------------- ### Example: Get and Print MAC Address Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html Demonstrates how to retrieve the MAC address using a pointer and print it to the serial monitor when connected to Wi-Fi. ```cpp if (WiFi.status() == WL_CONNECTED) { uint8_t macAddr[6]; WiFi.macAddress(macAddr); Serial.printf("Connected, mac address: %02x:%02x:%02x:%02x:%02x:%02x\n", macAddr[0], macAddr[1], macAddr[2], macAddr[3], macAddr[4], macAddr[5]); } ``` -------------------------------- ### Server Class Example Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/server-class.html Demonstrates the usage of WiFiServer::begin() and WiFiServer::setNoDelay() to configure and start a server. The setNoDelay(true) call disables the Nagle algorithm for potentially faster small packet transmission. ```cpp server.begin(); server.setNoDelay(true); ``` -------------------------------- ### Example: Get and Print Gateway IP Address Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html Demonstrates how to retrieve and print the gateway IP address. Requires a Wi-Fi connection. ```cpp Serial.printf("Gataway IP: %s\n", WiFi.gatewayIP().toString().c_str()); ``` -------------------------------- ### Example: Get and Print DNS IP Addresses Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html Demonstrates how to retrieve and print the IP addresses of the first and second DNS servers. Requires a Wi-Fi connection. ```cpp Serial.print("DNS #1, #2 IP: "); WiFi.dnsIP().printTo(Serial); Serial.print(", "); WiFi.dnsIP(1).printTo(Serial); Serial.println(); ``` -------------------------------- ### Complete Synchronous WiFi Scan Example Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/scan-examples.html A full Arduino sketch demonstrating how to initialize WiFi in station mode, disconnect, scan for networks, and print their SSIDs. Includes necessary includes and setup. ```arduino #include "ESP8266WiFi.h" void setup() { Serial.begin(115200); Serial.println(); WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(100); } void loop() { Serial.print("Scan start ... "); int n = WiFi.scanNetworks(); Serial.print(n); Serial.println(" network(s) found"); for (int i = 0; i < n; i++) { Serial.println(WiFi.SSID(i)); } Serial.println(); delay(5000); } ``` -------------------------------- ### Start GDB on Windows (Git Version) Source: https://arduino-esp8266.readthedocs.io/en/latest/gdb.html Start the GDB executable for ESP8266 debugging on Windows using the Git installation path. ```batch %userprofile%\Documents\Arduino\hardware\esp8266com\esp8266\tools\xtensa-lx106-elf\bin\xtensa-lx106-elf-gdb.exe ``` -------------------------------- ### Setup for Web Browser OTA Updates Source: https://arduino-esp8266.readthedocs.io/en/latest/ota_updates/readme.html This code initializes mDNS, sets up the HTTP update server, and starts the web server. It's required for enabling OTA updates via a web browser. ```cpp MDNS.begin(host); httpUpdater.setup(&httpServer); httpServer.begin(); MDNS.addService("http", "tcp", 80); ``` -------------------------------- ### Example: Get and Print Local IP Address Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html Demonstrates how to retrieve and print the local IP address of the ESP station's interface when connected to Wi-Fi. ```cpp if (WiFi.status() == WL_CONNECTED) { Serial.print("Connected, IP address: "); Serial.println(WiFi.localIP()); } ``` -------------------------------- ### Start WPS Configuration Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html Initiates the Wi-Fi Protected Setup (WPS) process using the push-button configuration method. This function is available from SDK 1.5.4. ```cpp #include void setup(void) { Serial.begin(115200); Serial.println(); Serial.printf("Wi-Fi mode set to WIFI_STA %s\n", WiFi.mode(WIFI_STA) ? "" : "Failed!"); Serial.print("Begin WPS (press WPS button on your router) ... "); Serial.println(WiFi.beginWPSConfig() ? "Success" : "Failed"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(); Serial.print("Connected, IP address: "); Serial.println(WiFi.localIP()); } void loop() {} ``` -------------------------------- ### Windows 7 Sketchbook Location Example Source: https://arduino-esp8266.readthedocs.io/en/latest/faq/a04-board-generic-is-unknown.html Provides an example path for the Arduino sketchbook location on Windows 7, guiding users to the directory containing the esp8266 hardware package. ```text Arduino15\packages\esp8266\hardware\esp8266 ``` -------------------------------- ### Example: Get and Print Subnet Mask Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html Demonstrates how to retrieve and print the subnet mask of the station's interface. Requires a Wi-Fi connection. ```cpp Serial.print("Subnet mask: "); Serial.println(WiFi.subnetMask()); ``` -------------------------------- ### Initialize GDB Stub in Setup Source: https://arduino-esp8266.readthedocs.io/en/latest/gdb.html Ensure the serial port is initialized and call gdbstub_init() within the void setup() function to prepare for GDB. ```c++ Serial.begin(115200); gdbstub_init(); ``` -------------------------------- ### WiFiServer Constructor and Begin Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/server-class.html Details on how to construct a WiFiServer object and start it on a specific port or the default port 23. ```APIDOC ## WiFiServer() ### Description Constructor for the WiFiServer class. ### Method Constructor ## begin(port) ### Description Starts the server on the specified port. ### Method `begin` ### Parameters #### Path Parameters - **port** (uint16_t) - The port number to start the server on. ## begin() ### Description Starts the server on the default port (23) if the constructor was called without a port. ### Method `begin` ``` -------------------------------- ### Start GDB on Windows (Board Manager) Source: https://arduino-esp8266.readthedocs.io/en/latest/gdb.html Start the GDB executable for ESP8266 debugging on Windows using the Board Manager installation path. ```batch %userprofile%\AppData\Local\Arduino15\packages\esp8266\tools\xtensa-lx106-elf-gcc\2.5.0-3-20ed2b9\bin\xtensa-lx106-elf-gdb.exe ``` -------------------------------- ### Start GDB on Linux Source: https://arduino-esp8266.readthedocs.io/en/latest/gdb.html Navigate to the toolchain directory and start the GDB executable for ESP8266 debugging on Linux. ```bash ~/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-4-b40a506/bin/xtensa-lx106-elf-gdb ``` -------------------------------- ### ESP8266 WiFi Connection and Event Handling Example Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/generic-examples.html This example demonstrates how to connect an ESP8266 to a Wi-Fi network and handle both IP assignment and disconnection events asynchronously. It also includes a blinking LED to show that the main loop continues to run. ```cpp #include const char* ssid = "********"; const char* password = "********"; WiFiEventHandler gotIpEventHandler, disconnectedEventHandler; bool ledState; void setup() { Serial.begin(115200); Serial.println(); pinMode(LED_BUILTIN, OUTPUT); gotIpEventHandler = WiFi.onStationModeGotIP([](const WiFiEventStationModeGotIP& event) { Serial.print("Station connected, IP: "); Serial.println(WiFi.localIP()); }); disconnectedEventHandler = WiFi.onStationModeDisconnected([](const WiFiEventStationModeDisconnected& event) { Serial.println("Station disconnected"); }); Serial.printf("Connecting to %s ...\n", ssid); WiFi.begin(ssid, password); } void loop() { digitalWrite(LED_BUILTIN, ledState); ledState = !ledState; delay(250); } ``` -------------------------------- ### ESP8266 Boot Mode Example Source: https://arduino-esp8266.readthedocs.io/en/latest/boards.html This is an example of the boot messages printed by the ESP module, indicating the reset cause and boot mode. ```text rst cause:2, boot mode:(3,6) ``` -------------------------------- ### Providing Hints for Compiler Cache Options Source: https://arduino-esp8266.readthedocs.io/en/latest/faq/a06-global-build-options.html Examples of using `mkbuildoptglobals.extra_flags` in `platform.local.txt` to provide hints about preferences or cache behavior. ```text mkbuildoptglobals.extra_flags=--preferences_sketch # assume file preferences.txt in the sketch folder ``` ```text mkbuildoptglobals.extra_flags=--preferences_sketch "pref.txt" # is relative to the sketch folder ``` ```text mkbuildoptglobals.extra_flags=--no_cache_core ``` ```text mkbuildoptglobals.extra_flags=--cache_core ``` ```text mkbuildoptglobals.extra_flags=--preferences_file "other-preferences.txt" # relative to IDE or full path ``` -------------------------------- ### Simplified Soft Access Point Setup Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/soft-access-point-examples.html A more concise version of the SoftAP setup using a ternary operator for printing the status. This reduces code verbosity while maintaining the same functionality. ```C++ #include void setup() { Serial.begin(115200); Serial.println(); Serial.print("Setting soft-AP ... "); Serial.println(WiFi.softAP("ESPsoftAP_01", "pass-to-soft-AP") ? "Ready" : "Failed!"); } void loop() { Serial.printf("Stations connected = %d\n", WiFi.softAPgetStationNum()); delay(3000); } ``` -------------------------------- ### Example Output of WiFi Scan Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/scan-examples.html Sample output from the complete synchronous WiFi scan example, showing the scan initiation message and a list of found network SSIDs. ```text Scan start ... 5 network(s) found Tech_D005107 HP-Print-A2-Photosmart 7520 ESP_0B09E3 Hack-4-fun-net UPC Wi-Free ``` -------------------------------- ### Basic Soft Access Point Setup Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/soft-access-point-examples.html Configures the ESP8266 to act as a SoftAP with a specified SSID and password. It prints the setup status to the serial monitor and periodically reports the number of connected stations. ```C++ #include void setup() { Serial.begin(115200); Serial.println(); Serial.print("Setting soft-AP ... "); boolean result = WiFi.softAP("ESPsoftAP_01", "pass-to-soft-AP"); if(result == true) { Serial.println("Ready"); } else { Serial.println("Failed!"); } } void loop() { Serial.printf("Stations connected = %d\n", WiFi.softAPgetStationNum()); delay(3000); } ``` -------------------------------- ### Start Asynchronous Network Scan with Callback Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/scan-class.html Starts an asynchronous Wi-Fi network scan and specifies a callback function to be executed upon completion. Optionally includes hidden networks. ```cpp WiFi.scanNetworksAsync(onComplete, show_hidden) ``` -------------------------------- ### Start UDP Listener Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/udp-examples.html Begin listening for incoming UDP packets on the specified local port after Wi-Fi connection is established. ```cpp Udp.begin(localUdpPort); ``` -------------------------------- ### Enable WiFi at Boot Time Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/generic-class.html This code snippet shows how to restore the legacy behavior where WiFi starts automatically at boot. This is achieved by calling enableWiFiAtBootTime(). ```cpp #include void setup () { #ifdef WIFI_IS_OFF_AT_BOOT enableWiFiAtBootTime(); // can be called from anywhere with the same effect #endif .... } ``` -------------------------------- ### Download Binary Tools (Windows) Source: https://arduino-esp8266.readthedocs.io/en/latest/installing.html Download the necessary binary tools for the ESP8266 core installation using a Python script. This is a required step after cloning the repository. ```bash cd tools python3 get.py ``` -------------------------------- ### Stream Extensions: Echo Service Example Source: https://arduino-esp8266.readthedocs.io/en/latest/reference.html Illustrates how to implement an echo service using Stream extensions for both network (TCP) and serial loopback scenarios. ```arduino serverClient.sendAvailable(serverClient); // tcp echo service Serial.sendAvailable(Serial); // serial software loopback ``` -------------------------------- ### UDP Object and Port Setup Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/udp-examples.html Create a WiFiUDP object, specify a local UDP port, and define buffers for incoming and reply packets. ```cpp WiFiUDP Udp; unsigned int localUdpPort = 4210; char incomingPacket[256]; char replyPacket[] = "Hi there! Got the message :-)"; ``` -------------------------------- ### Setting a Breakpoint in GDB Source: https://arduino-esp8266.readthedocs.io/en/latest/gdb.html Example of setting a breakpoint using the 'break' command in GDB. This can sometimes result in multiple locations being matched. ```gdb (gdb) break loop Breakpoint 1 at 0x40202c84: loop. (2 locations) ``` -------------------------------- ### Wi-Fi Debug Output Example (Enabled) Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/readme.html This is a sample output when Wi-Fi debug is enabled via Serial.setDebugOutput(true), showing detailed connection steps and information. ```text Connectingscandone state: 0 -> 2 (b0) state: 2 -> 3 (0) state: 3 -> 5 (10) add 0 aid 1 cnt connected with sensor-net, channel 6 dhcp client start... chg_B1:-40 ...ip:192.168.1.10,mask:255.255.255.0,gw:192.168.1.9 . Connected, IP address: 192.168.1.10 ``` -------------------------------- ### Example Sketch with Global Defines Source: https://arduino-esp8266.readthedocs.io/en/latest/faq/a06-global-build-options.html This is a basic Arduino sketch that utilizes preprocessor directives to conditionally print messages based on defined macros. ```arduino #include // has prototype for umm_free_heap_size_min() void setup() { Serial.begin(115200); delay(200); #ifdef MYTITLE1 Serial.printf("\r\n" MYTITLE1 MYTITLE2 "\r\n"); #else Serial.println("ERROR: MYTITLE1 not present"); #endif Serial.printf("Heap Low Watermark %u\r\n", umm_free_heap_size_min()); } void loop() {} ``` -------------------------------- ### Example: Setting up Soft-AP with Custom Configuration Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/soft-access-point-class.html Demonstrates how to configure the soft-AP's IP address, gateway, and subnet, then set up the soft-AP itself, and finally print its IP address. ```cpp #include IPAddress local_IP(192,168,4,22); IPAddress gateway(192,168,4,9); IPAddress subnet(255,255,255,0); void setup() { Serial.begin(115200); Serial.println(); Serial.print("Setting soft-AP configuration ... "); Serial.println(WiFi.softAPConfig(local_IP, gateway, subnet) ? "Ready" : "Failed!"); Serial.print("Setting soft-AP ... "); Serial.println(WiFi.softAP("ESPsoftAP_01") ? "Ready" : "Failed!"); Serial.print("Soft-AP IP address = "); Serial.println(WiFi.softAPIP()); } void loop() {} ``` -------------------------------- ### Initializing String with F Macro Source: https://arduino-esp8266.readthedocs.io/en/latest/PROGMEM.html Example of initializing a `String` object directly using the `F()` macro for an inline flash string. ```c++ String mystring(F("This string is stored in flash")); ``` -------------------------------- ### Get Filesystem Information (Standard) Source: https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html Fills a FSInfo structure with details about the filesystem, such as total and used bytes. Returns true on success. ```C++ FSInfo fs_info; SPIFFS.info(fs_info); ``` -------------------------------- ### begin Source: https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html Mounts the file system. Must be called before any other file system APIs. ```APIDOC ## begin ### Description Mounts the file system. This method must be called before using any other file system APIs. It returns `true` if the file system was mounted successfully, `false` otherwise. By default, `SPIFFS.begin()` will format the filesystem if it cannot mount it on the first try. Both `SPIFFS.begin()` and `LittleFS.begin()` will automatically format the filesystem if one is not detected. Be cautious, as attempting to `SPIFFS.begin()` on a LittleFS filesystem (or vice-versa) will result in data loss on that filesystem. ### Method `begin()` ### Endpoint N/A (Library Method) ### Parameters None ### Request Example ```cpp SPIFFS.begin() or LittleFS.begin() ``` ### Response * **bool** - `true` if the file system was mounted successfully, `false` otherwise. ``` -------------------------------- ### Arduino IDE Preferences Window Source: https://arduino-esp8266.readthedocs.io/en/latest/faq/a04-board-generic-is-unknown.html Illustrates where to find the sketchbook location in the Arduino IDE preferences, which is necessary for locating the esp8266 package installation folder. ```text File > Preferences (Ctrl+,) ``` -------------------------------- ### Connect to Access Point with All Parameters Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html This overload of `begin` allows specifying all connection parameters, including SSID, password, channel, BSSID, and a flag to control immediate connection. Use this for advanced control over the connection process. ```cpp WiFi.begin(ssid, password, channel, bssid, connect) ``` -------------------------------- ### Get ESP8266 CPU Instruction Cycle Count Source: https://arduino-esp8266.readthedocs.io/en/latest/libraries.html Returns the CPU instruction cycle count since the start. Useful for precise timing of short operations. ```cpp ESP.getCycleCount(); ``` -------------------------------- ### WiFi.begin(ssid, password, channel, bssid, connect) Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html Provides an advanced overload for establishing a station connection with optional parameters for channel, BSSID, and connection establishment control. ```APIDOC ## WiFi.begin(ssid, password, channel, bssid, connect) ### Description Provides an advanced overload for establishing a station connection with optional parameters for channel, BSSID, and connection establishment control. ### Method ``` WiFi.begin(ssid, password, channel, bssid, connect) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **ssid** (string) - Required - The SSID of the Access Point (up to 32 characters). - **password** (string) - Required - The password for the Access Point (minimum 8, maximum 64 characters). - **channel** (integer) - Optional - The specific channel of the Access Point. - **bssid** (string) - Optional - The MAC address of the Access Point. - **connect** (boolean) - Optional - If set to `false`, saves parameters without establishing connection. ``` -------------------------------- ### Select Specific Filesystem Configuration Source: https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html Invoke a particular filesystem configuration at sketch boot time using FLASH_MAP_SETUP_CONFIG. Choose between FLASH_MAP_OTA_FS, FLASH_MAP_MAX_FS, or FLASH_MAP_NO_FS. ```c++ FLASH_MAP_SETUP_CONFIG(FLASH_MAP_OTA_FS) void setup () { ... } void loop () { ... } ``` -------------------------------- ### Error Message for WeMos D1 Mini Source: https://arduino-esp8266.readthedocs.io/en/latest/faq/a04-board-generic-is-unknown.html An example of the error message when the 'WeMos D1 R2 & mini' board is not recognized by the Arduino IDE, often due to issues with the ESP8266 package installation. ```text Board d1_mini (platform esp8266, package esp8266) is unknown Error compiling for board WeMos D1 R2 & mini. ``` -------------------------------- ### Manual Signing - Using Signing Script Source: https://arduino-esp8266.readthedocs.io/en/latest/ota_updates/readme.html Demonstrates how to manually sign an unsigned binary using the signing.py script. This requires specifying the mode, private key, unsigned binary, and output path. ```bash /tools/signing.py --mode sign --privatekey --bin --out ``` -------------------------------- ### Complete ESP8266 WiFi Scan Example Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/scan-examples.html A full Arduino sketch for the ESP8266 that periodically triggers WiFi scans, blinks an LED, and prints scan results to the serial monitor upon completion. Includes setup for serial communication, LED, and WiFi mode. ```cpp #include "ESP8266WiFi.h" #define BLINK_PERIOD 250 long lastBlinkMillis; boolean ledState; #define SCAN_PERIOD 5000 long lastScanMillis; void setup () { Serial.begin(115200); Serial.println(); pinMode(LED_BUILTIN, OUTPUT); WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(100); } void loop() { long currentMillis = millis(); // blink LED if (currentMillis - lastBlinkMillis > BLINK_PERIOD) { digitalWrite(LED_BUILTIN, ledState); ledState = !ledState; lastBlinkMillis = currentMillis; } // trigger Wi-Fi network scan if (currentMillis - lastScanMillis > SCAN_PERIOD) { WiFi.scanNetworks(true); Serial.print("\nScan start ... "); lastScanMillis = currentMillis; } // print out Wi-Fi network scan result upon completion int n = WiFi.scanComplete(); if(n >= 0) { Serial.printf("%d network(s) found\n", n); for (int i = 0; i < n; i++) { Serial.printf("%d: %s, Ch:%d (%ddBm) %s\n", i+1, WiFi.SSID(i).c_str(), WiFi.channel(i), WiFi.RSSI(i), WiFi.encryptionType(i) == ENC_TYPE_NONE ? "open" : ""); } WiFi.scanDelete(); } } ``` -------------------------------- ### HTTP Headers for Web Page Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/server-examples.html Example HTTP headers to inform the client about the content type, connection handling, and refresh rate. Concludes with an empty line to separate headers from the body. ```text Content-Type: text/html Connection: close Refresh: 5 ``` -------------------------------- ### WiFi.begin() Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html Enables station mode and connects to the last used access point based on configuration saved in flash memory. Useful when no new connection details are needed. ```APIDOC ## WiFi.begin() ### Description Enables station mode and connects to the last used access point based on configuration saved in flash memory. Useful when no new connection details are needed. ### Method ``` WiFi.begin() ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` WiFi.begin() ``` ### Response #### Success Response (200) Implicit success upon connection. #### Response Example None ### Notes - It is possible that calling `begin` will result in the module being in STA + softAP mode if the module was previously placed into AP mode. - If you notice strange behavior with DNS or other network functionality, check which mode your module is in (see `WiFi.mode()` in the Generic Class Documentation). ``` -------------------------------- ### Client Connection Handling Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/server-class.html Explains how to accept incoming client connections and the differences in the `available` method compared to the Arduino WiFi library. ```APIDOC ## accept ### Description Returns a waiting client connection. This method is documented for the Arduino Ethernet library and is used similarly in ESP8266WiFi. ### Method `accept` ## available ### Description Deprecated since version 3.1.0. Use `accept` instead. In the ESP8266WiFi library, `available` functions identically to `accept`, returning a waiting client connection. ### Method `available` ``` -------------------------------- ### Set up Protected Soft Access Point with Options Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/soft-access-point-class.html Configure a protected Wi-Fi network with SSID, pre-shared key, channel, hidden status, and maximum connections. ```cpp WiFi.softAP(ssid, psk, channel, hidden, max_connection) ``` -------------------------------- ### esptool.py Upload Command Example Source: https://arduino-esp8266.readthedocs.io/en/latest/faq/a01-upload-failed.html This command demonstrates how to use esptool.py to write a firmware binary to an ESP8266 module. It specifies the chip, baud rate, and firmware file. ```bash $ esptool.py --after no_reset --chip esp8266 --baud 460800 write_flash 0x0 d1-mini-firmware.bin esptool.py v4.5.1 Found 1 serial ports Serial port /dev/ttyUSB0 Connecting.... Chip is ESP8266EX Features: WiFi Crystal is 26MHz MAC: 11:22:33:44:55:66 Uploading stub... Running stub... Stub running... Changing baud rate to 460800 Changed. Configuring flash size... Flash will be erased from 0x00000000 to 0x0004efff... Compressed 321440 bytes to 221714... Wrote 321440 bytes (221714 compressed) at 0x00000000 in 5.0 seconds (effective 511.4 kbit/s)... Hash of data verified. Leaving... Staying in bootloader. ``` -------------------------------- ### Install Python 3 SSL Certificates on macOS Source: https://arduino-esp8266.readthedocs.io/en/latest/installing.html Manually install SSL certificates for Python 3 on macOS if you encounter certificate verification errors during the 'get.py' script execution. This is often necessary when using Homebrew. ```bash cd "/Applications/Python 3.7/" && sudo "./Install Certificates.command" ``` -------------------------------- ### Example WiFi Scan Output Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/scan-examples.html Sample output from the complete ESP8266 WiFi scan example, showing detected networks with their SSIDs, channels, signal strength, and security type. This output appears every 5 seconds. ```text Scan start ... 5 network(s) found 1: Tech_D005107, Ch:6 (-72dBm) 2: HP-Print-A2-Photosmart 7520, Ch:6 (-79dBm) 3: ESP_0B09E3, Ch:9 (-89dBm) open 4: Hack-4-fun-net, Ch:9 (-91dBm) 5: UPC Wi-Free, Ch:11 (-79dBm) ``` -------------------------------- ### Get WiFi Channel Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/generic-class.html Retrieves the current WiFi channel. ```cpp int32_t channel (void) ``` -------------------------------- ### ESP.getCycleCount Source: https://arduino-esp8266.readthedocs.io/en/latest/libraries.html Returns the CPU instruction cycle count since start. ```APIDOC ## ESP.getCycleCount() ### Description Returns the CPU instruction cycle count since the start of the program as an unsigned 32-bit integer. This is useful for accurate timing of very short actions. ``` -------------------------------- ### WiFi.begin(ssid, password) Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html Establishes a connection to a specified Wi-Fi Access Point using its SSID and password. This is the primary method for initiating a station mode connection. ```APIDOC ## WiFi.begin(ssid, password) ### Description Establishes a connection to a specified Wi-Fi Access Point using its SSID and password. This is the primary method for initiating a station mode connection. ### Method ``` WiFi.begin(ssid, password) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ``` WiFi.begin("your_ssid", "your_password") ``` ### Response #### Success Response (200) Implicit success upon connection. #### Response Example None ``` -------------------------------- ### Get ESP8266 SDK Version Source: https://arduino-esp8266.readthedocs.io/en/latest/libraries.html Retrieves the SDK version as a character array. ```cpp ESP.getSdkVersion(); ``` -------------------------------- ### Get ESP8266 Flash Chip Speed Source: https://arduino-esp8266.readthedocs.io/en/latest/libraries.html Returns the flash chip frequency in Hz. ```cpp ESP.getFlashChipSpeed(void); ``` -------------------------------- ### Asynchronous WiFi Scan Example Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/scan-class.html Demonstrates how to perform an asynchronous WiFi scan and print the results, including SSID, channel, RSSI, and encryption type. Requires WiFi.h and Serial communication. ```cpp #include "ESP8266WiFi.h" void prinScanResult(int networksFound) { Serial.printf("%d network(s) found\n", networksFound); for (int i = 0; i < networksFound; i++) { Serial.printf("%d: %s, Ch:%d (%ddBm) %s\n", i + 1, WiFi.SSID(i).c_str(), WiFi.channel(i), WiFi.RSSI(i), WiFi.encryptionType(i) == ENC_TYPE_NONE ? "open" : ""); } } void setup() { Serial.begin(115200); Serial.println(); WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(100); WiFi.scanNetworksAsync(prinScanResult); } void loop() {} ``` -------------------------------- ### Get ESP8266 Core Version Source: https://arduino-esp8266.readthedocs.io/en/latest/libraries.html Returns a string representing the version of the ESP8266 core. ```cpp ESP.getCoreVersion(); ``` -------------------------------- ### Get PHY Mode Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/generic-class.html Retrieves the current physical layer mode of the WiFi radio. ```APIDOC ## getPhyMode ### Description Gets the current WiFi radio's physical layer (PHY) mode. ### Method WiFiPhyMode_t ### Returns The current PHY mode. ``` -------------------------------- ### Get WiFi Sleep Mode Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/generic-class.html Retrieves the current WiFi sleep mode setting. ```cpp WiFiSleepType_t getSleepMode () ``` -------------------------------- ### Set Client Certificate for Server Authentication Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/bearssl-client-secure-class.html Use setClientRSACert or setClientECCert before connect() to provide a client certificate and private key when the server requests it. ```cpp setClientRSACert(const uint8_t *certificate, size_t cert_len, const uint8_t *private_key, size_t key_len); setClientECCert(const uint8_t *certificate, size_t cert_len, const uint8_t *private_key, size_t key_len, const uint8_t *ec_params, size_t params_len); ``` -------------------------------- ### Get Current WiFi Mode Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/generic-class.html This function retrieves the current WiFi mode of the ESP8266. ```cpp WiFiMode_t getMode() ``` -------------------------------- ### Get ESP8266 Flash Chip ID Source: https://arduino-esp8266.readthedocs.io/en/latest/libraries.html Retrieves the ID of the flash chip as a 32-bit integer. ```cpp ESP.getFlashChipId(); ``` -------------------------------- ### Initialize Wi-Fi Connection Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/readme.html This code initializes the Wi-Fi connection process by calling the WiFi.begin() method with the network name and password. ```C++ WiFi.begin("network-name", "pass-to-network"); ``` -------------------------------- ### Set up Open Soft Access Point Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/soft-access-point-class.html Use this overload to quickly set up an open Wi-Fi network with a specified SSID. ```cpp WiFi.softAP(ssid) ``` -------------------------------- ### Get ESP8266 Chip ID Source: https://arduino-esp8266.readthedocs.io/en/latest/libraries.html Retrieves the unique 32-bit integer ID of the ESP8266 chip. ```cpp ESP.getChipId(); ``` -------------------------------- ### Get ESP8266 Free Heap Size Source: https://arduino-esp8266.readthedocs.io/en/latest/libraries.html Returns the amount of free memory available on the heap. ```cpp ESP.getFreeHeap(); ``` -------------------------------- ### Start Smart Config Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html Begins the Smart Config process by sniffing for special packets containing the SSID and password of the desired Access Point. Returns true on success, false otherwise. ```cpp beginSmartConfig() ``` -------------------------------- ### Get ESP8266 Reset Reason Source: https://arduino-esp8266.readthedocs.io/en/latest/libraries.html Retrieves a human-readable string indicating the reason for the last reset. ```cpp ESP.getResetReason(); ``` -------------------------------- ### Get ESP8266 Sketch MD5 Source: https://arduino-esp8266.readthedocs.io/en/latest/libraries.html Returns a lowercase string containing the MD5 hash of the current sketch. ```cpp ESP.getSketchMD5(); ``` -------------------------------- ### Create a Directory Source: https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html Creates a new directory at the specified absolute path. Returns true on success. ```C++ LittleFS.mkdir(path) ``` -------------------------------- ### Get ESP8266 CPU Frequency Source: https://arduino-esp8266.readthedocs.io/en/latest/libraries.html Returns the current CPU frequency in MHz as an unsigned 8-bit integer. ```cpp ESP.getCpuFreqMHz(); ``` -------------------------------- ### Get WiFi PHY Mode Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/generic-class.html Retrieves the current WiFi radio's physical layer mode. ```cpp WiFiPhyMode_t getPhyMode (WiFiPhyMode_t mode) ``` -------------------------------- ### Example: Printing Connected Station Count Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/soft-access-point-class.html Prints the number of stations currently connected to the soft-AP to the serial monitor. ```cpp Serial.printf("Stations connected to soft-AP = %d\n", WiFi.softAPgetStationNum()); ``` -------------------------------- ### Accept Incoming WiFi Client Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/server-examples.html In the main loop, accept new client connections to the server. This function blocks until a client connects. ```cpp void loop() { WiFiClient client = server.accept(); if (client) { // we have a new client sending some request } } ``` -------------------------------- ### mkdir Source: https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html Creates a directory at the specified path. ```APIDOC ## mkdir Creates a directory. ### Method LittleFS.mkdir(path) ### Parameters - **path** (string) - The path for the directory to create. ### Returns - **boolean**: `true` if the directory creation succeeded, `false` otherwise. ``` -------------------------------- ### File Object Methods Source: https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html Methods for interacting with individual files, including seeking, getting size, name, and status. ```APIDOC ## File Object ### Description The `File` object is returned by `SPIFFS/LittleFS.open()` and `dir.openFile()`. It provides methods for file manipulation and information retrieval. ### Methods * **seek(offset, mode)**: Moves the file position indicator. `mode` can be `SeekSet`, `SeekCur`, or `SeekEnd`. Returns `true` on success. * **position()**: Returns the current position within the file in bytes. * **size()**: Returns the total size of the file in bytes. * **name()**: Returns the short name of the file (without path). * **fullName()**: Returns the full path of the file. * **getLastWrite()**: Returns the last write time of the file (valid for read-only mode). * **getCreationTime()**: Returns the creation time of the file, if available. * **isFile()**: Returns `true` if the object represents a file. * **isDirectory()**: Returns `true` if the object represents a directory. * **close()**: Closes the file. No further operations should be performed on the `File` object after this. * **openNextFile()**: Opens the next file in the directory (use `Dir::openFile` for new code). Only valid if `File.isDirectory()` is true. ### Example Usage ```cpp File file = LittleFS.open("/myFile.txt", "r"); if (file) { Serial.println(file.size()); file.seek(10, SeekSet); Serial.println(file.position()); file.close(); } ``` ``` -------------------------------- ### Initialize Git Submodules (Windows) Source: https://arduino-esp8266.readthedocs.io/en/latest/installing.html Initialize and update git submodules to fetch external libraries required by the ESP8266 core. This step is crucial for build success. ```bash cd %USERPROFILE%\Documents\Arduino\hardware\esp8266com\esp8266 git submodule update --init ``` -------------------------------- ### subnetMask Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html Gets the subnet mask of the station's interface. The module should be connected to the access point to obtain this information. ```APIDOC ## subnetMask ### Description Get the subnet mask of the station’s interface. ### Method Signature ```cpp WiFi.subnetMask() ``` ### Notes Module should be connected to the access point to obtain the subnet mask. ``` -------------------------------- ### Get ESP8266 Sketch Size Source: https://arduino-esp8266.readthedocs.io/en/latest/libraries.html Returns the size of the currently uploaded sketch in bytes as an unsigned 32-bit integer. ```cpp ESP.getSketchSize(); ``` -------------------------------- ### Get Gateway IP Address Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html Retrieves the IP address of the gateway. Requires the module to be connected to an access point. ```cpp WiFi.gatewayIP() ``` -------------------------------- ### Separate Debug and Production Build Options Source: https://arduino-esp8266.readthedocs.io/en/latest/faq/a06-global-build-options.html This updated global header file demonstrates how to define separate build options for debug and production environments using distinct `/*@create-file:build.opt@` comment blocks. This allows for different compiler flags and defines based on the build type. ```arduino /*@create-file:build.opt:debug@ // Debug build options -DMYTITLE1="\"Running on \"" -DUMM_STATS_FULL=1 //-fanalyzer // Removing the optimization for "sibling and tail recursive calls" may fill // in some gaps in the stack decoder report. Preserves the stack frames // created at each level as you call down to the next. -fno-optimize-sibling-calls */ /*@create-file:build.opt@ // Production build options -DMYTITLE1="\"Running on \"" -DUMM_STATS_FULL=1 -O3 */ #ifndef LOWWATERMARK_INO_GLOBALS_H #define LOWWATERMARK_INO_GLOBALS_H #if defined(__cplusplus) #define MYTITLE2 "Empty" #endif #if !defined(__cplusplus) && !defined(__ASSEMBLER__) #define MYTITLE2 "Full" #endif #ifdef DEBUG_ESP_PORT // Global Debug defines // ... #else // Global Production defines // ... #endif #endif ``` -------------------------------- ### Manual Signing - C++ Declarations and Setup Source: https://arduino-esp8266.readthedocs.io/en/latest/ota_updates/readme.html Includes C++ code snippets for setting up BearSSL for signature validation within the main code. This involves declaring a public key, hash object, and signing verifier. ```cpp BearSSL::PublicKey signPubKey( ... key contents ... ); BearSSL::HashSHA256 hash; BearSSL::SigningVerifier sign( &signPubKey ); ... Update.installSignature( &hash, &sign ); ``` -------------------------------- ### Initialize Git Submodules Source: https://arduino-esp8266.readthedocs.io/en/latest/installing.html Initialize submodules to fetch external libraries required for building the ESP8266 core. This step is crucial to avoid build failures when including common libraries. ```bash cd esp8266 git submodule update --init ``` -------------------------------- ### Get ESP8266 Free Sketch Space Source: https://arduino-esp8266.readthedocs.io/en/latest/libraries.html Returns the remaining free space for the sketch in bytes as an unsigned 32-bit integer. ```cpp ESP.getFreeSketchSpace(); ``` -------------------------------- ### Get ESP8266 Heap Fragmentation Metric Source: https://arduino-esp8266.readthedocs.io/en/latest/libraries.html Returns a metric indicating the fragmentation of the heap. A value over 50% is considered problematic. ```cpp ESP.getHeapFragmentation(); ``` -------------------------------- ### Get WiFi Network Channel Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/scan-class.html Retrieves the channel of a discovered WiFi network. The networkItem is a zero-based index of the scanned network. ```cpp WiFi.channel(networkItem) ``` -------------------------------- ### Configure Flash Map Support Source: https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html Enable dynamic flash map configuration at boot time by defining FLASH_MAP_SUPPORT. This allows the sketch to select the filesystem configuration based on the flash chip size. ```c++ #define FLASH_MAP_SUPPORT 1 ``` -------------------------------- ### Get Full File Path Source: https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html Retrieve the complete path to the file within the filesystem. This includes the directory structure leading to the file. ```cpp // Filesystem: // testdir/ // file1 Dir d = LittleFS.openDir("testdir/"); File f = d.openFile("r"); // f.name() == "file1", f.fullName() == "testdir/file1" ``` -------------------------------- ### Using FPSTR with a Global Flash String Source: https://arduino-esp8266.readthedocs.io/en/latest/PROGMEM.html Demonstrates how to define a string in PROGMEM and then use `FPSTR()` to cast it to `__FlashStringHelper` for printing. ```c++ static const char xyz[] PROGMEM = "This is a string stored in flash"; Serial.println(FPSTR(xyz)); ``` -------------------------------- ### Include UDP Libraries Source: https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/udp-examples.html Include the ESP8266WiFi.h and WiFiUdp.h libraries for Wi-Fi and UDP functionality. ```cpp #include #include ``` -------------------------------- ### Get Short File Name Source: https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html Retrieve the base name of the file, without any path components. Useful for displaying or processing just the filename itself. ```cpp String name = file.name(); ```