Loading firmware to NodeMCU Over The Air – Part 1

Deepak Radhakrishnan
()

Introduction

Welcome back to Tech Rover, today’s post is all about how to Load firmware to NodeMCU using OTA(Over the Air). This method will be beneficial when you are building some product using NodeMCU. It is useful for the updation of the firmware, to perform security patches or on the other hand, for a total firmware upgrade.

Contents

Overview

OTA is extremely handy to load firmware to your ESP module wireless. So let me walk you through following methods to achieve it:

  • Arduino IDE
  • Web Browser
  • HTTP Server

Let’s take one step at a time, I will introduce you to Programming ESP module Over The Air using Arduino IDE in part 1. Later on, we will be discussing OTA using a web browser and HTTP server in the upcoming tutorials. Wait for it! In any case, Arduino IDE is used initially to set up OTA firmware over the serial port.

How Secure is it?

For you to update the firmware “Over The Air ” the module has to be connected to a network, right. It’s true that it creates chances of the module being hacked and packed with some other program. In order to cut down the possibility of being hacked, you can make use of various techniques such as: try protecting your uploads with the help of a password, selecting certain OTA port, hashing the password, etc.

Fortunately, various security practices are already built-in and do not call for any subsidiary coding on part of the developer. ArduinoOTA and espota.py make use of Digest-MD5 to verify the upload. By using MD5 checksum, the uprightness of transferred data is verified on the ESP side.

Safety Practices

OTA process get hold of ESP’s resources and bandwidth during the upload. Then the module is restarted and a new sketch will be executed. Beware, this might affect the current functionality of the device during the process.

So let me warn you to decide on, how to put this equipment into a safe state before the updation begins. For instance, your module might be controlling a solenoid valve, and as OTA takes over the control, when the valve is in the open state and after the OTA finished it might be left open.

I will help you with some functions to handle your application as changes occur through OTA.

void onStart(OTA_CALLBACK(fn));
void onEnd(OTA_CALLBACK(fn));
void onProgress(OTA_CALLBACK_PROGRESS(fn));
void onError(OTA_CALLBACK_ERROR (fn));

Loading the Basic OTA firmware

To implement OTA, the ESP board support must be prefixed to Arduino IDE. Feel free to skip step 2, if you are familiar with adding ESP board support on your own. Those who need assistance to add ESP board support, follow my lead. 😊

Step 1 : Adding ESP Board Support

Copy the code that follows and paste the below URL in Preferences -> Additional Boards Manager URLs

http://arduino.esp8266.com/stable/package_esp8266com_index.json

Select Board Manager from tools->Board->Board Manager and search for ESP. Install the module.

Step 2 : Loading Basic OTA Firmware

  1. Select Basic OTA from Examples->Arduino OTA
  2. Configure your wifi credentials
  3. Load the program using serial port

Loading New Program Over The Air

  1. Open the Basic OTA code
  2. Add your new program along with Basic OTA code
  3. Go to tools->port
  4. You can see a new section named “network ports
  5. Select your device listed under network ports
  6. Upload your code

Loading Updates Over The Air

  1. Make changes in the previous code
  2. Select the same network port previously selected
  3. Compile and upload your sketch

Conclusion

That’s all for this short update. Stay tuned for our next updates. Have a lovely weekend! Next tutorial you will get to explore on How to Load firmware Over the Air using Web Browser. I wish you good luck and happy coding. 😊

How useful was this post?

Click on a starts to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow me on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

%d bloggers like this: