esp32 cam ota 업데이트가 잘안되어서 찾아보니 웹으로 하는 방식이 있어 해보니 ota보다 잘되어서 아래와 같이 정리해봄
esp32용으로 esp8266은 테스터전임 esp8266은 include함수가 다르므로 아래에서 확인 후 변경이 필요함
https://github.com/ayushsharma82/ElegantOTA/tree/master/examples
웹서버가 비동기(Asyn)인지 일반 웹서버인지에 따라 사용하는 라이브러리가 달라짐
// async 방식인 경우
#include <ESPAsyncWebServer.h>
#include <AsyncElegantOTA.h>
AsyncWebServer server(80); //서버 정의
void setup(){
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
request->redirect("/update");
});
AsyncElegantOTA.begin(&server); // Start ElegantOTA
}
//일반 웹서버 방식, 라이브러리 관리자에서 ElegantOTA를 설치해야함
#include <WiFi.h>
#include <WebServer.h>
#include <ElegantOTA.h>
WebServer server(88);
unsigned long ota_progress_millis = 0;
void onOTAStart() {
// Log when OTA has started
Serial.println("OTA update started!");
// <Add your own code here>
}
void onOTAProgress(size_t current, size_t final) {
// Log every 1 second
if (millis() - ota_progress_millis > 1000) {
ota_progress_millis = millis();
Serial.printf("OTA Progress Current: %u bytes, Final: %u bytes\n", current, final);
}
}
void onOTAEnd(bool success) {
// Log when OTA has finished
if (success) {
Serial.println("OTA update finished successfully!");
} else {
Serial.println("There was an error during OTA update!");
}
// <Add your own code here>
}
void setup(){
ElegantOTA.begin(&server); // Start ElegantOTA
// ElegantOTA callbacks
ElegantOTA.onStart(onOTAStart);
ElegantOTA.onProgress(onOTAProgress);
ElegantOTA.onEnd(onOTAEnd);
server.begin();
}
void loop(void) {
server.handleClient();
ElegantOTA.loop();
}
'diy > esp32' 카테고리의 다른 글
Compilation error: text section exceeds available space in board 에러 (0) | 2024.05.07 |
---|---|
esp32-cam 사용시 나타나는 오류 등 해결하기 (0) | 2023.01.02 |