Uploading IoT Application From Command Line
Appearance
Upload Code to NodeMCU (ESP8266) Using CMD
Prerequisites
- Install Python from https://www.python.org/downloads (Check "Add Python to PATH")
- Install required tools:
pip install esptool pyserial
- Install Arduino IDE: https://www.arduino.cc/en/software
Step 1: Compile the Sketch
- Open the sketch in Arduino IDE
- Select board:
NodeMCU 1.0 (ESP-12E Module)under Tools → Board - Go to Sketch → Export Compiled Binary
- A
.binfile will be generated in the sketch folder
Step 2: Find the COM Port
- Plug in NodeMCU
- Open Command Prompt and type:
mode - Look for a line like
Status for device COM3:
Step 3: Flash the Code
- Open CMD and go to the folder where the .bin file is located:
cd "C:\Users\YourName\Documents\Arduino\MySketch"
- Upload the binary to NodeMCU:
python -m esptool --port COM3 --baud 115200 write_flash 0x00000 MySketch.ino.bin
(Optional) Erase Flash Before Upload
python -m esptool --port COM3 erase_flash
Notes
- Make sure the COM port matches the one detected