Over the Air(OTA) Update of Nodemcu(esp8266) Using MQTT)

We are a team of IoT & Embedded Systems developers. We are working in Raspberry Pi and Arduino.

Intro: Over the Air(OTA) Update of Nodemcu(esp8266) Using MQTT)

In this project I'm going to tell you about how to use Over-the-Air(OTA) software update for nodemcu(esp8266). So In this case we are taking a project as we have previously explained named "Wireless Attendance System Using Wi-Fi (ESP8266) with MySQL" you can get the details here

So what actually I'm going to do here, suppose I've installed this system somewhere in a office for attendance of employees or may be in school for attendance of student, now if I need to add more employees or student then what I'll do I'll take the nodemcu and edit the code from system. So this will be a huge problem, as I don't want to mess up with these things like take out the nodemcu and connect to laptop or PC and update the code. So what is the sollution? Here is the solution and that is we can update the code Over-the-Air(OTA) without even touching the nodemcu. So this is really a cool thing. So here I'll tell you how we can update the code Over-the-Air.

Step 1: Installation of All Software

a) Installation of LAMP Server and PHPMYADMIN:
First of all let us clear one thing that we are using LAMP Server for this project. In case if you don't know what is LAMP, it is an abbreviation of Linux, Apache, MySQL and PHP. So if you have windows or may be MAC then you have to install WAMP and MAMP respectively.

So what we are explaining that is only for LAMP server: and here are the steps for installing LAMP server

1. Install Apache

sudo apt-get install apache2

2. Install MySQL:

sudo apt-get install mysql-server

3. Install PHP:

sudo apt-get install php5 libapache2-mod-php5

4. Restart Server:

sudo /etc/init.d/apache2 restart

5. Check Apache http://localhost/ if you install these steps successfully then you will get the apche page like the image above.

Here we are using PHPMYADMIN that is the web interface of MySQL so for that you have to install that also and the command for that is:

sudo apt-get install phpmyadmin

b) Installation of Arduino IDE:

You can download the latest Arduino IDE from this link:


Step 2: Component Used:

As for OTA update we have chosen rfid access code, you can chose other program code as well.

So for this project you need :
1) Node MCU V3

2) RFID RC522 Reader with Tag

3) Jumper Wire

1) Node MCU V3 : Node MCU is an open source IOT platform. It includes firmware which runs on the ESP8266 Wi- Fi SoC from hardware which is based on the ESP-12 module. The term "Node MCU" by default refers to the firmware rather than the dev kits.

2) RFID RC522 Reader with Tag: There are cheap RFID modules that can read and write Mifare's tags and being sold at several web stores, like eBay and included with many "starter kits" nowadays. Simply search RFID-RC522 (MF-RC522). The microcontroller and card reader uses SPI for communication (chip supports I2C and UART protocols but not implemented on library). The card reader and the tags communicate using a 13.56MHz electromagnetic field.

Step 3: How to Program NodeMCU Using Arduino IDE

Firstly open the Arduino IDE.


Go to the File then click on preferences tab like Figure 1.

Now you have to copy in the additional board manager URL- http://arduino.esp8266.com/stable/package_esp8266... then click ok

Step 3:

Now go to the Tools then select Board Manager. open window like figure 2. Just Scroll down on that window and search for esp8266 by ESP8266 Community and then click on install button. Step4: Restart your Arduino IDE Step5: Now goto Tools then Select like figure 3

Step 4: Circuit Diagram

Circuit Diagram of this project is given above.
Here are the connections of our circuit:



MOSI ----------------------------GPIO13--------D7

MISO ----------------------------GPIO12--------D6

SCK ----------------------------- GPIO14--------D5

GND -----------------------------GND

3.3V ------------------------------3.3V

RST ------------------------------not connected

IRQ -------------------------------not connected

Step 5: Importing Necessary Library for NodeMCU

Here we are using RFID RC522. So you have to import MFRC522. Here is a GitHub link:


Step 6: Why We Need MQTT

Here we don't necessarily need MQTT. What is the purpose of MQTT here that we want to make one toggle button in this case. So when it will be 0 then our nodemcu will be in programming mode and if it is 1 then it will be in OTA mode. So if you want to update the installed nodemcu just click the button and value will be 1, So here you can update the code and then after successful update you can again click and make it 0 for programming mode.

If you don't want to go with MQTT then you can chose one push button as well which is connected to one gpio of nodemcu, but again the problem is that button will always be there connected to nodemcu, and also every time you need to press that button for making it OTA or programming mode.

So That's why we thought that we should go with some soft toggle button and we can easily make that using MQTT.

Step 7: How to Use MQTT

In this step I'm going to explain you about how we can create Mqtt Dashboard. So for that we are using Adafruit Mqtt. The UI of Adafruit IO is very user-friendly. So Step by step I'm going to explain you about this. So you just follow the process.

Here are the steps:

1. First you need to create account in io.adafruit.com

2. You will get the page like above, so fill these details, now when you will sign in you will get the page like above

3. In this page in the top right corner you will get some icons. From this you can click on 'Create a new block'. So from here you can create toggle button.

As we have given the name Bulb1 for our toggle button. When you will create that button then you need to give value 1 and 0 for for High and Low respectively, remember these values are not a numeric value, these are string values which we will convert to integer through our arduino code

Step 8: How to Write the Code

In this case we are merging three codes one is for MQTT and 2nd one is for main program and the other one is for OTA bootloader. For main program we are using Rfid access details and send it to phpmyadmin.

You can download the source code from the below link.



    • Furniture Contest 2018

      Furniture Contest 2018
    • Audio Contest 2018

      Audio Contest 2018
    • Metalworking Contest

      Metalworking Contest