This commit is contained in:
2023-11-05 12:32:12 +01:00
parent 60cd485806
commit 83f31b704a
4 changed files with 80 additions and 1 deletions

View File

@@ -17,3 +17,8 @@ lib_deps =
me-no-dev/AsyncTCP@^1.1.1
madhephaestus/ESP32Servo@^1.1.0
ottowinter/ESPAsyncWebServer-esphome@^3.1.0
build_flags =
-DCORE_DEBUG_LEVEL=3
-DNDEF_DEBUG=1
upload_protocol = espota
upload_port = MiniSkidi.local

View File

@@ -4,12 +4,14 @@
#include <WiFi.h>
#include "motors.h"
#include "webserver.h"
#include "ota.h"
const char* ssid = "iot";
const char* pwd = "Rijnstraat214";
void setup(void)
{
log_i("init hardware");
setUpPinModes();
Serial.begin(115200);
WiFi.mode(WIFI_STA);
@@ -22,11 +24,12 @@ void setup(void)
IPAddress IP = WiFi.localIP();
Serial.print("AP IP address: ");
Serial.println(IP);
initOTA("MiniSkidi");
setup_webserver();
}
void loop()
{
loop_webserver();
loopOTA();
}

62
src/ota.cpp Normal file
View File

@@ -0,0 +1,62 @@
#include "ota.h"
void initOTA(const char* hostname)
{
Serial.begin(115200);
Serial.println("Booting");
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("Connection Failed! Rebooting...");
delay(5000);
ESP.restart();
}
// Port defaults to 3232
// ArduinoOTA.setPort(3232);
// Hostname defaults to esp3232-[MAC]
ArduinoOTA.setHostname(hostname);
// No authentication by default
// ArduinoOTA.setPassword("admin");
// Password can be set with it's md5 value as well
// MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
// ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
ArduinoOTA
.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH)
type = "sketch";
else // U_SPIFFS
type = "filesystem";
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
Serial.println("Start updating " + type);
})
.onEnd([]() {
Serial.println("\nEnd");
})
.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
})
.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void loopOTA() {
ArduinoOTA.handle();
}

9
src/ota.h Normal file
View File

@@ -0,0 +1,9 @@
#pragma once
#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
void initOTA(const char* hostname);
void loopOTA();