add WDT 10s, fix 8266, tiny

This commit is contained in:
Mit4el
2024-11-16 15:00:04 +03:00
parent dc87331c4b
commit dbad34b42c
8 changed files with 143 additions and 159 deletions

View File

@@ -17,15 +17,17 @@ typedef struct {
time_t heap_min_time;
uint32_t backtrace[CONFIG_RESTART_DEBUG_STACK_DEPTH];
} re_restart_debug_t;
__NOINIT_ATTR static int8_t bootloop_panic_count;
void IRAM_ATTR debugUpdate();
#endif // RESTART_DEBUG_INFO
__NOINIT_ATTR static int8_t bootloop_panic_count;
extern "C" void __real_esp_panic_handler(void*);
void printDebugTrace();
void sendDebugTraceAndFreeMemory(bool);
void IRAM_ATTR debugUpdate();
void startWatchDog();
extern "C" bool verifyRollbackLater();
void verifyFirmware();

View File

@@ -869,6 +869,7 @@ build_src_filter =
[env:tiny_fromitems]
lib_deps =
plerup/EspSoftwareSerial
build_src_filter =
+<modules/virtual/Cron>
+<modules/virtual/Loging>
@@ -878,5 +879,10 @@ build_src_filter =
+<modules/virtual/Timer>
+<modules/virtual/Variable>
+<modules/virtual/VButton>
+<modules/sensors/AnalogAdc>
+<modules/sensors/BL0937>
+<modules/sensors/UART>
+<modules/exec/AnalogBtn>
+<modules/exec/ButtonIn>
+<modules/exec/ButtonOut>

View File

