How to Implement OTA Updates for ESP32 with FreeRTOS on Google Cloud IoT Core?

@Middleware & OS Hello guys am interested in over the air (OTA) firmware update of an ESP32 microcontroller running FreeRTOS and connect it to Google Cloud IoT Core for data monitoring, please i would need any form of guidance i can get i.e code examples or documentation and suggested libraries that can aid me in OTA updates for ESP32 with FreeRTOS
Solution:
Your code should be identical or similar to 👇 ```cpp #include <WiFi.h> #include <PubSubClient.h> #include <ArduinoOTA.h>...
Jump to solution
5 Replies
Marvee Amasi
Marvee Amasi•3w ago
Hi @Boss lady HTTP and MQTT are popular protocols for OTA updates on an ESP32 , which are u leaning on to?
Boss lady
Boss lady•3w ago
MQTT
Dtynin
Dtynin•3w ago
@Boss lady Create an account on their official site, install necessary libraries like ArduinoOTA library, PubSubClient library, etc then configure the network by connecting your ESP32 to the wifi network using the Wi-Fi library, then you implement OTA firmware update functionality
Solution
Enthernet Code
Enthernet Code•3w ago
Your code should be identical or similar to 👇
#include <WiFi.h>
#include <PubSubClient.h>
#include <ArduinoOTA.h>

const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
const char* mqttServer = "mqtt.googleapis.com";
const char* mqttUsername = "unused";
const int mqttPort = 8883;
const char* devicePrivateKey = "YOUR_DEVICE_PRIVATE_KEY";

WiFiClientSecure wifiClient;
PubSubClient client(wifiClient);

void connectWiFi() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
}
}

void connectMQTT() {
client.setServer(mqttServer, mqttPort);
client.setCallback(callback);
while (!client.connected()) {
if (client.connect("ESP32-device", mqttUsername, devicePrivateKey)) {
client.subscribe("your_topic");
} else {
delay(1000);
}
}
}

void callback(char* topic, byte* payload, unsigned int length) {
// Handle incoming MQTT messages here
}

void setup() {
Serial.begin(115200);

connectWiFi();

ArduinoOTA.setHostname("ESP32-device");
ArduinoOTA.setPassword("Your_OTA_Password");

// Callbacks to handle OTA updates
ArduinoOTA.onStart([]() {
Serial.println("OTA update started...");
});

ArduinoOTA.onEnd([]() {
Serial.println("\nOTA update complete!");
ESP.restart();
});

ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));

// You can use progress/total to publish update progress to Google Cloud IoT Core
});

ArduinoOTA.begin();

connectMQTT();
}

void loop() {
ArduinoOTA.handle();

if (!client.connected()) {
connectMQTT();
}
client.loop();

// Perform your regular tasks here

delay(1000);
}
#include <WiFi.h>
#include <PubSubClient.h>
#include <ArduinoOTA.h>

const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
const char* mqttServer = "mqtt.googleapis.com";
const char* mqttUsername = "unused";
const int mqttPort = 8883;
const char* devicePrivateKey = "YOUR_DEVICE_PRIVATE_KEY";

WiFiClientSecure wifiClient;
PubSubClient client(wifiClient);

void connectWiFi() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
}
}

void connectMQTT() {
client.setServer(mqttServer, mqttPort);
client.setCallback(callback);
while (!client.connected()) {
if (client.connect("ESP32-device", mqttUsername, devicePrivateKey)) {
client.subscribe("your_topic");
} else {
delay(1000);
}
}
}

void callback(char* topic, byte* payload, unsigned int length) {
// Handle incoming MQTT messages here
}

void setup() {
Serial.begin(115200);

connectWiFi();

ArduinoOTA.setHostname("ESP32-device");
ArduinoOTA.setPassword("Your_OTA_Password");

// Callbacks to handle OTA updates
ArduinoOTA.onStart([]() {
Serial.println("OTA update started...");
});

ArduinoOTA.onEnd([]() {
Serial.println("\nOTA update complete!");
ESP.restart();
});

ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));

// You can use progress/total to publish update progress to Google Cloud IoT Core
});

ArduinoOTA.begin();

connectMQTT();
}

void loop() {
ArduinoOTA.handle();

if (!client.connected()) {
connectMQTT();
}
client.loop();

// Perform your regular tasks here

delay(1000);
}
youcef_ali
youcef_ali•3w ago
Which frame works Arduino or esp-idf?
Want results from more Discord servers?
Add your server
More Posts
How to Identify and Resolve Latency Spikes in a Linux GPIO Application Using Preempt_rt Kernel PatchHi guys, during a discussion yesterday, my colleague and I were exploring ways to detect and solve lAre there alternatives to system() that might be more performant for CGI scripts on embedded Linux?I'm facing a performance issue with the system() call in C on my embedded Linux system. The command What exactly do inner and outer cache policies refer to?Hey guys @Middleware & OS I am trying to develop my own RTOS kernel for a Cortex-M7 STM32F746 DiscoDeveloping a smart thermostat device using Android Things OS@Middleware & OS Hey guys, I'm developing a smart thermostat device using Android Things OS. I woulDeveloping automotive test systems with STM32 Nucleo devices (like Nucleo144) using RTOSI've been working with STM32 Nucleo boards (mainly Nucleo144) for basic projects using CubeIDE. Now How to Keep Spring Boot App Running After Closing PuTTY Session Without Using a Linux Service?Hi Everyone, I'm running a Spring Boot application with an embedded Tomcat server deployed as an exeIs it possible to compile Busybox directly into the initramfs during the kernel build process?@Middleware & OS I'm working on an embedded Linux system and want to use Busybox for its small foothow can I send data from a smart door lock to Azure IoT Hub?@Middleware & OS Hey guys, how can I send data from a smart door lock device(lock status, access atAny tips for a smooth transition from mbed to Zephyr development?@Middleware & OS I've written a C++ LCD driver using PlatformIO and mbed. Now I'm setting up ZephyrBuilding an embedded Linux system for an A20-based board using Buildroot@Middleware & OS I'm building an embedded Linux system for an A20-based board using Buildroot. The