15 Minutes or Less: Set Up Over the Air (OTA) Updates for Your NodeMCU and ESP32 Modules
In three quick steps (and less than 15 minutes), you can set up OTA updates for your NodeMCU and ESP32-based IoT projects.

In 30 Minutes or Less: Build a Wireless Sensor Network with NodeMCU, we showed you how to easily create a wireless sensor network that can send information to a Universal Sensor Hub built with a Raspberry Pi.

But what happens when you need to update the software on these modules? Climbing into building rafters or traveling to remote (or outdoor) destinations to update software can be time consuming, costly and well, just a real pain. In this article, we will show you how to enable Over the Air (OTA) updates to your NodeMCU, ESP8266, or ESP32 project in three quick steps.

Step One — Download and Install the WebOTA .zip File

At the core of this functionality is the WebOTA library. Download the .zip library:

Now Install the .zip library to your Arduino IDE:

Step Two — Download the updated Arduino Sketch to the NodeMCU

The code listing is at the bottom of this article. Make sure you switch to “raw” before copying, or just download the .zip; copying and pasting can add unwanted characters to the sketch which drives the Arduino IDE crazy. There are really just a few lines of code to add the OTA capability:

#include <WebOTA.h> // Initialize WebOTA webota.init();

Serial.flush();

delay(500); // Replace all delay() calls with webota.delay()

// Allows webota to listen for update requests during delay()

// For example: webota.delay(1000); // Finally, at the end of your sketch loop: webota.handle();

Step Three — Test out the OTA capability

Once the sketch is running, export it as a binary file (you will find it in the sub-directory for the project, under Arduino):

If you are testing with the target NodeMCU still connected to the PC via USB, open a Serial Monitor to see the OTA “in action”. To test out the OTA capability, use the following curl command to send the binary file (for this example our filename is “Attic-NodeMCU-OTA.ino.nodemcu.bin” and the target NodeMCU IP address is: 192.168.1.6):

curl -F “file=@Attic-NodeMCU-OTA.ino.nodemcu.bin” 192.168.1.6:8080/webota

Here’s a short video of an OTA in action:

Source code:

With Machinechat’s JEDI One software you can quickly enable cost-effective on-prem professional data monitoring, visualization and storage for your IoT ESP32 and NodeMCU projects. Now you can make sure that your project stays up-to-date without having to leave the comfort of your desk.

Additional resources:

Machinechat.io
['Machinechat Jedi']
['Raspberry Pi', 'Technology', 'IoT', 'Programming', 'Nodemcu']