Login

Upload code to NodeMCU using OTA

Objectives

  • To configure the NodeMCU wirelessly through OTA
  • For faster processing  as many devices can be deployed simultaneously

Things

  1. NodeMCU board (quantity: 1 no.)
  2. Micro USB cable A to B (quantity: 1 no.)
  3. Arduino IDE on your computer
  4. External power source for wireless communication

Let’s Begin!

Over The Air (OTA) is a standard for transmission and reception of application related information in a wireless communications system.Follow the steps below.

Install Python 2.7.11

Make sure all Arduino windows are closed. Download the Windows MSI Installer for Python 2.7.11 from this link and install.

During installation, first choose “Install for all users” and then make sure to select “Add python.exe to path” as shown below

Step 1: Open Arduino IDE and copy paste the code given below.

Step 2: Edit the code and add your WiFi credentials.

Step 3:Open serial monitor,then you will see the IP address of your module if it is connected to the network.

Step 4: A new port will appear at Tools > Port > Network ports.

Note: if network port doesn’t show up then restart your Arduino IDE as Administrator; if it doesn’t help then check your firewall settings.

Step 5: Now your device is ready for OTA update.You can upload any code to your device remotely.

Final Code

To copy the code, right click on view raw at the bottom of the code, click on open link in new tab and then copy the code.

You need to have a piece of code inside setup,plus a bunch of functions called OTA,plus a little bit of code inside loop.This is because,when you record over the air, you have to put a code inside ESP that allows this device to communicate over the IP network with Arduino IDE.

  • onStart() – configures what will be executed when ArduinoOTA starts.
  • onEnd() – configures what will be executed when ArduinoOTA ends.
  • onProgress() – configures what will be executed when the sketches is  burning in the ESP.
  • onError() – configures what will be executed when ArduinoOTA finds and error.
  • begin() – initializes ArduinoOTA.
  • handle() – it is an abstract reference to a resource,that references variables on the blocks of memory.

Upload the code

To copy the code, right click on view raw at the bottom of the code, click on open link in new tab and then copy the code.

Step 1: Enter the final code in the Arduino IDE window.

Step 2: Compile/ verify the code by clicking on the verify button.

Step 3: Upload the code by clicking on the upload button, which is right next to the verify button.

Step 4: If you encounter any errors, you need to go back to the code and fix the errors. Check if the correct board and port is selected.

SEE ALL Add a note
YOU
Add your Comment

We would love to see what you build out of these learnings!

Click here to submit your projects, share it with the world and stand a chance to be rewarded.

top

Knowledge and Content by Li2 Technologies | © 2021 NASSCOM Foundation | All rights reserved

X