Remote ESP32 Firmware Upate (OTA)
Intro: Remote ESP32 Firmware Upate (OTA)
In this instructable we will demonstrate how to remotely update a ESP32 firmware.
- No physical connection (means that no need to connect the ESP32 to the computer to upload the firmware).
- No need to be in the same network (i.e. your ESP32 at your home and you at work)
STEP 1: Create a Google Firebase Storage
Create a Google Firebase console as link included on supplies
STEP 2: Upload the Code to ESP32
To implement this OTA, the first firmware (code attached) must be uploaded by cable. So, connect your ESP32 to your computer and upload it.
The following code lines must be modified for you account and project details:
const char* ssid = "YourWifiNetworkName";const char* password = "YourWifiPassword";#define API_KEY "GoogleFirebaseAPIKEY" // Firebase: Define the API Key#define USER_EMAIL "GoogleFirebaseUserEmail" // Firebase: Define the user Email#define USER_PASSWORD "GoogleFirebaseUserPassword" // Firebase: Define password#define STORAGE_BUCKET_ID "GoogleFirebaseBucketID" // Firebase: Define the Firebase storage bucket ID e.g bucket-name.appspot.com#define FIRMWARE_PATH "test/firmware.bin" // Firebase: Define the firmware path on Firebase
STEP 3: Ok, and Now?
After successfully uploading the code to your ESP32 and restarting it, it will connect to your Wifi network and will search for the firmware file on the Firebase Storage.
If no file is present in the storage, the code will move on.
IP address: 10.92.61.230Firebase Client v4.0.0 Token info: type = id token, status = on requestToken info: type = id token, status = readyChecking for new firmware update available...New firmware update not available or download failed, Not Found.Not Found.
If a file is found, the ESP32 will download it, delete it after download and restart the device.
WiFi connectedIP address: 10.92.61.230Firebase Client v4.0.0Token info: type = id token, status = on requestToken info: type = id token, status = readyChecking for new firmware update available...New update foundDownloading firmware test/firmware.bin (1048000 bytes)Downloaded 0%Downloaded 2%Downloaded 4%Downloaded 6%Downloaded 8%Downloaded 10%...Downloaded 90%Downloaded 92%Downloaded 94%Downloaded 96%Downloaded 98%Downloaded 100%Donwload firmware completed.Delete file... okRestarting...
At this point, the new firmware will run at your device.
STEP 4: Import a New Firmware to the Storage
To provide a new firmware for your device, you shall upload to the Firebase Storage the binary file created by your compiler, usually it is named "firmware.bin".
If your are using Visual Studio with PlataformIO, the binary file can be found on the path similar to:
...\PlatformIO\Projects\WebUpdate\.pio\build\wemos_d1_mini32\firmware.bin
You shall have a storage like the picture.
11 Comments
a5 3 months ago
People, please remember that this code will sit on top of your exisiting code. Otherwise it will work only one time and once the firmware is updated, your ESP wont be able to connect with firebase. If you add this code inside (or on top of) your existing code, you will able to rewrite new firmwares that support future OTAs.
a5 3 months ago
For those who are facing the issue or message "Invalid HTTP method / URL ",
Please do not use gs:// in the #define STORAGE_BUCKET_ID
example : if the firebase storage path is gs://yourProject.yourDomain.appspot.com
use only "yourProject.yourDomain.appspot.com"
Hope this helps!
a5 3 months ago
Thats simple!
You will have to use this code WITH your code. The good part is, this code checks for update ONLY when its booted, and not in-between. Everytime your device restarts, this code checks the firebase for updates. Increase the buffer size if the update stop abruptly. Remember, if for some reason ESP cant connect to firebase (internet issues etc), your regular code will not work because the above code tries connecting to firebase in a loop (you might want to get rid of it in that case).
Hope this helps.
niki_kit 3 months ago
Did you made this code work to check for firmware update repeatedly? This code works only 1st time when I upload it to ESP32 it deletes file from firebase storage. Next time it wont work when I upload new firmware to Firebase storage.
niki_kit 3 months ago
One moment. This code will work only once: downloadOTA, delete firebase file, restart ESP. How to make it run continuously if I want to automatically download every new firmware from firebase?
alperenyilmaz47 6 months ago
tiagom16 6 months ago
Try to change this line:
#defineSTORAGE_BUCKET_ID"gs://firmwareota-f1e76.appspot.com"
to this:
#defineSTORAGE_BUCKET_ID"firmwareota-f1e76.appspot.com"
In other words, just take out the "gs://"
tiagom16 6 months ago
usmodel3d 11 months ago
thank you
tiagom16 6 months ago
put those lines on .ini file if using PlatformIO.
board_build.flash_mode = qio
board_build.partitions = default_8MB.csv
If tou are using Arduino IDE, maybe it helps you:
https://iotespresso.com/how-to-set-partitions-in-esp32/
tiagom16 6 months ago