Jump to content

Uploading IoT Application From Command Line

From cognifront

Uploading Code to NodeMCU (ESP8266) via Command Line

This guide explains how to compile and upload code to a NodeMCU (ESP8266) board using the command line, and how to monitor its serial output without using the Arduino IDE interface.

Prerequisites

  1. Install Python from: https://www.python.org/downloads
 - Make sure to check "Add Python to PATH" during installation.
  1. Open a command prompt and install the required Python packages:

pip install esptool

  1. Install the Arduino IDE from: https://www.arduino.cc/en/software

Step 1: Compile the Sketch

  1. Open your `.ino` sketch in the Arduino IDE.
  2. Go to:

Tools → Board → NodeMCU 1.0 (ESP-12E Module)

  1. Then export the compiled binary:

Sketch → Export Compiled Binary

  1. The binary file (e.g., MySketch.ino.bin) will appear in the same folder as your sketch.

Step 2: Identify the COM Port

  1. Connect your NodeMCU via USB.
  2. Open the command prompt and type:

mode

  1. Look for a line similar to:

Status for device COM3: - Note the COM port (e.g., COM3), which will be used in later steps.

Step 3: Flash the Code to NodeMCU

  1. Navigate to the folder where your `.bin` file is saved:

cd "C:\Users\YourName\Documents\Arduino\MySketch"

  1. Run the following command to upload the binary:

python -m esptool --port COM3 --baud 115200 write_flash 0x00000 MySketch.ino.bin

- Replace COM3 with your actual COM port. - Replace MySketch.ino.bin with the correct filename if different.

(Optional) Erase Flash Before Uploading

  1. If you want to erase previous data on the chip before uploading new code:

python -m esptool --port COM3 erase_flash

Notes

  • Close the Arduino IDE's serial monitor before using the command-line monitor to avoid port conflicts.
  • If the command esptool or miniterm is not recognized, make sure Python's Scripts folder is added to your system PATH.
  • USB-to-Serial drivers such as CH340 or CP210x may be required depending on your NodeMCU model.