
ArduinoOTA ESP32: Wireless Update from the Arduino IDE
Introduction
Updating firmware on the ESP32 using a USB cable can be inconvenient, especially if your ESP32 board is deployed in a hard-to-reach location. This is where ArduinoOTA (Over-The-Air) updates come in handy. Using ArduinoOTA, you can wirelessly upload new code to your ESP32 without a physical connection, making development and maintenance much easier.
This guide will walk you through setting up ArduinoOTA for your ESP32 board using the Arduino IDE for seamless wireless updates.
What is ArduinoOTA?
ArduinoOTA is a library that enables wireless code updates for ESP32 and ESP8266 boards. It establishes a Wi-Fi connection between the development environment (Arduino IDE) and the ESP32, allowing firmware updates over the air.
Key Benefits of ArduinoOTA:
- Wireless Firmware Updates: No physical USB connection needed.
- Remote Deployment: Perfect for devices installed in hard-to-access areas.
- Time-Saving: Faster and more convenient than manual USB uploads.
- Stable and Secure: Supports password protection for secure firmware deployment.
Requirements
Before you proceed, ensure you have the following:
- ESP32 Development Board
- Arduino IDE (Latest Version)
- ESP32 Board Package installed in Arduino IDE
- Stable Wi-Fi Network
Step 1: Install ArduinoOTA Library
The ArduinoOTA library is included in the ESP32 core package. If you haven’t installed the ESP32 board package yet:
- Open Arduino IDE.
- Go to File → Preferences.
- In the “Additional Board Manager URLs” field, add:
https://dl.espressif.com/dl/package_esp32_index.json
- Go to Tools → Board → Board Manager.
- Search for ESP32 and click Install.
Step 2: ArduinoOTA Code for ESP32
Now, create a new sketch in Arduino IDE and add the following code for OTA updates:
#include <WiFi.h>
#include <ArduinoOTA.h>
// Wi-Fi Credentials
const char* ssid = "YOUR_SSID"; // Replace with your Wi-Fi SSID
const char* password = "YOUR_PASSWORD"; // Replace with your Wi-Fi password
void setup() {
// Start Serial Monitor
Serial.begin(115200);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi Connected");
// Initialize ArduinoOTA
ArduinoOTA.setHostname("ESP32_OTA_Device");
ArduinoOTA.onStart([]() {
String type = (ArduinoOTA.getCommand() == U_FLASH) ? "sketch" : "filesystem";
Serial.println("Start updating " + type);
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
Serial.println("Ready for OTA Updates");
}
void loop() {
ArduinoOTA.handle();
delay(1000);
}
Step 3: Upload the Code via USB
- Connect your ESP32 to your PC via USB.
- In Arduino IDE, go to Tools → Board and select ESP32 Dev Module.
- In Tools → Port, select the appropriate COM port for your ESP32.
- Upload the sketch via USB to initially program your ESP32 with OTA support.
Step 4: Wireless OTA Update Setup
Once your ESP32 has the OTA firmware:
- Disconnect the USB cable.
- Restart your ESP32 — it will now connect to Wi-Fi and await OTA updates.
- In Arduino IDE, go to Tools → Port, and you should see a new network port named “ESP32_OTA_Device”.
- Select this network port.
- Now you can wirelessly upload new code changes without physically reconnecting the ESP32 to your computer.
Step 5: Testing OTA Firmware Update
To test OTA updates:
- Modify your sketch slightly (e.g., add a new
Serial.print()
message inloop()
). - Select the “ESP32_OTA_Device” network port from the Tools → Port menu.
- Click the Upload button — your code will upload wirelessly.
- Monitor the changes in the Serial Monitor.
Step 6: Adding OTA Security (Optional but Recommended)
To enhance security during OTA updates, add password protection:
ArduinoOTA.setPassword("your_OTA_password");
This will prompt for a password each time you upload firmware via OTA, ensuring better security for your ESP32 device.
Step 7: Troubleshooting Common Issues
If you face issues during the OTA update process:
- No Network Port Visible: Ensure your ESP32 and computer are on the same Wi-Fi network.
- ESP32 Not Responding: Check that
ArduinoOTA.handle()
is present inside theloop()
. - Update Fails at 0% Progress: Verify your ESP32 has sufficient free memory for OTA updates.
- Authentication Errors: Double-check your OTA password if enabled.
Conclusion
Using ArduinoOTA with ESP32 is a powerful way to streamline firmware updates wirelessly. By enabling OTA updates, you can improve your workflow, reduce development time, and manage devices deployed in remote areas more efficiently.
If you have any questions, feel free to ask in the comments.
Pingback: Espruino - open-source JavaScript interpreter for microcontrollers
Pingback: Android Things - OS for IoT and embedded devices - IoTbyHVM - Explore TechBytes
Pingback: ESP32 BLE with DHT11 - ESP8266 - IoTbyHVM - Explore TechBytes
Pingback: ESP8266 as a MQTT Broker | How To Make ESP8266 as a MQTT Broker
Pingback: NodeRed on Android | How To Use Node-Red on Android Smartphone
Pingback: ESP32 BLE Tutorials | How to use ESP32 with BLE
Pingback: Heroku | How To use | Getting started with Heroku ...
Pingback: Install Ubuntu Core on Raspberry Pi 2 or 3 - IoTbyHVM
Pingback: NodeRed Alternatives - Visual programming tools -IoTbyHVM
Pingback: GPIO pins of ESP8266 and How to use efficiently -IoTbyHVM
Pingback: Program Your Arduino With an Android Device - IoTbyHVM - Bits & Bytes of IoT
Pingback: GPIO Pins of ESP32 | ESP32 Tutorials - IoTbyHVM - Bits & Bytes of IoT
Pingback: IoT OS and RTOS for Internet of Things Devices – CompileIoT
Pingback: Portable OS - Your pocket operating systems -
Pingback: Top 10 IoT Cloud Platforms - CompileIoT