Arduino UNO R4 WiFi OTA update #258
Unanswered
Alessio6976
asked this question in
Q&A
Replies: 2 comments 13 replies
-
the sketch you posted is not for this library and not for Uno R4. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thank you JAndrassy, your advanced example works perfectly. I only made a little update for UNO R4 WiFi, but now it's perfect! Thank you |
Beta Was this translation helpful? Give feedback.
13 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone,
is there a way to update the firmware over the air for an Arduino UNO R4 WiFi, storing the new firmware on github? I saw some example, but nothing work.
I followed some tutorial, but in the "update.h" include there are many includes missing, like "md5.h"...."esp_spi_flash.h"...and every include I fix, it asks for another missing include... So I'm aware that is not possible.
I'm searching for a simple skecth that connects to wifi, and ping to a given url (I've just uploaded a new version of a sample firmware on github) to download and than upgrade the firmware:
My example (not working):
#include <WiFiS3.h>
#include <SPIFFS.h>
#include "Update.h"
#include <WiFiClientSecure.h>
// Definisci le credenziali WiFi
const char* ssid = "IlTuoSSID"; // Inserisci il tuo SSID
const char* password = "LaTuaPassword"; // Inserisci la tua password
// Definisci i dettagli del server e il percorso del file
#define HOST "raw.githubusercontent.com"
#define PATH "/ilTuoNomeUtente/ilTuoRepository/main/firmware.bin" // Sostituisci con il tuo percorso
#define PORT 443
// Definisci il nome del file per il firmware scaricato
#define FILE_NAME "/firmware.bin"
void setup() {
Serial.begin(115200);
// Inizializza SPIFFS
if (!SPIFFS.begin(true)) {
Serial.println("SPIFFS Mount Failed");
return;
}
// Connettiti al WiFi
connectToWiFi();
// Scarica il firmware dal server
getFileFromServer();
// Esegui l'aggiornamento OTA
performOTAUpdateFromSPIFFS();
}
void loop() {
// Nessuna azione nel loop
}
void connectToWiFi() {
// Inizia la connessione al WiFi usando SSID e password forniti
WiFi.begin(ssid, password);
// Mostra il progresso della connessione
Serial.print("Connecting to WiFi");
// Attendi finché non è connesso al WiFi
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// Messaggio di conferma quando il WiFi è connesso
Serial.println("WiFi connected");
}
void getFileFromServer() {
WiFiClientSecure client;
client.setInsecure(); // Imposta il client per permettere connessioni insicure
if (client.connect(HOST, PORT)) { // Connettiti al server
Serial.println("Connected to server");
client.print("GET " + String(PATH) + " HTTP/1.1\r\n"); // Invia richiesta GET HTTP
client.print("Host: " + String(HOST) + "\r\n"); // Specifica l'host
client.println("Connection: close\r\n"); // Chiudi la connessione dopo la risposta
client.println(); // Invia una riga vuota per indicare la fine delle intestazioni della richiesta
}
else {
Serial.println("Failed to connect to server");
}
}
void performOTAUpdateFromSPIFFS() {
// Apri il file del firmware in SPIFFS per la lettura
File file = SPIFFS.open(FILE_NAME, FILE_READ);
if (!file) {
Serial.println("Failed to open file for reading");
return;
}
Serial.println("Starting update..");
size_t fileSize = file.size(); // Ottieni la dimensione del file
Serial.println(fileSize);
// Inizia il processo di aggiornamento OTA con la dimensione specificata e la destinazione flash
if (!Update.begin(fileSize, U_FLASH)) {
Serial.println("Cannot do the update");
return;
}
// Scrivi i dati del firmware dal file all'aggiornamento OTA
Update.writeStream(file);
// Completa il processo di aggiornamento OTA
if (Update.end()) {
Serial.println("Successful update");
}
else {
Serial.println("Error Occurred:" + String(Update.getError()));
return;
}
file.close(); // Chiudi il file
Serial.println("Reset in 4 seconds....");
delay(4000);
ESP.restart(); // Riavvia l'ESP32 per applicare l'aggiornamento
}
Beta Was this translation helpful? Give feedback.
All reactions