Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.pio
.vscode/
/platformio.ini
54 changes: 40 additions & 14 deletions src/flashz-http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,16 @@ void FlashZhttp::handle_ota_form(AsyncWebServer *srv, const char* url){
request->send(503, PGmimetxt, "Update FAILED");
} else {
if (rst_timeout){
if (!t)
t = new Ticker;

t->once_ms(rst_timeout, [](){ ESP.restart(); });
if (!_tmr){
_tmr = xTimerCreate(TAG,
pdMS_TO_TICKS(rst_timeout),
pdFALSE, // one time timer
static_cast<void*>(this),
[](TimerHandle_t h) { ESP.restart(); }
);
}

xTimerReset( _tmr, portMAX_DELAY );
}
request->send(200, PGmimetxt, "OTA complete, autoreboot in 5 sec...");
}
Expand Down Expand Up @@ -247,10 +253,16 @@ fz_http_err_t FlashZhttp::_http_get(const char* url, int imgtype){
}

if (rst_timeout){
if (!t)
t = new Ticker;
if (!_tmr){
_tmr = xTimerCreate(TAG,
pdMS_TO_TICKS(rst_timeout),
pdFALSE, // one time timer
static_cast<void*>(this),
[](TimerHandle_t h) { ESP.restart(); }
);
}

t->once_ms(rst_timeout, [](){ ESP.restart(); });
xTimerReset( _tmr, portMAX_DELAY );
}

return fz_http_err_t::ok;
Expand Down Expand Up @@ -279,14 +291,20 @@ void FlashZhttp::handle_ota_form(WebServer *server, const char* url){
server->send(500, PGmimetxt, "UPDATE FAILED");
} else {
if (rst_timeout){
if (!t)
t = new Ticker;
if (!_tmr){
_tmr = xTimerCreate(TAG,
pdMS_TO_TICKS(rst_timeout),
pdFALSE, // one time timer
static_cast<void*>(this),
[](TimerHandle_t h) { ESP.restart(); }
);
}

t->once_ms(rst_timeout, [](){ ESP.restart(); });
xTimerReset( _tmr, portMAX_DELAY );
}

server->client().setNoDelay(true);
server->send(200, PGmimetxt, F("OTA complete, autoreboot in 5 sec..."));
server->send(200, PGmimetxt, "OTA complete, autoreboot in 5 sec...");
server->client().stop();
}
}
Expand Down Expand Up @@ -374,9 +392,17 @@ unsigned FlashZhttp::autoreboot(unsigned t){
#ifndef FZ_NOHTTPCLIENT
void FlashZhttp::fetch_async(const char* url, int imgtype, int delay){
if (!cb){ cb = new callback_arg_t(imgtype, url); }
if (!t) t = new Ticker;
// have no idea why, but C3 bootloops here, needs investigation
t->once_ms(delay, FlashZhttp::_fz_http_trigger, this);
if (!_tmr){
_tmr = xTimerCreate(TAG,
pdMS_TO_TICKS(delay),
pdFALSE, // one time timer
static_cast<void*>(this),
[](TimerHandle_t h) { ESP.restart(); }
);
}

xTimerReset( _tmr, portMAX_DELAY );

_err = fz_http_err_t::pending;
}
#endif //FZ_NOHTTPCLIENT
13 changes: 9 additions & 4 deletions src/flashz-http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@

#pragma once

#include "freertos/FreeRTOS.h"
#include "freertos/timers.h"

#ifdef FZ_WITH_ASYNCSRV
#include <ESPAsyncWebServer.h>
#define FZ_NO_WEBSRV
#else
#include <WebServer.h>
#endif // #ifdef FZ_WITH_ASYNCSRV

#include <Ticker.h>

#define FZ_REBOOT_TIMEOUT 5000
#define FZ_HTTP_CLIENT_DELAY 1000

Expand Down Expand Up @@ -67,7 +68,7 @@ enum class fz_http_err_t:int {
*/
class FlashZhttp {
unsigned rst_timeout = FZ_REBOOT_TIMEOUT;
Ticker *t = nullptr;
TimerHandle_t _tmr{nullptr};

#ifndef FZ_NOHTTPCLIENT
struct callback_arg_t {
Expand Down Expand Up @@ -95,7 +96,11 @@ class FlashZhttp {

public:
~FlashZhttp(){
delete t; t = nullptr;
if (_tmr){
xTimerStop(_tmr, portMAX_DELAY );
xTimerDelete(_tmr, portMAX_DELAY );
}

#ifndef FZ_NOHTTPCLIENT
delete cb;
cb = nullptr;
Expand Down