Skip to content

Commit ac83ce6

Browse files
committed
Arduino Bootstrapper (v1.15.1)
1 parent 414960f commit ac83ce6

File tree

4 files changed

+39
-21
lines changed

4 files changed

+39
-21
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"type": "git",
77
"url": "https://github.com/sblantipodi/arduino_bootstrapper.git"
88
},
9-
"version": "1.14.2",
9+
"version": "1.15.1",
1010
"examples": "examples/*.cpp",
1111
"exclude": "tests",
1212
"frameworks": "arduino",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Bootstrapper
2-
version=1.14.2
2+
version=1.15.1
33
author=Davide Perini <[email protected]>
44
maintainer=Davide Perini <[email protected]>
55
sentence=A client library for MQTT messaging.

src/BootstrapManager.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ void BootstrapManager::bootstrapSetup(void (*manageDisconnections)(), void (*man
5151
isConfigFileOk = false;
5252
launchWebServerForOTAConfig();
5353
}
54+
#if defined(ARDUINO_ARCH_ESP32)
55+
esp_task_wdt_init(3000, true); //enable panic so ESP32 restarts
56+
esp_task_wdt_add(NULL); //add current thread to WDT watch
57+
#endif
58+
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
59+
Serial.setTxTimeoutMs(0);
60+
#endif
5461
}
5562

5663
/********************************** BOOTSTRAP FUNCTIONS FOR SETUP() *****************************************/
@@ -74,13 +81,24 @@ void BootstrapManager::bootstrapSetup(void (*manageDisconnections)(), void (*man
7481
isConfigFileOk = false;
7582
launchWebServerCustom(waitImprov, listener);
7683
}
84+
#if defined(ARDUINO_ARCH_ESP32)
85+
esp_task_wdt_init(3000, true); //enable panic so ESP32 restarts
86+
esp_task_wdt_add(NULL); //add current thread to WDT watch
87+
#endif
88+
#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
89+
Serial.setTxTimeoutMs(0);
90+
#endif
7791
}
7892

