Uploading IoT Application From Command Line
Appearance
Deploy NodeMCU (ESP8266) Code via Command Line
Prerequisites
- Install Python: https://www.python.org/downloads
- Install esptool:
pip install esptool
- Install Arduino IDE: https://www.arduino.cc/en/software
- (Optional) Install USB-to-Serial Drivers:
- CH340: https://sparks.gogo.co.nz/ch340.html
- CP210x: https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers
Step 1: Compile Code
- Open your sketch in Arduino IDE
- Go to:
Sketch → Export Compiled Binary - Find the
.binfile in your sketch folder (e.g.,MySketch.ino.bin)
Step 2: Identify COM Port
- Plug in NodeMCU
- Open Command Prompt and run:
mode
- Note your device COM port (e.g.,
COM3)
Step 3: Flash Firmware
- Navigate to your compiled sketch folder:
cd "C:\Users\<YourName>\Documents\Arduino\MySketch"
- Flash the firmware:
python -m esptool --port COM3 --baud 115200 write_flash 0x00000 MySketch.ino.bin
Optional: Erase Flash Before Writing
python -m esptool --port COM3 erase_flash
Step 4: View Serial Monitor Output
- Install pyserial (if not already):
pip install pyserial
- View Serial Monitor:
python -m serial.tools.miniterm COM3 115200
- Press
Ctrl + ]to exit
Notes
- Ensure no other serial monitor (like Arduino IDE) is open when using miniterm.
- Make sure baud rate matches your
Serial.begin()setting.