mirror of
https://github.com/EyeTrackVR/OpenIris.git
synced 2025-11-04 15:39:42 +08:00
fix: fix current OTA stack
- update board.ini to clean it up - minor update to OTA.cpp
This commit is contained in:
parent
f254b7b194
commit
c96e3f7108
@ -5,29 +5,24 @@
|
||||
board = esp32cam
|
||||
build_type = debug
|
||||
build_flags = ${env.build_flags}
|
||||
-DCORE_DEBUG_LEVEL=4 ; set the debug level
|
||||
-DDEBUG_MODE=1 ; Set the debug mode
|
||||
-DCORE_DEBUG_LEVEL=4 ; set the debug level
|
||||
-DDEBUG_MODE=1 ; Set the debug mode
|
||||
; CAMERA PINOUT DEFINITIONS
|
||||
${pinoutsAIThinker.build_flags}
|
||||
|
||||
[env:esp32AIThinker_release]
|
||||
board = esp32cam
|
||||
build_type = release
|
||||
build_flags = ${env.build_flags}
|
||||
-DDEBUG_MODE=0 ; Set the debug mode
|
||||
-DCORE_DEBUG_LEVEL=1
|
||||
; CAMERA PINOUT DEFINITIONS
|
||||
${pinoutsAIThinker.build_flags}
|
||||
|
||||
; Experimental OTA Environment - do not select unless you know what you are doing
|
||||
[env:esp32AIThinker_OTA]
|
||||
board = esp32cam
|
||||
build_flags = ${env.build_flags}
|
||||
-DDEBUG_MODE=0 ; Set the debug mode
|
||||
-DCORE_DEBUG_LEVEL=1
|
||||
-DDEBUG_ESP_OTA
|
||||
; CAMERA PINOUT DEFINITIONS
|
||||
${pinoutsAIThinker.build_flags}
|
||||
|
||||
; Experimental OTA Environment - do not select unless you know what you are doing
|
||||
[env:esp32AIThinker_OTA]
|
||||
extends = env:esp32AIThinker_release
|
||||
upload_port = ${ota.otaserverip}
|
||||
upload_protocol = espota
|
||||
upload_flags =
|
||||
@ -52,24 +47,19 @@ build_flags = ${env.build_flags}
|
||||
${pinoutsESPCAM_M5STACK.build_flags}
|
||||
|
||||
[env:esp32M5Stack_OTA]
|
||||
board = esp32cam
|
||||
build_flags = ${env.build_flags}
|
||||
-DDEBUG_MODE=0
|
||||
-DCORE_DEBUG_LEVEL=1
|
||||
-DDEBUG_ESP_OTA
|
||||
${pinoutsESPCAM_M5STACK.build_flags}
|
||||
extends = env:esp32M5Stack_release
|
||||
upload_port = ${ota.otaserverip}
|
||||
upload_protocol = espota
|
||||
upload_flags =
|
||||
--port=${ota.otaserverport}
|
||||
--auth=${ota.otapassword}
|
||||
build_type = release
|
||||
|
||||
[env:esp32Cam]
|
||||
board = esp32cam
|
||||
build_type = debug
|
||||
build_flags = ${env.build_flags}
|
||||
-DDEBUG_MODE=1 ; Set the debug mode
|
||||
-DDEBUG_MODE=1
|
||||
-DCORE_DEBUG_LEVEL=4 ; Set the debug mode
|
||||
; CAMERA PINOUT DEFINITIONS
|
||||
${pinoutsESPCam.build_flags}
|
||||
|
||||
@ -77,20 +67,15 @@ build_flags = ${env.build_flags}
|
||||
board = esp32cam
|
||||
build_type = release
|
||||
build_flags = ${env.build_flags}
|
||||
-DDEBUG_MODE=0 ; Set the debug mode
|
||||
-DDEBUG_MODE=0 ; Set the debug mode
|
||||
-DCORE_DEBUG_LEVEL=1
|
||||
-DDEBUG_ESP_OTA
|
||||
; CAMERA PINOUT DEFINITIONS
|
||||
${pinoutsESPCam.build_flags}
|
||||
|
||||
; Experimental OTA Environment - do not select unless you know what you are doing
|
||||
[env:esp32Cam_OTA]
|
||||
board = esp32cam
|
||||
build_flags = ${env.build_flags}
|
||||
-DDEBUG_MODE=0 ; Set the debug mode
|
||||
-DCORE_DEBUG_LEVEL=1
|
||||
-DDEBUG_ESP_OTA
|
||||
; CAMERA PINOUT DEFINITIONS
|
||||
${pinoutsESPCam.build_flags}
|
||||
extends = env:esp32Cam_release
|
||||
upload_port = ${ota.otaserverip}
|
||||
upload_protocol = espota
|
||||
upload_flags =
|
||||
@ -104,7 +89,7 @@ board = esp-wrover-kit
|
||||
;board_build.flash_mode = qio
|
||||
build_type = debug
|
||||
build_flags = ${env.build_flags}
|
||||
-DDEBUG_MODE=1 ; Set the debug mode
|
||||
-DDEBUG_MODE=1 ; Set the debug mode
|
||||
; CAMERA PINOUT DEFINITIONS
|
||||
${pinoutsESP-EYE.build_flags}
|
||||
|
||||
@ -114,20 +99,15 @@ board = esp-wrover-kit
|
||||
;board_build.flash_mode = qio
|
||||
build_type = release
|
||||
build_flags = ${env.build_flags}
|
||||
-DDEBUG_MODE=0 ; Set the debug mode
|
||||
-DDEBUG_MODE=0 ; Set the debug mode
|
||||
-DCORE_DEBUG_LEVEL=1
|
||||
-DDEBUG_ESP_OTA
|
||||
; CAMERA PINOUT DEFINITIONS
|
||||
${pinoutsESP-EYE.build_flags}
|
||||
|
||||
; Experimental OTA Environment - do not select unless you know what you are doing
|
||||
[env:esp_eye_OTA]
|
||||
board = esp-wrover-kit
|
||||
build_flags = ${env.build_flags}
|
||||
-DDEBUG_MODE=0 ; Set the debug mode
|
||||
-DCORE_DEBUG_LEVEL=1
|
||||
-DDEBUG_ESP_OTA
|
||||
; CAMERA PINOUT DEFINITIONS
|
||||
${pinoutsESP-EYE.build_flags}
|
||||
extends = env:esp_eye_release
|
||||
upload_port = ${ota.otaserverip}
|
||||
upload_protocol = espota
|
||||
upload_flags =
|
||||
@ -141,8 +121,8 @@ board_build.f_flash = 80000000L
|
||||
board_build.flash_mode = qio
|
||||
build_type = debug
|
||||
build_flags = ${env.build_flags}
|
||||
-DCORE_DEBUG_LEVEL=4 ; set the debug level
|
||||
-DDEBUG_MODE=1 ; Set the debug mode
|
||||
-DCORE_DEBUG_LEVEL=4 ; set the debug level
|
||||
-DDEBUG_MODE=1 ; Set the debug mode
|
||||
; CAMERA PINOUT DEFINITIONS
|
||||
${pinoutsESPWROVER.build_flags}
|
||||
|
||||
@ -152,21 +132,14 @@ board_build.f_flash = 80000000L
|
||||
board_build.flash_mode = qio
|
||||
build_type = debug
|
||||
build_flags = ${env.build_flags}
|
||||
-DDEBUG_MODE=0 ; Set the debug mode
|
||||
-DCORE_DEBUG_LEVEL=1
|
||||
; CAMERA PINOUT DEFINITIONS
|
||||
${pinoutsESPWROVER.build_flags}
|
||||
|
||||
[env:wrover_OTA]
|
||||
board = esp-wrover-kit
|
||||
board_build.f_flash = 80000000L
|
||||
board_build.flash_mode = qio
|
||||
build_flags = ${env.build_flags}
|
||||
-DDEBUG_MODE=0 ; Set the debug mode
|
||||
-DDEBUG_MODE=0 ; Set the debug mode
|
||||
-DCORE_DEBUG_LEVEL=1
|
||||
-DDEBUG_ESP_OTA
|
||||
; CAMERA PINOUT DEFINITIONS
|
||||
${pinoutsESPWROVER.build_flags}
|
||||
|
||||
[env:wrover_OTA]
|
||||
extends = env:wrover_release
|
||||
upload_port = ${ota.otaserverip}
|
||||
upload_protocol = espota
|
||||
upload_flags =
|
||||
|
||||
@ -14,6 +14,6 @@ adhocchannel = 1
|
||||
|
||||
[ota]
|
||||
enableota = 1
|
||||
otaserverip = "192.168.4.1"
|
||||
otaserverip = "openiristracker.local"
|
||||
otapassword = "12345678"
|
||||
otaserverport = 3232
|
||||
|
||||
@ -1,74 +1,70 @@
|
||||
#include "OTA.hpp"
|
||||
|
||||
OTA::OTA(ProjectConfig *_deviceConfig) : _deviceConfig(_deviceConfig),
|
||||
_bootTimestamp(0),
|
||||
_isOtaEnabled(true) {}
|
||||
OTA::OTA(ProjectConfig* _deviceConfig)
|
||||
: _deviceConfig(_deviceConfig), _bootTimestamp(0), _isOtaEnabled(true) {}
|
||||
|
||||
OTA::~OTA() {}
|
||||
|
||||
void OTA::SetupOTA()
|
||||
{
|
||||
log_e("Setting up OTA updates");
|
||||
auto localConfig = _deviceConfig->getDeviceConfig();
|
||||
void OTA::begin() {
|
||||
log_i("Setting up OTA updates");
|
||||
auto localConfig = _deviceConfig->getDeviceConfig();
|
||||
|
||||
if (strcmp(localConfig->OTAPassword.c_str(), "") == 0)
|
||||
{
|
||||
log_e("THE PASSWORD IS REQUIRED, [[ABORTING]]");
|
||||
return;
|
||||
}
|
||||
ArduinoOTA.setPort(localConfig->OTAPort);
|
||||
ArduinoOTA
|
||||
.onStart([]()
|
||||
{
|
||||
String type;
|
||||
if (ArduinoOTA.getCommand() == U_FLASH)
|
||||
type = "sketch";
|
||||
else // U_SPIFFS
|
||||
type = "filesystem"; })
|
||||
.onEnd([]()
|
||||
{ Serial.println("OTA updated finished successfully!"); })
|
||||
.onProgress([](unsigned int progress, unsigned int total)
|
||||
{ Serial.printf("Progress: %u%%\r", (progress / (total / 100))); })
|
||||
.onError([](ota_error_t error)
|
||||
{
|
||||
log_e("Error[%u]: ", error);
|
||||
switch (error)
|
||||
{
|
||||
case OTA_AUTH_ERROR:
|
||||
log_e("Auth Failed");
|
||||
break;
|
||||
case OTA_BEGIN_ERROR:
|
||||
log_e("Begin Failed");
|
||||
break;
|
||||
case OTA_CONNECT_ERROR:
|
||||
log_e("Connect Failed");
|
||||
break;
|
||||
case OTA_RECEIVE_ERROR:
|
||||
log_e("Receive Failed");
|
||||
break;
|
||||
case OTA_END_ERROR:
|
||||
log_e("End Failed");
|
||||
break;
|
||||
} });
|
||||
log_i("Starting up basic OTA server");
|
||||
log_i("OTA will be live for 5 minutes, after which it will be disabled until restart");
|
||||
auto mdnsConfig = _deviceConfig->getMDNSConfig();
|
||||
ArduinoOTA.setHostname(mdnsConfig->hostname.c_str());
|
||||
ArduinoOTA.begin();
|
||||
_bootTimestamp = millis();
|
||||
if (localConfig->OTAPassword.empty()) {
|
||||
log_e("THE PASSWORD IS REQUIRED, [[ABORTING]]");
|
||||
return;
|
||||
}
|
||||
ArduinoOTA.setPort(localConfig->OTAPort);
|
||||
ArduinoOTA
|
||||
.onStart([]() {
|
||||
String type;
|
||||
if (ArduinoOTA.getCommand() == U_FLASH)
|
||||
type = "sketch";
|
||||
else // U_SPIFFS
|
||||
type = "filesystem";
|
||||
})
|
||||
.onEnd([]() { Serial.println("OTA updated finished successfully!"); })
|
||||
.onProgress([](unsigned int progress, unsigned int total) {
|
||||
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
|
||||
})
|
||||
.onError([](ota_error_t error) {
|
||||
log_e("Error[%u]: ", error);
|
||||
switch (error) {
|
||||
case OTA_AUTH_ERROR:
|
||||
log_e("Auth Failed");
|
||||
break;
|
||||
case OTA_BEGIN_ERROR:
|
||||
log_e("Begin Failed");
|
||||
break;
|
||||
case OTA_CONNECT_ERROR:
|
||||
log_e("Connect Failed");
|
||||
break;
|
||||
case OTA_RECEIVE_ERROR:
|
||||
log_e("Receive Failed");
|
||||
break;
|
||||
case OTA_END_ERROR:
|
||||
log_e("End Failed");
|
||||
break;
|
||||
}
|
||||
});
|
||||
log_i("Starting up basic OTA server");
|
||||
log_i(
|
||||
"OTA will be live for 5 minutes, after which it will be disabled until "
|
||||
"restart");
|
||||
auto mdnsConfig = _deviceConfig->getMDNSConfig();
|
||||
ArduinoOTA.setHostname(mdnsConfig->hostname.c_str());
|
||||
ArduinoOTA.begin();
|
||||
_bootTimestamp = millis();
|
||||
}
|
||||
|
||||
void OTA::HandleOTAUpdate()
|
||||
{
|
||||
if (_isOtaEnabled)
|
||||
{
|
||||
if (_bootTimestamp + (60000 * 5) < millis())
|
||||
{
|
||||
// we're disabling ota after first 5 minutes so that nothing bad happens during runtime
|
||||
_isOtaEnabled = false;
|
||||
log_i("From now on, OTA is disabled");
|
||||
return;
|
||||
}
|
||||
ArduinoOTA.handle();
|
||||
void OTA::handleOTAUpdate() {
|
||||
if (_isOtaEnabled) {
|
||||
if (_bootTimestamp + (60000 * 5) < millis()) {
|
||||
// we're disabling ota after first 5 minutes so that nothing bad happens
|
||||
// during runtime
|
||||
_isOtaEnabled = false;
|
||||
log_i("From now on, OTA is disabled");
|
||||
return;
|
||||
}
|
||||
}
|
||||
ArduinoOTA.handle();
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,12 +9,12 @@ class OTA
|
||||
public:
|
||||
OTA(ProjectConfig *_deviceConfig);
|
||||
virtual ~OTA();
|
||||
void SetupOTA();
|
||||
void HandleOTAUpdate();
|
||||
void begin();
|
||||
void handleOTAUpdate();
|
||||
|
||||
private:
|
||||
ProjectConfig *_deviceConfig;
|
||||
unsigned long _bootTimestamp;
|
||||
bool _isOtaEnabled;
|
||||
};
|
||||
#endif // OTA_HPP
|
||||
#endif // OTA_HPP
|
||||
|
||||
@ -13,8 +13,6 @@
|
||||
#include <logo/logo.hpp>
|
||||
#include <data/config/project_config.hpp>
|
||||
|
||||
// #include <data/utilities/makeunique.hpp>
|
||||
|
||||
int STREAM_SERVER_PORT = 80;
|
||||
int CONTROL_SERVER_PORT = 81;
|
||||
/**
|
||||
@ -30,7 +28,7 @@ OTA ota(&deviceConfig);
|
||||
#endif // ENABLE_OTA
|
||||
LEDManager ledManager(33);
|
||||
CameraHandler cameraHandler(&deviceConfig, &ledStateManager);
|
||||
// SerialManager serialManager(&deviceConfig);
|
||||
|
||||
WiFiHandler wifiHandler(&deviceConfig, &wifiStateManager, WIFI_SSID, WIFI_PASSWORD, WIFI_CHANNEL);
|
||||
APIServer apiServer(CONTROL_SERVER_PORT, &deviceConfig, &cameraHandler, &wifiStateManager, "/control");
|
||||
MDNSHandler mdnsHandler(&mdnsStateManager, &deviceConfig);
|
||||
@ -40,9 +38,12 @@ void setup()
|
||||
{
|
||||
setCpuFrequencyMhz(240); // set to 240mhz for performance boost
|
||||
Serial.begin(115200);
|
||||
Serial.setDebugOutput(DEBUG_MODE);
|
||||
Serial.println("\n");
|
||||
//Serial.setDebugOutput(DEBUG_MODE);
|
||||
//Serial.println("Free Heap: " + String(ESP.getFreeHeap()));
|
||||
Logo::printASCII();
|
||||
Serial.flush();
|
||||
//Serial.println("Free Heap: " + String(ESP.getFreeHeap()));
|
||||
|
||||
ledManager.begin();
|
||||
deviceConfig.attach(&cameraHandler);
|
||||
deviceConfig.attach(&mdnsHandler);
|
||||
@ -106,15 +107,14 @@ void setup()
|
||||
}
|
||||
}
|
||||
#if ENABLE_OTA
|
||||
ota.SetupOTA();
|
||||
ota.begin();
|
||||
#endif // ENABLE_OTA
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
#if ENABLE_OTA
|
||||
ota.HandleOTAUpdate();
|
||||
ota.handleOTAUpdate();
|
||||
#endif // ENABLE_OTA
|
||||
ledManager.handleLED(&ledStateManager);
|
||||
// serialManager.handleSerial();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user