SensESP 3.0.1
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
ota.h
Go to the documentation of this file.
1#ifndef SENSESP_NET_OTA_H_
2#define SENSESP_NET_OTA_H_
3
4#include "sensesp.h"
5
6#include <Arduino.h>
7#include <ArduinoOTA.h>
8
9#include "sensesp_base_app.h"
10
11namespace sensesp {
12
13class OTA {
14 public:
20 OTA(const char* password) : password_{password} {
21 event_loop()->onDelay(0, [this]() {
22 ArduinoOTA.setPassword(password_);
23 ArduinoOTA.onStart([]() { ESP_LOGW(__FILENAME__, "Starting OTA"); });
24 ArduinoOTA.onEnd([]() { ESP_LOGW(__FILENAME__, "OTA End"); });
25 ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
26 ESP_LOGI(__FILENAME__, "OTA Progress: %u%%\r",
27 (progress / (total / 100)));
28 });
29 ArduinoOTA.onError([](ota_error_t error) {
30 ESP_LOGE(__FILENAME__, "OTA Error[%u]: ", error);
31 if (error == OTA_AUTH_ERROR) {
32 ESP_LOGE(__FILENAME__, "OTA Auth Failed");
33 } else if (error == OTA_BEGIN_ERROR) {
34 ESP_LOGE(__FILENAME__, "OTA Begin Failed");
35 } else if (error == OTA_CONNECT_ERROR) {
36 ESP_LOGE(__FILENAME__, "OTA Connect Failed");
37 } else if (error == OTA_RECEIVE_ERROR) {
38 ESP_LOGE(__FILENAME__, "OTA Receive Failed");
39 } else if (error == OTA_END_ERROR) {
40 ESP_LOGE(__FILENAME__, "OTA End Failed");
41 }
42 });
43 ArduinoOTA.begin();
44 event_loop()->onRepeat(20, OTA::handle_ota);
45 });
46 }
47
48 private:
49 const char* password_;
50 static void handle_ota();
51};
52
53} // namespace sensesp
54
55#endif
OTA(const char *password)
Construct a new OTA (Over-the-air update) object.
Definition ota.h:20
std::shared_ptr< reactesp::EventLoop > event_loop()
Definition sensesp.cpp:9