From a569ac21e69c73e5be9cdf8c3ba032bc1db7f809 Mon Sep 17 00:00:00 2001 From: Zdzislaw Goik Date: Wed, 2 Mar 2022 22:14:00 +0100 Subject: [PATCH] Add basic OTA updates handling (#3) --- ESP/include/WifiHandler.h | 2 +- ESP/include/credentials.h | 5 ++++- ESP/platformio.ini | 11 +++++++++-- ESP/src/main.cpp | 8 ++++++-- ESP/src/wifiHandler.cpp | 3 +-- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/ESP/include/WifiHandler.h b/ESP/include/WifiHandler.h index 04990e9..a7c28ea 100644 --- a/ESP/include/WifiHandler.h +++ b/ESP/include/WifiHandler.h @@ -2,5 +2,5 @@ #include "pinout.h" namespace WiFiHandler { - void setupWifi(); + void setupWifi(const char* ssid, const char* password); } \ No newline at end of file diff --git a/ESP/include/credentials.h b/ESP/include/credentials.h index 08a7858..fa3ad4c 100644 --- a/ESP/include/credentials.h +++ b/ESP/include/credentials.h @@ -1,2 +1,5 @@ const char* ssid = ""; -const char* password = ""; \ No newline at end of file +const char* password = ""; + +const char* OTAPassword = ""; // if empty, no password will be required +uint16_t OTAServerPort = 3232; \ No newline at end of file diff --git a/ESP/platformio.ini b/ESP/platformio.ini index f232de0..9de0e3b 100644 --- a/ESP/platformio.ini +++ b/ESP/platformio.ini @@ -15,8 +15,15 @@ framework = arduino monitor_speed = 115200 monitor_rts = 0 monitor_dtr = 0 -build_flags = -O2 +build_flags = + -O2 build_unflags = -Os +;upload_port = 192.168.1.43 ;replace this with your own ip +;upload_protocol = espota +upload_flags = + --auth=Password +board_build.partitions = min_spiffs.csv lib_deps = - esp32-camera \ No newline at end of file + esp32-camera + \ No newline at end of file diff --git a/ESP/src/main.cpp b/ESP/src/main.cpp index 99bd168..3d5c184 100644 --- a/ESP/src/main.cpp +++ b/ESP/src/main.cpp @@ -1,9 +1,11 @@ #include #include "pinout.h" +#include "credentials.h" #include "WifiHandler.h" #include "cameraHandler.h" #include "LEDManager.h" #include "httpdHandler.h" +#include "OTA.h" void setup(){ Serial.begin(115200); @@ -14,12 +16,14 @@ void setup(){ LEDManager::setupLED(); // todo add blink handling CameraHandler::setupCamera(); - WiFiHandler::setupWifi(); + WiFiHandler::setupWifi(ssid, password); // todo add blink handling HttpdHandler::startStreamServer(); LEDManager::on(); + + OTA::SetupOTA(OTAPassword, OTAServerPort); } void loop(){ - delay(1); + OTA::HandleOTAUpdate(); } \ No newline at end of file diff --git a/ESP/src/wifiHandler.cpp b/ESP/src/wifiHandler.cpp index 29b73c6..328132a 100644 --- a/ESP/src/wifiHandler.cpp +++ b/ESP/src/wifiHandler.cpp @@ -1,9 +1,8 @@ #include "WifiHandler.h" -#include "credentials.h" #include "LEDManager.h" namespace WiFiHandler { - void setupWifi(){ + void setupWifi(const char* ssid, const char* password){ Serial.println("Initializing connection to wifi"); WiFi.begin(ssid, password);