### PlatformIO Build System Targets CLI Examples Source: https://context7.com/platformio/platform-espressif8266/llms.txt Command-line examples for invoking PlatformIO build system targets such as build, size, upload, buildfs, uploadfs, and erase. ```bash # Build and show size pio run -e nodemcuv2 -t size # Flash firmware via serial (auto-detects port) pio run -e nodemcuv2 -t upload # Flash firmware via OTA (requires upload_protocol = espota + upload_port = ) pio run -e ota -t upload # Build LittleFS image from data/ directory and flash it pio run -e nodemcuv2 -t uploadfs # Erase all flash contents pio run -e nodemcuv2 -t erase ``` -------------------------------- ### PlatformIO Project Commands Source: https://github.com/platformio/platform-espressif8266/blob/develop/examples/arduino-wifiscan/README.md Use these commands to navigate to the example directory, build the project, upload the firmware, and clean build files. ```shell # Change directory to example $ cd platform-espressif8266/examples/arduino-wifiscan # Build project $ pio run # Upload firmware $ pio run --target upload # Clean build files $ pio run --target clean ``` -------------------------------- ### PlatformIO Project Commands Source: https://github.com/platformio/platform-espressif8266/blob/develop/examples/arduino-webserver/README.md Use these commands to navigate to the example directory, build the project, upload firmware, and clean build files. ```shell # Change directory to example $ cd platform-espressif8266/examples/arduino-webserver ``` ```shell # Build project $ pio run ``` ```shell # Upload firmware $ pio run --target upload ``` ```shell # Build specific environment $ pio run -e nodemcuv2 ``` ```shell # Upload firmware for the specific environment $ pio run -e nodemcuv2 --target upload ``` ```shell # Clean build files $ pio run --target clean ``` -------------------------------- ### ESP8266 RTOS SDK Blink Example Configuration Source: https://context7.com/platformio/platform-espressif8266/llms.txt PlatformIO configuration for an ESP8266 RTOS SDK blink example using the nodemcuv2 board. ```ini ; platformio.ini [env:nodemcuv2] platform = espressif8266 framework = esp8266-rtos-sdk board = nodemcuv2 ``` -------------------------------- ### Board Manifest Schema Example Source: https://context7.com/platformio/platform-espressif8266/llms.txt Example of a board manifest JSON file for NodeMCU 1.0 (ESP-12E Module). This file defines build settings, connectivity, supported frameworks, and upload parameters. ```json // boards/nodemcuv2.json — NodeMCU 1.0 (ESP-12E Module) { "build": { "arduino": { "ldscript": "eagle.flash.4m1m.ld" // default LD script for Arduino }, "core": "esp8266", "extra_flags": "-DESP8266 -DARDUINO_ARCH_ESP8266 -DARDUINO_ESP8266_NODEMCU_ESP12E", "f_cpu": "80000000L", // 80 MHz CPU clock "f_flash": "40000000L", // 40 MHz flash clock "flash_mode": "dio", "mcu": "esp8266", "variant": "nodemcu" }, "connectivity": ["wifi"], "frameworks": ["arduino", "esp8266-rtos-sdk", "esp8266-nonos-sdk"], "name": "NodeMCU 1.0 (ESP-12E Module)", "upload": { "maximum_ram_size": 81920, // 80 KB SRAM "maximum_size": 4194304, // 4 MB flash "require_upload_port": true, "resetmethod": "nodemcu", // DTR-based auto-reset "speed": 115200 }, "url": "http://www.nodemcu.com/", "vendor": "NodeMCU" } ``` -------------------------------- ### PlatformIO Project Commands Source: https://github.com/platformio/platform-espressif8266/blob/develop/examples/arduino-asyncudp/README.md Commands to navigate to an example directory, build the project, upload firmware, and clean build files using PlatformIO. ```shell # Change directory to example $ cd platform-espressif8266/examples/arduino-asyncudp # Build project $ pio run # Upload firmware $ pio run --target upload # Clean build files $ pio run --target clean ``` -------------------------------- ### Arduino Blink Example Configuration Source: https://context7.com/platformio/platform-espressif8266/llms.txt PlatformIO configuration for the NodeMCUv2 board using the Arduino framework to run a basic blink sketch. ```ini ; platformio.ini [env:nodemcuv2] platform = espressif8266 framework = arduino board = nodemcuv2 ``` -------------------------------- ### Expected Serial Output for Web Server Source: https://context7.com/platformio/platform-espressif8266/llms.txt The expected serial monitor output when the Arduino HTTP web server example connects to Wi-Fi and starts. ```text Connected. IP: 192.168.1.42 MDNS responder started HTTP server started ``` -------------------------------- ### Arduino HTTP Web Server Example Code Source: https://context7.com/platformio/platform-espressif8266/llms.txt Arduino sketch that creates a Wi-Fi station, hosts an HTTP server, and registers an mDNS hostname for easy access. ```cpp // src/HelloServer.ino #include #include #include #include const char* ssid = "MyNetwork"; const char* password = "MyPassword"; ESP8266WebServer server(80); const int led = 13; void handleRoot() { digitalWrite(led, 1); server.send(200, "text/plain", "hello from esp8266!"); digitalWrite(led, 0); } void handleNotFound() { String message = "File Not Found\n\nURI: " + server.uri(); message += "\nMethod: " + String(server.method() == HTTP_GET ? "GET" : "POST"); server.send(404, "text/plain", message); } void setup() { pinMode(led, OUTPUT); Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("\nConnected. IP: " + WiFi.localIP().toString()); MDNS.begin("esp8266"); // accessible at http://esp8266.local server.on("/", handleRoot); server.on("/inline", []() { server.send(200, "text/plain", "inline handler"); }); server.onNotFound(handleNotFound); server.begin(); Serial.println("HTTP server started"); } void loop() { server.handleClient(); // must be called continuously MDNS.update(); } ``` -------------------------------- ### Arduino Blink Example Code Source: https://context7.com/platformio/platform-espressif8266/llms.txt The simplest Arduino sketch that blinks the on-board LED using standard Arduino functions. ```cpp // src/main.cpp #include "Arduino.h" void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop() { digitalWrite(LED_BUILTIN, HIGH); // LED on delay(1000); digitalWrite(LED_BUILTIN, LOW); // LED off delay(1000); } ``` -------------------------------- ### ESP8266 Non-OS SDK Blink Example Source: https://context7.com/platformio/platform-espressif8266/llms.txt A bare-metal C application using the Non-OS SDK with `os_timer` for periodic GPIO toggling. `user_rf_cal_sector_set` is mandatory. ```ini ; platformio.ini [env:nodemcuv2] platform = espressif8266 framework = esp8266-nonos-sdk board = nodemcuv2 build_flags = -I include monitor_speed = 74880 ``` ```c // src/user_main.c #include "osapi.h" #include "user_interface.h" static os_timer_t ptimer; // Required by SDK: return RF calibration sector based on flash size uint32 ICACHE_FLASH_ATTR user_rf_cal_sector_set(void) { enum flash_size_map size_map = system_get_flash_size_map(); switch (size_map) { case FLASH_SIZE_4M_MAP_256_256: return 128 - 5; case FLASH_SIZE_8M_MAP_512_512: return 256 - 5; default: return 0; } } void blinky(void *arg) { static uint8_t state = 0; GPIO_OUTPUT_SET(2, state); state ^= 1; } void ICACHE_FLASH_ATTR user_init(void) { gpio_init(); uart_init(115200, 115200); os_printf("SDK version: %s\n", system_get_sdk_version()); wifi_set_opmode(NULL_MODE); // disable Wi-Fi PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); // set GPIO2 as output os_timer_disarm(&ptimer); os_timer_setfn(&ptimer, (os_timer_func_t *)blinky, NULL); os_timer_arm(&ptimer, 2000, 1); // fire every 2 s, repeat } ``` -------------------------------- ### ESP8266 RTOS SDK Blink Example Code Source: https://context7.com/platformio/platform-espressif8266/llms.txt FreeRTOS-based application that toggles GPIO16 every second using vTaskDelay for non-blocking delay. Requires the esp8266-rtos-sdk framework. ```c // src/main.c #include "esp_common.h" #include "freertos/task.h" #include "gpio.h" uint32 user_rf_cal_sector_set(void) { flash_size_map size_map = system_get_flash_size_map(); switch (size_map) { case FLASH_SIZE_4M_MAP_256_256: return 128 - 5; case FLASH_SIZE_8M_MAP_512_512: return 256 - 5; default: return 0; } } void task_blink(void* ignore) { gpio16_output_conf(); while (true) { gpio16_output_set(0); vTaskDelay(1000 / portTICK_RATE_MS); // 1 s ON gpio16_output_set(1); vTaskDelay(1000 / portTICK_RATE_MS); // 1 s OFF } vTaskDelete(NULL); } // Entry point — create FreeRTOS task and return void user_init(void) { xTaskCreate(&task_blink, "startup", 2048, NULL, 1, NULL); } ``` -------------------------------- ### Build and Upload Command Source: https://context7.com/platformio/platform-espressif8266/llms.txt Command to build the project for the 'nodemcuv2' environment and upload it to the device. ```bash pio run -e nodemcuv2 --target upload ``` -------------------------------- ### Arduino Framework Build Script Integration Source: https://context7.com/platformio/platform-espressif8266/llms.txt Delegates build system control to the platformio-build.py script bundled with the framework package when 'framework = arduino' is set. ```python # builder/frameworks/arduino.py from os.path import join from SCons.Script import COMMAND_LINE_TARGETS, DefaultEnvironment, SConscript if "nobuild" not in COMMAND_LINE_TARGETS: SConscript( join( DefaultEnvironment().PioPlatform().get_package_dir( "framework-arduinoespressif8266" ), "tools", "platformio-build.py", ) ) ``` -------------------------------- ### Espressif8266Platform Class Configuration Source: https://context7.com/platformio/platform-espressif8266/llms.txt Configures default packages, including toolchain version selection based on framework and marking filesystem tools as non-optional for 'buildfs' targets. ```python from platformio.public import PlatformBase class Espressif8266Platform(PlatformBase): def configure_default_packages(self, variables, targets): """ - Uses the newer toolchain (~2.x) only for Arduino; Non-OS/RTOS SDK builds fall back to the older ~1.40802.0 toolchain. - Marks mkspiffs and mklittlefs as non-optional when the 'buildfs' target is requested. """ framework = variables.get("pioframework", []) if "arduino" not in framework: self.packages['toolchain-xtensa']['version'] = "~1.40802.0" if "buildfs" in targets: self.packages['tool-mkspiffs']['optional'] = False self.packages['tool-mklittlefs']['optional'] = False return super().configure_default_packages(variables, targets) def get_boards(self, id_=None): """ Wraps the base implementation to ensure every board has upload.protocols = ["esptool", "espota"] and upload.protocol = "esptool" as defaults. """ result = super().get_boards(id_) if not result: return result if id_: return self._add_upload_protocols(result) for key, value in result.items(): result[key] = self._add_upload_protocols(result[key]) return result ``` -------------------------------- ### Configure Development Espressif8266 Platform Source: https://github.com/platformio/platform-espressif8266/blob/develop/README.md Use this configuration in your platformio.ini file to set up the development version of the Espressif8266 platform directly from its GitHub repository. ```ini [env:development] platform = https://github.com/platformio/platform-espressif8266.git board = ... ... ``` -------------------------------- ### Platform Configuration in platformio.ini Source: https://context7.com/platformio/platform-espressif8266/llms.txt Configure the Espressif 8266 platform in `platformio.ini` for different build environments. Specify the platform, framework, and board. Optional overrides for linker scripts and upload protocols are supported. ```ini ; Minimal Arduino project targeting NodeMCU v2 (ESP-12E) [env:nodemcuv2] platform = espressif8266 framework = arduino board = nodemcuv2 ; Pin a specific platform release [env:pinned] platform = espressif8266@4.2.1 framework = arduino board = d1_mini ; Development build directly from GitHub [env:dev] platform = https://github.com/platformio/platform-espressif8266.git framework = arduino board = huzzah ; Custom linker script (overrides board default) [env:custom_flash] platform = espressif8266 framework = arduino board = d1 board_build.ldscript = eagle.flash.1m256.ld ; OTA upload [env:ota] platform = espressif8266 framework = arduino board = nodemcuv2 upload_protocol = espota upload_port = 192.168.1.105 ; IP address of the running ESP8266 ; Serial monitor with exception decoder [env:debug_monitor] platform = espressif8266 framework = arduino board = nodemcuv2 build_type = debug monitor_filters = esp8266_exception_decoder monitor_speed = 115200 ``` -------------------------------- ### Configure Stable Espressif8266 Platform Source: https://github.com/platformio/platform-espressif8266/blob/develop/README.md Use this configuration in your platformio.ini file to set up the stable version of the Espressif8266 platform. ```ini [env:stable] platform = espressif8266 board = ... ... ``` -------------------------------- ### Async UDP Communication with ESP8266 Source: https://context7.com/platformio/platform-espressif8266/llms.txt Connects to a UDP server, registers an asynchronous packet callback, and broadcasts UDP messages. Requires the ESPAsyncUDP library. ```ini ; platformio.ini [env:nodemcuv2] platform = espressif8266 framework = arduino board = nodemcuv2 lib_deps = ESPAsyncUDP ``` ```cpp // src/AsyncUDPClient.ino #include #include "ESPAsyncUDP.h" const char* ssid = "MyNetwork"; const char* password = "MyPassword"; AsyncUDP udp; void setup() { Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); if (WiFi.waitForConnectResult() != WL_CONNECTED) { Serial.println("WiFi Failed"); while (true) delay(1000); } // Connect to a UDP server at 192.168.1.100:1234 if (udp.connect(IPAddress(192, 168, 1, 100), 1234)) { Serial.println("UDP connected"); udp.onPacket([](AsyncUDPPacket packet) { Serial.printf("From %s:%u -> %u bytes: ", packet.remoteIP().toString().c_str(), packet.remotePort(), packet.length()); Serial.write(packet.data(), packet.length()); Serial.println(); packet.printf("Got %u bytes", packet.length()); // reply }); udp.print("Hello Server!"); // send initial unicast message } } void loop() { delay(1000); udp.broadcastTo("Anyone here?", 1234); // periodic broadcast } ``` -------------------------------- ### Esp8266ExceptionDecoder Monitor Filter Configuration Source: https://context7.com/platformio/platform-espressif8266/llms.txt PlatformIO configuration to enable the Esp8266ExceptionDecoder monitor filter for debugging ESP8266 crashes. Requires build_type = debug. ```ini ; platformio.ini — enable the decoder [env:nodemcuv2] platform = espressif8266 framework = arduino board = nodemcuv2 build_type = debug ; required for addr2line to work monitor_filters = esp8266_exception_decoder monitor_speed = 115200 ``` -------------------------------- ### Scan for Wi-Fi Networks with ESP8266 Source: https://context7.com/platformio/platform-espressif8266/llms.txt Scans for nearby access points and prints SSID, RSSI, and encryption status. Ensure WiFi library is included. ```cpp #include "ESP8266WiFi.h" void setup() { Serial.begin(115200); WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(100); } void loop() { Serial.println("scan start"); int n = WiFi.scanNetworks(); if (n == 0) { Serial.println("no networks found"); } else { Serial.printf("%d networks found\n", n); for (int i = 0; i < n; i++) { // SSID (RSSI) [open/*secured] Serial.printf("%2d: %-32s (%d) %s\n", i + 1, WiFi.SSID(i).c_str(), WiFi.RSSI(i), WiFi.encryptionType(i) == ENC_TYPE_NONE ? "open" : "*"); delay(10); } } delay(5000); // re-scan every 5 s } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.