@@ -1,6 +1,6 @@
#include "DebugTrace.h"
#if defined(RESTART_DEBUG_INFO) && defined(ESP32) && !defined(esp32c3m_4mb)
//#ifdef RESTART_DEBUG_INFO
// #ifdef RESTART_DEBUG_INFO
__NOINIT_ATTR static re_restart_debug_t _debug_info;
#include "esp_debug_helpers.h"
@@ -9,7 +9,6 @@ __NOINIT_ATTR static re_restart_debug_t _debug_info;
#include "esp_err.h"
#include "soc/soc_memory_layout.h"
#include "soc/cpu.h"
#include "esp_ota_ops.h"
// RU: Размер буфера для конвертации даты и времeни в строку
#define CONFIG_FORMAT_STRFTIME_BUFFER_SIZE 32
@@ -215,10 +214,9 @@ void printDebugTrace()
}
Serial.println(INFO_MESSAGE_DEBUG);
}
void sendDebugTraceAndFreeMemory( bool postMsg)
void sendDebugTraceAndFreeMemory(bool postMsg)
{
// esp_register_shutdown_handler(debugUpdate);
re_restart_debug_t debug = debugGet();
@@ -265,7 +263,7 @@ void sendDebugTraceAndFreeMemory( bool postMsg)
}
free(debug_heap);
}
/* else
/* else
{
// Serial.println("DEVICE START");
// Serial.printf(CONFIG_MESSAGE_TG_VERSION_DEF,
@@ -279,13 +277,11 @@ void sendDebugTraceAndFreeMemory( bool postMsg)
free(msg);
}
};*/
}
#else
#else // RESTART_DEBUG_INFO
void printDebugTrace() {}
void sendDebugTraceAndFreeMemory(bool) {}
void IRAM_ATTR debugUpdate() {}
//void IRAM_ATTR debugUpdate() {}
extern "C" void __wrap_esp_panic_handler(void *info)
{
// Call the original panic handler function to finish processing this error (creating a core dump for example...)
@@ -293,33 +289,60 @@ extern "C" void __wrap_esp_panic_handler(void *info)
}
#endif // RESTART_DEBUG_INFO
#if defined(ESP32)
extern "C" bool verifyRollbackLater(){
#include "esp_ota_ops.h"
#include <esp_task_wdt.h>
// 3 seconds WDT, reset in 1 seconds
#define WDT_TIMEOUT 10
void startWatchDog()
{
esp_task_wdt_init(WDT_TIMEOUT, true); // enable panic so ESP32 restarts
esp_task_wdt_add(NULL); // add current thread to WDT watch
}
extern "C" bool verifyRollbackLater()
{
Serial.printf("verifyRollbackLater OVERRIDDEN FUNCTION!");
return true;
}
}
void verifyFirmware(){
void verifyFirmware()
{
Serial.printf("[SYSTEM] - Checking firmware...\n");
const esp_partition_t *running = esp_ota_get_running_partition();
esp_ota_img_states_t ota_state;
if (esp_ota_get_state_partition(running, &ota_state) == ESP_OK) {
const char* otaState = ota_state == ESP_OTA_IMG_NEW ? "ESP_OTA_IMG_NEW"
if (esp_ota_get_state_partition(running, &ota_state) == ESP_OK)
{
const char *otaState = ota_state == ESP_OTA_IMG_NEW ? "ESP_OTA_IMG_NEW"
: ota_state == ESP_OTA_IMG_PENDING_VERIFY ? "ESP_OTA_IMG_PENDING_VERIFY"
: ota_state == ESP_OTA_IMG_VALID ? "ESP_OTA_IMG_VALID"
: ota_state == ESP_OTA_IMG_INVALID ? "ESP_OTA_IMG_INVALID"
: ota_state == ESP_OTA_IMG_ABORTED ? "ESP_OTA_IMG_ABORTED"
: "ESP_OTA_IMG_UNDEFINED";
Serial.printf( "[System] - Ota state: %s\n",otaState);
Serial.printf("[System] - Ota state: %s\n", otaState);
if (ota_state == ESP_OTA_IMG_PENDING_VERIFY) {
if (esp_ota_mark_app_valid_cancel_rollback() == ESP_OK) {
Serial.printf( "[System] - App is valid, rollback cancelled successfully\n");
} else {
if (ota_state == ESP_OTA_IMG_PENDING_VERIFY)
{
if (esp_ota_mark_app_valid_cancel_rollback() == ESP_OK)
{
Serial.printf("[System] - App is valid, rollback cancelled successfully\n");
}
else
{
Serial.printf("[System] - Failed to cancel rollback\n");
}
}
}else{
}
else
{
Serial.printf("[System] - OTA partition has no record in OTA data\n");
}
}
}
#else //ESP32
void startWatchDog() {}
//extern "C" bool verifyRollbackLater() {}
void verifyFirmware() {}
#endif

View File

@@ -38,7 +38,7 @@ AsyncUDP asyncUdp;
void udpListningInit() {
#if defined(LIBRETINY)
if (asyncUdp.listenMulticast(IPAddress(239, 255, 255, 255), 4210/* , WiFi.localIP() */)) {
if (asyncUdp.listenMulticast(IPAddress(239, 255, 255, 255), 4210 , WiFi.localIP() )) {
#else
if (asyncUdp.listenMulticast(IPAddress(239, 255, 255, 255), 4210)) {
#endif

View File

@@ -7,6 +7,9 @@
#include <Wire.h>
#endif
#include "DebugTrace.h"
#if defined(ESP32)
#include <esp_task_wdt.h>
#endif
#if defined(esp32s2_4mb) || defined(esp32s3_16mb)
#include <USB.h>
#endif
@@ -101,11 +104,13 @@ void setup() {
Serial.begin(115200);
Serial.flush();
//----------- Отладка EXCEPTION (функции с заглушками для отключения) ---------
#if defined(RESTART_DEBUG_INFO) && defined(ESP32) && !defined(esp32c3m_4mb)
//Привязка коллбэк функции для вызова при перезагрузке
esp_register_shutdown_handler(debugUpdate);
#endif // RESTART_DEBUG_INFO
// Печать или оправка отладочной информации
printDebugTrace();
startWatchDog();
Serial.println();
Serial.println(F("--------------started----------------"));
@@ -151,7 +156,7 @@ void setup() {
#endif
SerialPrint("i", "i2c", F("i2c pins overriding done"));
}
#if defined(RESTART_DEBUG_INFO) && defined(ESP32) && !defined(esp32c3m_4mb)
if (bootloop_panic_count >= 3)
{
resetSettingsFlashByPanic();
@@ -162,7 +167,7 @@ void setup() {
SerialPrint("E", "CORE", F("CONFIG and SCENARIO reset !!!"));
bootloop_panic_count = 0;
}
#endif // RESTART_DEBUG_INFO
// настраиваем микроконтроллер
configure("/config.json");
@@ -228,6 +233,11 @@ void setup() {
// настраиваем секундные обслуживания системы
ts.add(
TIMES, 1000, [&](void *) {
// сброс WDT
#if defined(ESP32)
SerialPrint("i", "Task", "Resetting WDT...");
esp_task_wdt_reset();
#endif
// сохраняем значения IoTItems в файл каждую секунду, если были изменения (установлены маркеры на сохранение)
if (needSaveValues) {
syncValuesFlashJson();
@@ -248,7 +258,9 @@ void setup() {
Serial.println("--------test end---------");
stopErrorMarker(SETUPLAST_ERRORMARKER);
#if defined(RESTART_DEBUG_INFO) && defined(ESP32) && !defined(esp32c3m_4mb)
bootloop_panic_count = 0;
#endif // RESTART_DEBUG_INFO
}
void loop() {

View File

@@ -8,7 +8,7 @@
#include "utils/SerialPrint.h"
void ntpInit() {
#if defined(USE_LIBRETINY)
#if defined(LIBRETINY)
if (sntp_enabled()) {
sntp_stop();
}
@@ -23,6 +23,7 @@ void ntpInit() {
ts.add(
TIME, 1000, [&](void*) {
unixTime = getSystemTime();
//SerialPrint("I", F("NTP"), "TIME " + String(unixTime));
if (unixTime < MIN_DATETIME) {
isTimeSynch = false;
// SerialPrint("E", "NTP", "Time not synched");
@@ -62,8 +63,9 @@ void synchTime() {
// force resync
if (sntp_enabled()) {
sntp_stop();
sntp_init();
}
sntp_init();
#else
configTime(0, 0, "pool.ntp.org", "ru.pool.ntp.org", jsonReadStr(settingsFlashJson, F("ntp")).c_str());
#endif

View File

@@ -599,20 +599,20 @@ void handleFileList() {
if (path != "/" && !FileFS.exists(path)) {
return replyBadRequest("BAD PATH");
}
lfs_dir_t dir;
struct lfs_info info;
int err = lfs_dir_open(&lfs, &dir, path);
if (err) {
FileFS.open(path.c_str());
lfs_dir_t dir;
struct lfs_info info;
int err = lfs_dir_open(FileFS.getFS(), &dir, path.c_str());
if (err) {
HTTP.send(500, "text/plain", "FAIL OPEN DIR");
return;
}
String output = "[";
while (true) {
int res = lfs_dir_read(&lfs, &dir, &info);
}
String output = "[";
while (true) {
int res = lfs_dir_read(FileFS.getFS(), &dir, &info);
if (res < 0) {
lfs_dir_close(&lfs, &dir);
return err;
lfs_dir_close(FileFS.getFS(), &dir);
return ;
}
if (!res) {
@@ -638,18 +638,13 @@ while (true) {
output += "\"}";
//file = root.openNextFile();
}
}
err = lfs_dir_close(&lfs, &dir);
if (err) {
err = lfs_dir_close(FileFS.getFS(), &dir);
if (err) {
HTTP.send(500, "text/plain", "FAIL CLOSE DIR");
return;
}
}
output += "]";
HTTP.send(200, "text/json", output);

View File

@@ -5,43 +5,15 @@ void* getAPI_Loging(String subtype, String params);
void* getAPI_LogingDaily(String subtype, String params);
void* getAPI_IoTMath(String subtype, String params);
void* getAPI_owmWeather(String subtype, String params);
void* getAPI_Ping(String subtype, String params);
void* getAPI_Timer(String subtype, String params);
void* getAPI_Variable(String subtype, String params);
void* getAPI_VButton(String subtype, String params);
void* getAPI_A02Distance(String subtype, String params);
void* getAPI_Acs712(String subtype, String params);
void* getAPI_AhtXX(String subtype, String params);
void* getAPI_AnalogAdc(String subtype, String params);
void* getAPI_BL0937(String subtype, String params);
void* getAPI_Bme280(String subtype, String params);
void* getAPI_Bmp280(String subtype, String params);
void* getAPI_Dht1122(String subtype, String params);
void* getAPI_Ds18b20(String subtype, String params);
void* getAPI_Impulse(String subtype, String params);
void* getAPI_MQgas(String subtype, String params);
void* getAPI_Pzem004_v2(String subtype, String params);
void* getAPI_RTC(String subtype, String params);
void* getAPI_S8(String subtype, String params);
void* getAPI_Sht20(String subtype, String params);
void* getAPI_Sht30(String subtype, String params);
void* getAPI_Sonar(String subtype, String params);
void* getAPI_UART(String subtype, String params);
void* getAPI_AnalogBtn(String subtype, String params);
void* getAPI_ButtonIn(String subtype, String params);
void* getAPI_ButtonOut(String subtype, String params);
void* getAPI_Buzzer(String subtype, String params);
void* getAPI_Encoder(String subtype, String params);
void* getAPI_IoTServo(String subtype, String params);
void* getAPI_Mcp23017(String subtype, String params);
void* getAPI_Mp3(String subtype, String params);
void* getAPI_Multitouch(String subtype, String params);
void* getAPI_Pcf8574(String subtype, String params);
void* getAPI_Pwm8266(String subtype, String params);
void* getAPI_TelegramLT(String subtype, String params);
void* getAPI_DwinI(String subtype, String params);
void* getAPI_Lcd2004(String subtype, String params);
void* getAPI_Oled64(String subtype, String params);
void* getAPI(String subtype, String params) {
void* tmpAPI;
@@ -50,42 +22,14 @@ if ((tmpAPI = getAPI_Loging(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_LogingDaily(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_IoTMath(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_owmWeather(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Ping(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Timer(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Variable(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_VButton(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_A02Distance(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Acs712(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_AhtXX(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_AnalogAdc(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_BL0937(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Bme280(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Bmp280(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Dht1122(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Ds18b20(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Impulse(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_MQgas(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Pzem004_v2(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_RTC(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_S8(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Sht20(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Sht30(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Sonar(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_UART(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_AnalogBtn(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_ButtonIn(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Buzzer(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Encoder(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_IoTServo(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Multitouch(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Pcf8574(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Pwm8266(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_TelegramLT(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_DwinI(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Oled64(subtype, params)) != nullptr) return tmpAPI;
return nullptr;
}