7993
/********************************** BOOTSTRAP FUNCTIONS FOR LOOP() *****************************************/
8094
bool rcpResponseSent = false;
81-
82-
void BootstrapManager::bootstrapLoop(void (*manageDisconnections)(), void (*manageQueueSubscription)(),
83-
void (*manageHardwareButton)()) {
95+
void BootstrapManager::bootstrapLoop(void (*manageDisconnections)(), void (*manageQueueSubscription)(), void (*manageHardwareButton)()) {
96+
#if defined(ARDUINO_ARCH_ESP32)
97+
if (millis() - lastMillisForWdt >= 3000) {
98+
lastMillisForWdt = millis();
99+
esp_task_wdt_reset();
100+
}
101+
#endif
84102
#if (IMPROV_ENABLED > 0)
85103
if (!rcpResponseSent && WifiManager::isConnected()) {
86104
rcpResponseSent = true;

src/BootstrapManager.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,29 @@
3030
#include "Helpers.h"
3131
#include "WifiManager.h"
3232
#include "QueueManager.h"
33-
33+
#if defined(ARDUINO_ARCH_ESP32)
34+
#include <esp_task_wdt.h>
35+
#endif
3436

3537
class BootstrapManager {
3638

3739
private:
3840
WifiManager wifiManager; // WifiManager classes for Wifi management
3941
QueueManager queueManager; // QueueManager classes for MQTT queue management
4042
Helpers helper;
43+
#if defined(ARDUINO_ARCH_ESP32)
44+
unsigned long lastMillisForWdt = millis();
45+
#endif
4146

4247
public:
4348
StaticJsonDocument<BUFFER_SIZE> jsonDoc;
4449
StaticJsonDocument<BUFFER_SIZE_MAX_SIZE> jsonDocBigSize;
45-
4650
// using JsonDocument = StaticJsonDocument<BUFFER_SIZE>;
47-
StaticJsonDocument<BUFFER_SIZE>
48-
parseQueueMsg(char *topic, byte *payload, unsigned int length); // print the message arriving from the queue
49-
StaticJsonDocument<BUFFER_SIZE>
50-
parseHttpMsg(String payload, unsigned int length); // print the message arriving from HTTP
51+
StaticJsonDocument<BUFFER_SIZE> parseQueueMsg(char* topic, byte* payload, unsigned int length); // print the message arriving from the queue
52+
StaticJsonDocument<BUFFER_SIZE> parseHttpMsg(String payload, unsigned int length); // print the message arriving from HTTP
5153
void littleFsInit();
52-
53-
void bootstrapSetup(void (*manageDisconnectionFunction)(), void (*manageHardwareButton)(), void (*callback)(char *, byte *, unsigned int)); // bootstrap setup()
54-
void bootstrapSetup(void (*manageDisconnectionFunction)(), void (*manageHardwareButton)(), void (*callback)(char *, byte *, unsigned int), bool waitImprov,
55-
void (*listener)()); // bootstrap setup()
54+
void bootstrapSetup(void (*manageDisconnectionFunction)(), void (*manageHardwareButton)(), void (*callback)(char*, byte*, unsigned int)); // bootstrap setup()
55+
void bootstrapSetup(void (*manageDisconnectionFunction)(), void (*manageHardwareButton)(), void (*callback)(char*, byte*, unsigned int), bool waitImprov, void (*listener)()); // bootstrap setup()
5656
void bootstrapLoop(void (*manageDisconnectionFunction)(), void (*manageQueueSubscription)(), void (*manageHardwareButton)()); // bootstrap loop()
5757
static void setMQTTWill(const char *topic, const char *payload, int qos, boolean retain, boolean cleanSession); // set the last will parameters for mqtt
5858
static void publish(const char *topic, const char *payload, boolean retained); // send a message on the queue
@@ -63,12 +63,12 @@ class BootstrapManager {
6363
JsonObject getJsonObject(); // return a new json object instance
6464
[[maybe_unused]] static void nonBlokingBlink(); // blink default LED when sending data to the queue
6565
[[maybe_unused]] static void getMicrocontrollerInfo(); // print or display microcontroller's info
66-
[[maybe_unused]] void drawInfoPage(const String &softwareVersion, const String &author); // draw a page with all the microcontroller's info
67-
[[maybe_unused]] void drawScreenSaver(const String &txt); // useful for OLED displays
68-
[[maybe_unused]] static void sendState(const char *topic, JsonObject objectToSend, const String &version); // send microcontroller's info on the queue
69-
[[maybe_unused]] static void writeToLittleFS(const DynamicJsonDocument &jDoc, const String &filenameToUse); // write json file to storage
70-
[[maybe_unused]] static StaticJsonDocument<BUFFER_SIZE> readLittleFS(const String &filenameToUse); // read json file from storage
71-
[[maybe_unused]] String readValueFromFile(const String &filenameToUse, const String &paramName); // read a param from a json file
66+
[[maybe_unused]] void drawInfoPage(const String& softwareVersion, const String& author); // draw a page with all the microcontroller's info
67+
[[maybe_unused]] void drawScreenSaver(const String& txt); // useful for OLED displays
68+
[[maybe_unused]] static void sendState(const char *topic, JsonObject objectToSend, const String& version); // send microcontroller's info on the queue
69+
[[maybe_unused]] static void writeToLittleFS(const DynamicJsonDocument& jDoc, const String& filenameToUse); // write json file to storage
70+
[[maybe_unused]] static StaticJsonDocument<BUFFER_SIZE> readLittleFS(const String& filenameToUse); // read json file from storage
71+
[[maybe_unused]] String readValueFromFile(const String& filenameToUse, const String& paramName); // read a param from a json file
7272
static bool isWifiConfigured(); // check if wifi is correctly configured
7373
void launchWebServerForOTAConfig(); // if no ssid available, launch web server to get config params via browser
7474
void launchWebServerCustom(bool waitImprov, void (*listener)()); // if no ssid available, launch web server to get config params via browser

0 commit comments

Comments
 (0)