mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-31 04:19:15 +03:00
DebugTrace, Nextion, BrokerMQTT
This commit is contained in:
20
include/DebugTrace.h
Normal file
20
include/DebugTrace.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
//
|
||||||
|
#include "Global.h"
|
||||||
|
|
||||||
|
#define RESTART_DEBUG_INFO
|
||||||
|
#if defined(RESTART_DEBUG_INFO) && defined(ESP32) && !defined(esp32c3m_4mb)
|
||||||
|
#define CONFIG_RESTART_DEBUG_STACK_DEPTH 15
|
||||||
|
typedef struct {
|
||||||
|
size_t heap_total;
|
||||||
|
size_t heap_free;
|
||||||
|
size_t heap_free_min;
|
||||||
|
time_t heap_min_time;
|
||||||
|
uint32_t backtrace[CONFIG_RESTART_DEBUG_STACK_DEPTH];
|
||||||
|
} re_restart_debug_t;
|
||||||
|
|
||||||
|
#endif // RESTART_DEBUG_INFO
|
||||||
|
extern "C" void __real_esp_panic_handler(void*);
|
||||||
|
void printDebugTrace();
|
||||||
|
void sendDebugTraceAndFreeMemory(bool);
|
||||||
|
void IRAM_ATTR debugUpdate();
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
[platformio]
|
[platformio]
|
||||||
default_envs = esp8266_4mb
|
default_envs = esp32_4mb3f
|
||||||
data_dir = data_svelte
|
data_dir = data_svelte
|
||||||
|
|
||||||
[common_env_data]
|
[common_env_data]
|
||||||
@@ -185,9 +185,10 @@ lib_deps =
|
|||||||
${common_env_data.lib_deps_external}
|
${common_env_data.lib_deps_external}
|
||||||
${env:esp32_4mb_fromitems.lib_deps}
|
${env:esp32_4mb_fromitems.lib_deps}
|
||||||
build_flags = -Desp32_4mb="esp32_4mb"
|
build_flags = -Desp32_4mb="esp32_4mb"
|
||||||
|
-Wl,--wrap=esp_panic_handler
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
platform = espressif32 @5.1.1
|
platform = espressif32 @6.6.0
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
@@ -206,9 +207,10 @@ lib_deps =
|
|||||||
${common_env_data.lib_deps_external}
|
${common_env_data.lib_deps_external}
|
||||||
${env:esp32_4mb3f_fromitems.lib_deps}
|
${env:esp32_4mb3f_fromitems.lib_deps}
|
||||||
build_flags = -Desp32_4mb="esp32_4mb"
|
build_flags = -Desp32_4mb="esp32_4mb"
|
||||||
|
-Wl,--wrap=esp_panic_handler
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
platform = espressif32 @5.1.1
|
platform = espressif32 @6.6.0
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
@@ -231,9 +233,10 @@ build_flags =
|
|||||||
-Desp32cam_4mb="esp32cam_4mb"
|
-Desp32cam_4mb="esp32cam_4mb"
|
||||||
-DBOARD_HAS_PSRAM
|
-DBOARD_HAS_PSRAM
|
||||||
-mfix-esp32-psram-cache-issue
|
-mfix-esp32-psram-cache-issue
|
||||||
|
-Wl,--wrap=esp_panic_handler
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board = esp32cam
|
board = esp32cam
|
||||||
platform = espressif32 @5.1.1
|
platform = espressif32 @6.6.0
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
@@ -251,13 +254,13 @@ extra_scripts = pre:tools/patch32_ws.py
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
${common_env_data.lib_deps_external}
|
${common_env_data.lib_deps_external}
|
||||||
${env:esp32s2_4mb_fromitems.lib_deps}
|
${env:esp32s2_4mb_fromitems.lib_deps}
|
||||||
build_flags =
|
build_flags = -Desp32s2_4mb="esp32s2_4mb"
|
||||||
-Desp32s2_4mb="esp32s2_4mb"
|
|
||||||
-DARDUINO_USB_CDC_ON_BOOT=1
|
-DARDUINO_USB_CDC_ON_BOOT=1
|
||||||
-DARDUINO_USB_MODE=0
|
-DARDUINO_USB_MODE=0
|
||||||
|
-Wl,--wrap=esp_panic_handler
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board = lolin_s2_mini
|
board = lolin_s2_mini
|
||||||
platform = espressif32 @6.3.1
|
platform = espressif32 @6.6.0
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
@@ -275,11 +278,11 @@ extra_scripts = pre:tools/patch32_ws.py
|
|||||||
lib_deps =
|
lib_deps =
|
||||||
${common_env_data.lib_deps_external}
|
${common_env_data.lib_deps_external}
|
||||||
${env:esp32c3m_4mb_fromitems.lib_deps}
|
${env:esp32c3m_4mb_fromitems.lib_deps}
|
||||||
build_flags =
|
build_flags = -Desp32c3m_4mb="esp32c3m_4mb"
|
||||||
-Desp32c3m_4mb="esp32c3m_4mb"
|
-Wl,--wrap=esp_panic_handler
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board = lolin_c3_mini
|
board = lolin_c3_mini
|
||||||
platform = espressif32 @6.3.1
|
platform = espressif32 @6.6.0
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
@@ -300,10 +303,11 @@ lib_deps =
|
|||||||
${env:esp32s3_16mb_fromitems.lib_deps}
|
${env:esp32s3_16mb_fromitems.lib_deps}
|
||||||
build_flags =
|
build_flags =
|
||||||
-Desp32s3_16mb="esp32s3_16mb"
|
-Desp32s3_16mb="esp32s3_16mb"
|
||||||
|
-Wl,--wrap=esp_panic_handler
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board = esp32-s3-devkitc-1
|
board = esp32-s3-devkitc-1
|
||||||
board_build.mcu = esp32s3
|
board_build.mcu = esp32s3
|
||||||
platform = espressif32 @6.3.1
|
platform = espressif32 @6.6.0
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
@@ -324,9 +328,10 @@ lib_deps =
|
|||||||
${common_env_data.lib_deps_external}
|
${common_env_data.lib_deps_external}
|
||||||
${env:esp32_16mb_fromitems.lib_deps}
|
${env:esp32_16mb_fromitems.lib_deps}
|
||||||
build_flags = -Desp32_16mb="esp32_16mb"
|
build_flags = -Desp32_16mb="esp32_16mb"
|
||||||
|
-Wl,--wrap=esp_panic_handler
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board = esp32dev
|
board = esp32dev
|
||||||
platform = espressif32 @5.1.1
|
platform = espressif32 @6.6.0
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
upload_port = COM11
|
upload_port = COM11
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
|
|||||||
287
src/DebugTrace.cpp
Normal file
287
src/DebugTrace.cpp
Normal file
@@ -0,0 +1,287 @@
|
|||||||
|
#include "DebugTrace.h"
|
||||||
|
#if defined(RESTART_DEBUG_INFO) && defined(ESP32) && !defined(esp32c3m_4mb)
|
||||||
|
//#ifdef RESTART_DEBUG_INFO
|
||||||
|
__NOINIT_ATTR static re_restart_debug_t _debug_info;
|
||||||
|
|
||||||
|
#include "esp_debug_helpers.h"
|
||||||
|
#include "esp_types.h"
|
||||||
|
#include "esp_attr.h"
|
||||||
|
#include "esp_err.h"
|
||||||
|
#include "soc/soc_memory_layout.h"
|
||||||
|
#include "soc/cpu.h"
|
||||||
|
|
||||||
|
// RU: Размер буфера для конвертации даты и времeни в строку
|
||||||
|
#define CONFIG_FORMAT_STRFTIME_BUFFER_SIZE 32
|
||||||
|
#define CONFIG_FORMAT_STRFTIME_DTS_BUFFER_SIZE 20 // YYYY.MM.DD HH:NN:SS + \n
|
||||||
|
|
||||||
|
// RU: Форматы даты и времени
|
||||||
|
#define CONFIG_FORMAT_DTS "%d.%m.%Y %H:%M:%S"
|
||||||
|
|
||||||
|
void IRAM_ATTR debugHeapUpdate()
|
||||||
|
{
|
||||||
|
_debug_info.heap_total = heap_caps_get_total_size(MALLOC_CAP_DEFAULT);
|
||||||
|
_debug_info.heap_free = heap_caps_get_free_size(MALLOC_CAP_DEFAULT);
|
||||||
|
size_t _new_free_min = heap_caps_get_minimum_free_size(MALLOC_CAP_DEFAULT);
|
||||||
|
if ((_debug_info.heap_free_min == 0) || (_new_free_min < _debug_info.heap_free_min))
|
||||||
|
{
|
||||||
|
_debug_info.heap_free_min = _new_free_min;
|
||||||
|
_debug_info.heap_min_time = time(nullptr);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void IRAM_ATTR debugBacktraceUpdate()
|
||||||
|
{
|
||||||
|
esp_backtrace_frame_t stk_frame;
|
||||||
|
esp_backtrace_get_start(&(stk_frame.pc), &(stk_frame.sp), &(stk_frame.next_pc));
|
||||||
|
_debug_info.backtrace[0] = esp_cpu_process_stack_pc(stk_frame.pc);
|
||||||
|
|
||||||
|
bool corrupted = (esp_stack_ptr_is_sane(stk_frame.sp) &&
|
||||||
|
esp_ptr_executable((void *)esp_cpu_process_stack_pc(stk_frame.pc)))
|
||||||
|
? false
|
||||||
|
: true;
|
||||||
|
|
||||||
|
uint8_t i = CONFIG_RESTART_DEBUG_STACK_DEPTH;
|
||||||
|
while (i-- > 0 && stk_frame.next_pc != 0 && !corrupted)
|
||||||
|
{
|
||||||
|
if (!esp_backtrace_get_next_frame(&stk_frame))
|
||||||
|
{
|
||||||
|
corrupted = true;
|
||||||
|
};
|
||||||
|
_debug_info.backtrace[CONFIG_RESTART_DEBUG_STACK_DEPTH - i] = esp_cpu_process_stack_pc(stk_frame.pc);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void IRAM_ATTR debugUpdate()
|
||||||
|
{
|
||||||
|
debugHeapUpdate();
|
||||||
|
debugBacktraceUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void __wrap_esp_panic_handler(void *info)
|
||||||
|
{
|
||||||
|
|
||||||
|
debugHeapUpdate();
|
||||||
|
debugBacktraceUpdate();
|
||||||
|
// Call the original panic handler function to finish processing this error (creating a core dump for example...)
|
||||||
|
__real_esp_panic_handler(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
re_restart_debug_t debugGet()
|
||||||
|
{
|
||||||
|
re_restart_debug_t ret;
|
||||||
|
memset(&ret, 0, sizeof(re_restart_debug_t));
|
||||||
|
esp_reset_reason_t esp_reason = esp_reset_reason();
|
||||||
|
if ((esp_reason != ESP_RST_UNKNOWN) && (esp_reason != ESP_RST_POWERON))
|
||||||
|
{
|
||||||
|
uint8_t i = CONFIG_RESTART_DEBUG_STACK_DEPTH;
|
||||||
|
ret = _debug_info;
|
||||||
|
if (_debug_info.heap_total > heap_caps_get_total_size(MALLOC_CAP_DEFAULT))
|
||||||
|
{
|
||||||
|
memset(&ret, 0, sizeof(re_restart_debug_t));
|
||||||
|
};
|
||||||
|
};
|
||||||
|
memset(&_debug_info, 0, sizeof(re_restart_debug_t));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CONFIG_MESSAGE_TG_VERSION_DEF "! Устройство запущено\n\nИмя устройства: %s\nПричина перезапуска: %s\nCPU0: %s\nCPU1: %s"
|
||||||
|
#define CONFIG_MESSAGE_TG_VERSION_HEAP "! Устройство аварийно перезапущено !\n\nИмя устройства: %s\nПричина перезапуска: %s\nCPU0: %s\nCPU1: %s\nHEAP: %s"
|
||||||
|
#define CONFIG_MESSAGE_TG_VERSION_TRACE "! Устройство аварийно перезапущено !\n\nИмя устройства: %s\nПричина перезапуска: %s\nCPU0: %s\nCPU1: %s\nHEAP: %s\nTRACE: %s"
|
||||||
|
|
||||||
|
char *malloc_stringf(const char *format, ...)
|
||||||
|
{
|
||||||
|
char *ret = nullptr;
|
||||||
|
if (format != nullptr)
|
||||||
|
{
|
||||||
|
// get the list of arguments
|
||||||
|
va_list args1, args2;
|
||||||
|
va_start(args1, format);
|
||||||
|
va_copy(args2, args1);
|
||||||
|
// calculate length of resulting string
|
||||||
|
int len = vsnprintf(nullptr, 0, format, args1);
|
||||||
|
va_end(args1);
|
||||||
|
// allocate memory for string
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
|
#if USE_ESP_MALLOC
|
||||||
|
ret = (char *)esp_malloc(len + 1);
|
||||||
|
#else
|
||||||
|
ret = (char *)malloc(len + 1);
|
||||||
|
#endif
|
||||||
|
if (ret != nullptr)
|
||||||
|
{
|
||||||
|
memset(ret, 0, len + 1);
|
||||||
|
vsnprintf(ret, len + 1, format, args2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// rlog_e(tagHEAP, "Failed to format string: out of memory!");
|
||||||
|
};
|
||||||
|
};
|
||||||
|
va_end(args2);
|
||||||
|
};
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *statesGetDebugHeap(re_restart_debug_t *debug)
|
||||||
|
{
|
||||||
|
if ((debug->heap_total > 0) && (debug->heap_total > debug->heap_free))
|
||||||
|
{
|
||||||
|
struct tm timeinfo;
|
||||||
|
localtime_r(&debug->heap_min_time, &timeinfo);
|
||||||
|
char time_buffer[CONFIG_FORMAT_STRFTIME_DTS_BUFFER_SIZE];
|
||||||
|
memset(&time_buffer, 0, CONFIG_FORMAT_STRFTIME_DTS_BUFFER_SIZE);
|
||||||
|
strftime(time_buffer, CONFIG_FORMAT_STRFTIME_DTS_BUFFER_SIZE, CONFIG_FORMAT_DTS, &timeinfo);
|
||||||
|
|
||||||
|
double heapTotal = (double)debug->heap_total / 1024;
|
||||||
|
double heapFree = (double)debug->heap_free / 1024;
|
||||||
|
double heapFreeMin = (double)debug->heap_free_min / 1024;
|
||||||
|
|
||||||
|
return malloc_stringf("Total %.1fkB ; Free %.1fkB (%.1f%%) ; FreeMin %.1fkB (%.1f%%) %s",
|
||||||
|
heapTotal,
|
||||||
|
heapFree, 100.0 * (heapFree / heapTotal),
|
||||||
|
heapFreeMin, 100.0 * (heapFreeMin / heapTotal), time_buffer);
|
||||||
|
};
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *statesGetDebugTrace(re_restart_debug_t *debug)
|
||||||
|
{
|
||||||
|
char *backtrace = nullptr;
|
||||||
|
char *item = nullptr;
|
||||||
|
char *temp = nullptr;
|
||||||
|
for (uint8_t i = 0; i < CONFIG_RESTART_DEBUG_STACK_DEPTH; i++)
|
||||||
|
{
|
||||||
|
if (debug->backtrace[i] != 0)
|
||||||
|
{
|
||||||
|
item = malloc_stringf("0x%08x", debug->backtrace[i]);
|
||||||
|
if (item)
|
||||||
|
{
|
||||||
|
if (backtrace)
|
||||||
|
{
|
||||||
|
temp = backtrace;
|
||||||
|
backtrace = malloc_stringf("%s %s", temp, item);
|
||||||
|
free(item);
|
||||||
|
free(temp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
backtrace = item;
|
||||||
|
};
|
||||||
|
item = nullptr;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return backtrace;
|
||||||
|
}
|
||||||
|
|
||||||
|
void printDebugTrace()
|
||||||
|
{
|
||||||
|
// esp_register_shutdown_handler(debugUpdate);
|
||||||
|
re_restart_debug_t debug = debugGet();
|
||||||
|
char *debug_heap = statesGetDebugHeap(&debug);
|
||||||
|
char *debug_trace = nullptr;
|
||||||
|
if (debug_heap)
|
||||||
|
{
|
||||||
|
debug_trace = statesGetDebugTrace(&debug);
|
||||||
|
if (debug_trace)
|
||||||
|
{
|
||||||
|
Serial.printf(CONFIG_MESSAGE_TG_VERSION_TRACE,
|
||||||
|
jsonReadStr(settingsFlashJson, F("name")), ESP_getResetReason().c_str(), ESP32GetResetReason(0).c_str(), ESP32GetResetReason(1).c_str(),
|
||||||
|
debug_heap, debug_trace);
|
||||||
|
// free(debug_trace);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial.printf(CONFIG_MESSAGE_TG_VERSION_HEAP,
|
||||||
|
jsonReadStr(settingsFlashJson, F("name")), ESP_getResetReason().c_str(), ESP32GetResetReason(0).c_str(), ESP32GetResetReason(1).c_str(),
|
||||||
|
debug_heap);
|
||||||
|
};
|
||||||
|
// free(debug_heap);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Serial.println("DEVICE START");
|
||||||
|
Serial.printf(CONFIG_MESSAGE_TG_VERSION_DEF,
|
||||||
|
jsonReadStr(settingsFlashJson, F("name")), ESP_getResetReason().c_str(), ESP32GetResetReason(0).c_str(), ESP32GetResetReason(1).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendDebugTraceAndFreeMemory( bool postMsg)
|
||||||
|
{
|
||||||
|
// esp_register_shutdown_handler(debugUpdate);
|
||||||
|
re_restart_debug_t debug = debugGet();
|
||||||
|
char *debug_heap = statesGetDebugHeap(&debug);
|
||||||
|
char *debug_trace = nullptr;
|
||||||
|
|
||||||
|
if (debug_heap)
|
||||||
|
{
|
||||||
|
if (isNetworkActive() && postMsg)
|
||||||
|
{
|
||||||
|
debug_trace = statesGetDebugTrace(&debug);
|
||||||
|
if (debug_trace)
|
||||||
|
{
|
||||||
|
if (tlgrmItem)
|
||||||
|
{
|
||||||
|
char *msg;
|
||||||
|
msg = malloc_stringf(CONFIG_MESSAGE_TG_VERSION_TRACE,
|
||||||
|
jsonReadStr(settingsFlashJson, F("name")).c_str(), ESP_getResetReason().c_str(), ESP32GetResetReason(0).c_str(), ESP32GetResetReason(1).c_str(),
|
||||||
|
debug_heap, debug_trace);
|
||||||
|
tlgrmItem->sendTelegramMsg(false, String(msg));
|
||||||
|
tlgrmItem->sendTelegramMsg(false, String("Подробности /helpDebug в Telegram_v2"));
|
||||||
|
free(msg);
|
||||||
|
}
|
||||||
|
free(debug_trace);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Serial.printf(CONFIG_MESSAGE_TG_VERSION_HEAP,
|
||||||
|
jsonReadStr(settingsFlashJson, F("name")), ESP_getResetReason().c_str(), ESP32GetResetReason(0).c_str(), ESP32GetResetReason(1).c_str(),
|
||||||
|
debug_heap);
|
||||||
|
*/
|
||||||
|
if (tlgrmItem)
|
||||||
|
{
|
||||||
|
char *msg;
|
||||||
|
msg = malloc_stringf(CONFIG_MESSAGE_TG_VERSION_HEAP,
|
||||||
|
jsonReadStr(settingsFlashJson, F("name")).c_str(), ESP_getResetReason().c_str(), ESP32GetResetReason(0).c_str(), ESP32GetResetReason(1).c_str(),
|
||||||
|
debug_heap);
|
||||||
|
tlgrmItem->sendTelegramMsg(false, String(msg));
|
||||||
|
tlgrmItem->sendTelegramMsg(false, String("Подробности /helpDebug в Telegram_v2"));
|
||||||
|
free(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(debug_heap);
|
||||||
|
}
|
||||||
|
/* else
|
||||||
|
{
|
||||||
|
// Serial.println("DEVICE START");
|
||||||
|
// Serial.printf(CONFIG_MESSAGE_TG_VERSION_DEF,
|
||||||
|
// FIRMWARE_VERSION, ESP_getResetReason().c_str(), ESP32GetResetReason(0).c_str(), ESP32GetResetReason(1).c_str());
|
||||||
|
if (tlgrmItem && isNetworkActive())
|
||||||
|
{
|
||||||
|
char *msg;
|
||||||
|
msg = malloc_stringf(CONFIG_MESSAGE_TG_VERSION_DEF,
|
||||||
|
WiFi.localIP().toString(), FIRMWARE_VERSION, ESP_getResetReason().c_str(), ESP32GetResetReason(0).c_str(), ESP32GetResetReason(1).c_str());
|
||||||
|
tlgrmItem->sendTelegramMsg(false, String(msg));
|
||||||
|
free(msg);
|
||||||
|
}
|
||||||
|
};*/
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
void printDebugTrace() {}
|
||||||
|
void sendDebugTraceAndFreeMemory(bool) {}
|
||||||
|
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...)
|
||||||
|
__real_esp_panic_handler(info);
|
||||||
|
}
|
||||||
|
#endif // RESTART_DEBUG_INFO
|
||||||
@@ -79,7 +79,7 @@ uint32_t ESP_getChipId(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// устарела используем новую функцию ниже
|
/*// устарела используем новую функцию ниже
|
||||||
#if !defined(esp32s2_4mb) && !defined(esp32c3m_4mb) && !defined(esp32s3_16mb)
|
#if !defined(esp32s2_4mb) && !defined(esp32c3m_4mb) && !defined(esp32s3_16mb)
|
||||||
//#ifndef esp32s2_4mb
|
//#ifndef esp32s2_4mb
|
||||||
uint32_t ESP_getFlashChipId(void)
|
uint32_t ESP_getFlashChipId(void)
|
||||||
@@ -93,6 +93,7 @@ uint32_t ESP_getFlashChipId(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
// https://github.com/espressif/arduino-esp32/issues/6945#issuecomment-1199900892
|
// https://github.com/espressif/arduino-esp32/issues/6945#issuecomment-1199900892
|
||||||
// получение flash ch id из проекта esp easy
|
// получение flash ch id из проекта esp easy
|
||||||
|
|||||||
11
src/Main.cpp
11
src/Main.cpp
@@ -4,6 +4,7 @@
|
|||||||
#include "utils/Statistic.h"
|
#include "utils/Statistic.h"
|
||||||
#include "classes/IoTBench.h"
|
#include "classes/IoTBench.h"
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
|
#include "DebugTrace.h"
|
||||||
#if defined(esp32s2_4mb) || defined(esp32s3_16mb)
|
#if defined(esp32s2_4mb) || defined(esp32s3_16mb)
|
||||||
#include <USB.h>
|
#include <USB.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -97,6 +98,12 @@ void setup() {
|
|||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
|
//----------- Отладка EXCEPTION (функции с заглушками для отключения) ---------
|
||||||
|
//Привязка коллбэк функции для вызова при перезагрузке
|
||||||
|
esp_register_shutdown_handler(debugUpdate);
|
||||||
|
// Печать или оправка отладочной информации
|
||||||
|
printDebugTrace();
|
||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println(F("--------------started----------------"));
|
Serial.println(F("--------------started----------------"));
|
||||||
|
|
||||||
@@ -179,6 +186,10 @@ void setup() {
|
|||||||
|
|
||||||
stopErrorMarker(SETUPINET_ERRORMARKER);
|
stopErrorMarker(SETUPINET_ERRORMARKER);
|
||||||
|
|
||||||
|
bool postMsgTelegram;
|
||||||
|
if (!jsonRead(settingsFlashJson, "debugTrace", postMsgTelegram, false)) postMsgTelegram = 1;
|
||||||
|
sendDebugTraceAndFreeMemory(postMsgTelegram);
|
||||||
|
|
||||||
initErrorMarker(SETUPLAST_ERRORMARKER);
|
initErrorMarker(SETUPLAST_ERRORMARKER);
|
||||||
|
|
||||||
elementsLoop();
|
elementsLoop();
|
||||||
|
|||||||
@@ -61,7 +61,22 @@ String ESP_getResetReason(void) {
|
|||||||
#endif
|
#endif
|
||||||
#if defined(esp32s2_4mb) || defined(esp32s3_16mb) || defined(esp32c3m_4mb)
|
#if defined(esp32s2_4mb) || defined(esp32s3_16mb) || defined(esp32c3m_4mb)
|
||||||
String ESP_getResetReason(void) {
|
String ESP_getResetReason(void) {
|
||||||
return ESP32GetResetReason(0); // CPU 0
|
// return ESP32GetResetReason(0); // CPU 0
|
||||||
|
esp_reset_reason_t esp_reason = esp_reset_reason();
|
||||||
|
switch (esp_reason) {
|
||||||
|
case ESP_RST_UNKNOWN: return "UNKNOWN";
|
||||||
|
case ESP_RST_POWERON: return "POWER ON";
|
||||||
|
case ESP_RST_EXT: return "EXTERNAL PIN";
|
||||||
|
case ESP_RST_SW: return "SOFTWARE RESET";
|
||||||
|
case ESP_RST_PANIC: return "EXCEPTION / PANIC";
|
||||||
|
case ESP_RST_INT_WDT: return "INTERRUPT WATCHDOG";
|
||||||
|
case ESP_RST_TASK_WDT: return "TASK WATCHDOG";
|
||||||
|
case ESP_RST_WDT: return "WATCHDOGS";
|
||||||
|
case ESP_RST_DEEPSLEEP: return "EXITING DEEP SLLEP MODE";
|
||||||
|
case ESP_RST_BROWNOUT: return "BROWNOUT";
|
||||||
|
case ESP_RST_SDIO: return "SDIO";
|
||||||
|
default : return "NO MEAN";
|
||||||
|
};
|
||||||
}
|
}
|
||||||
String ESP32GetResetReason(uint32_t cpu_no) {
|
String ESP32GetResetReason(uint32_t cpu_no) {
|
||||||
// tools\sdk\include\esp32\rom\rtc.h
|
// tools\sdk\include\esp32\rom\rtc.h
|
||||||
@@ -103,7 +118,22 @@ String ESP32GetResetReason(uint32_t cpu_no) {
|
|||||||
#endif
|
#endif
|
||||||
#if defined(esp32_4mb) || defined(esp32_16mb) || defined(esp32cam_4mb)
|
#if defined(esp32_4mb) || defined(esp32_16mb) || defined(esp32cam_4mb)
|
||||||
String ESP_getResetReason(void) {
|
String ESP_getResetReason(void) {
|
||||||
return ESP32GetResetReason(0); // CPU 0
|
// return ESP32GetResetReason(0); // CPU 0
|
||||||
|
esp_reset_reason_t esp_reason = esp_reset_reason();
|
||||||
|
switch (esp_reason) {
|
||||||
|
case ESP_RST_UNKNOWN: return "UNKNOWN";
|
||||||
|
case ESP_RST_POWERON: return "POWER ON";
|
||||||
|
case ESP_RST_EXT: return "EXTERNAL PIN";
|
||||||
|
case ESP_RST_SW: return "SOFTWARE RESET";
|
||||||
|
case ESP_RST_PANIC: return "EXCEPTION / PANIC";
|
||||||
|
case ESP_RST_INT_WDT: return "INTERRUPT WATCHDOG";
|
||||||
|
case ESP_RST_TASK_WDT: return "TASK WATCHDOG";
|
||||||
|
case ESP_RST_WDT: return "WATCHDOGS";
|
||||||
|
case ESP_RST_DEEPSLEEP: return "EXITING DEEP SLLEP MODE";
|
||||||
|
case ESP_RST_BROWNOUT: return "BROWNOUT";
|
||||||
|
case ESP_RST_SDIO: return "SDIO";
|
||||||
|
default : return "NO MEAN";
|
||||||
|
};
|
||||||
}
|
}
|
||||||
String ESP32GetResetReason(uint32_t cpu_no) {
|
String ESP32GetResetReason(uint32_t cpu_no) {
|
||||||
// tools\sdk\include\esp32\rom\rtc.h
|
// tools\sdk\include\esp32\rom\rtc.h
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,15 @@
|
|||||||
* @file NexUpload.h
|
* @file NexUpload.h
|
||||||
* The definition of class NexUpload.
|
* The definition of class NexUpload.
|
||||||
*
|
*
|
||||||
|
* 1 - Removed all the Arduino code and replaced it by ESP-IDF
|
||||||
|
* 2 - Removed hard-coded UART configuration, see ESPNexUpload constructor
|
||||||
|
* 3 - Removed statusMessage and the function _printInfoLine
|
||||||
|
* 4 - Removed call-back functionality
|
||||||
|
* 5 - Removed one out of two upload functions
|
||||||
|
* 6 - BugFix in upload function
|
||||||
|
* @author Machiel Mastenbroek (machiel.mastenbroek@gmail.com)
|
||||||
|
* @date 2022/08/14
|
||||||
|
* @version 0.6.0
|
||||||
*
|
*
|
||||||
* 1 - BugFix when display baudrate is diffrent from initial ESP baudrate
|
* 1 - BugFix when display baudrate is diffrent from initial ESP baudrate
|
||||||
* 2 - Improved debug information
|
* 2 - Improved debug information
|
||||||
@@ -52,25 +61,27 @@
|
|||||||
|
|
||||||
#ifndef __ESPNEXUPLOAD_H__
|
#ifndef __ESPNEXUPLOAD_H__
|
||||||
#define __ESPNEXUPLOAD_H__
|
#define __ESPNEXUPLOAD_H__
|
||||||
#include <functional>
|
//#include <iostream>
|
||||||
|
#include <string.h> /* printf, scanf, NULL */
|
||||||
|
|
||||||
|
//#include <inttypes.h>
|
||||||
|
#include "esp_log.h"
|
||||||
|
//#include "freertos/FreeRTOS.h"
|
||||||
|
//#include "freertos/task.h"
|
||||||
|
//#include "driver/gpio.h"
|
||||||
|
#include "driver/uart.h"
|
||||||
|
|
||||||
|
//#include "hal/uart_types.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <StreamString.h>
|
#include <StreamString.h>
|
||||||
|
|
||||||
#ifdef ESP8266
|
#define CONFIG_NEX_UART_RECV_BUFFER_SIZE 256
|
||||||
#include <SoftwareSerial.h>
|
|
||||||
#else
|
|
||||||
#include <HardwareSerial.h>
|
|
||||||
#include <SoftwareSerial.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup CoreAPI
|
* @addtogroup CoreAPI
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// callback template definition
|
|
||||||
typedef std::function<void(void)> THandlerFunction;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Provides the API for nextion to upload the ftf file.
|
* Provides the API for nextion to upload the ftf file.
|
||||||
@@ -78,21 +89,18 @@ typedef std::function<void(void)> THandlerFunction;
|
|||||||
class ESPNexUpload
|
class ESPNexUpload
|
||||||
{
|
{
|
||||||
public: /* methods */
|
public: /* methods */
|
||||||
// callback template definition
|
|
||||||
typedef std::function<void(void)> THandlerFunction;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param uint32_t upload_baudrate - set upload baudrate.
|
|
||||||
*/
|
*/
|
||||||
ESPNexUpload(uint32_t upload_baudrate, int line, int rx, int tx);
|
ESPNexUpload(uart_port_t uart_num, uint32_t baud_rate, gpio_num_t tx_io_num, gpio_num_t rx_io_num);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* destructor.
|
* destructor.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
~ESPNexUpload() {}
|
~ESPNexUpload(){}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to Nextion over serial
|
* Connect to Nextion over serial
|
||||||
@@ -106,14 +114,7 @@ public: /* methods */
|
|||||||
*
|
*
|
||||||
* @return true if success, false for failure.
|
* @return true if success, false for failure.
|
||||||
*/
|
*/
|
||||||
bool prepareUpload(uint32_t file_size);
|
bool prepareUpload(uint32_t file_size, bool prot);
|
||||||
|
|
||||||
/**
|
|
||||||
* set Update Progress Callback. (What to do during update progress)
|
|
||||||
*
|
|
||||||
* @return none
|
|
||||||
*/
|
|
||||||
void setUpdateProgressCallback(THandlerFunction value);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* start update tft file to nextion.
|
* start update tft file to nextion.
|
||||||
@@ -124,32 +125,29 @@ public: /* methods */
|
|||||||
*/
|
*/
|
||||||
bool upload(const uint8_t *file_buf, size_t buf_size);
|
bool upload(const uint8_t *file_buf, size_t buf_size);
|
||||||
|
|
||||||
/**
|
|
||||||
* start update tft file to nextion.
|
|
||||||
*
|
|
||||||
* @param Stream &myFile
|
|
||||||
* @return true if success, false for failure.
|
|
||||||
*/
|
|
||||||
bool upload(Stream &myFile);
|
bool upload(Stream &myFile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send reset command to Nextion over serial
|
* Send reset command to Nextion over serial
|
||||||
*
|
*
|
||||||
* @return none.
|
* @return none.
|
||||||
*/
|
*/
|
||||||
void softReset(void);
|
void softReset(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send reset, end serial, reset _sent_packets & update status message
|
* Send reset, end serial, reset _sent_packets & update status message
|
||||||
*
|
*
|
||||||
* @return none.
|
* @return none.
|
||||||
*/
|
*/
|
||||||
void end(void);
|
void end(void);
|
||||||
|
|
||||||
public: /* data */
|
|
||||||
String statusMessage = "";
|
|
||||||
|
|
||||||
private: /* methods */
|
private: /* methods */
|
||||||
|
/*
|
||||||
|
* Semaphore construction to prevent double UART actions
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void uart_mutex_lock(void) {do {} while (xSemaphoreTake(_upload_uart_lock, portMAX_DELAY) != pdPASS);};
|
||||||
|
void uart_mutex_unlock(void) {xSemaphoreGive(_upload_uart_lock);};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get communicate baudrate.
|
* get communicate baudrate.
|
||||||
*
|
*
|
||||||
@@ -165,7 +163,7 @@ private: /* methods */
|
|||||||
*
|
*
|
||||||
* @return true if success, false for failure.
|
* @return true if success, false for failure.
|
||||||
*/
|
*/
|
||||||
bool _searchBaudrate(uint32_t baudrate);
|
bool _searchBaudrate(int baudrate);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* set download baudrate.
|
* set download baudrate.
|
||||||
@@ -179,65 +177,58 @@ private: /* methods */
|
|||||||
/*
|
/*
|
||||||
* set Nextion running mode.
|
* set Nextion running mode.
|
||||||
*
|
*
|
||||||
* Undocumented feature of the Nextion protocol.
|
* Undocumented feature of the Nextion protocol.
|
||||||
* It's used by the 'upload to Nextion device' feature of the Nextion Editor V0.58
|
* It's used by the 'upload to Nextion device' feature of the Nextion Editor V0.58
|
||||||
*
|
*
|
||||||
* The nextion display doesn't send any response
|
* The nextion display doesn't send any response
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void _setRunningMode(void);
|
void _setRunningMode(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test UART nextion connection availability
|
* Test UART nextion connection availability
|
||||||
*
|
*
|
||||||
* @param input - echo string,
|
* @param input - echo string,
|
||||||
*
|
*
|
||||||
* @return true when the 'echo string' that is send is equal to the received string
|
* @return true when the 'echo string' that is send is equal to the received string
|
||||||
*
|
*
|
||||||
* This test is used by the 'upload to Nextion device' feature of the Nextion Editor V0.58
|
* This test is used by the 'upload to Nextion device' feature of the Nextion Editor V0.58
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
bool _echoTest(String input);
|
bool _echoTest(std::string input);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function get the sleep and dim value from the Nextion display.
|
* This function get the sleep and dim value from the Nextion display.
|
||||||
*
|
*
|
||||||
* If sleep = 1 meaning: sleep is enabled
|
* If sleep = 1 meaning: sleep is enabled
|
||||||
* action : sleep will be disabled
|
* action : sleep will be disabled
|
||||||
* If dim = 0, meaning: the display backlight is turned off
|
* If dim = 0, meaning: the display backlight is turned off
|
||||||
* action : dim will be set to 100 (percent)
|
* action : dim will be set to 100 (percent)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
bool _handlingSleepAndDim(void);
|
bool _handlingSleepAndDim(void);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function (debug) print the Nextion response to a human readable string
|
* This function (debug) print the Nextion response to a human readable string
|
||||||
*
|
*
|
||||||
* @param esp_request - true: request message from esp to nextion
|
* @param esp_request - true: request message from esp to nextion
|
||||||
* false: response message from nextion to esp
|
* false: response message from nextion to esp
|
||||||
*
|
*
|
||||||
* @param input - string to print
|
* @param input - string to print
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void _printSerialData(bool esp_request, String input);
|
void _printSerialData(bool esp_request, std::string input);
|
||||||
|
|
||||||
/*
|
|
||||||
* This function print a prefix debug line
|
|
||||||
*
|
|
||||||
* @param line: optional debug/ info line
|
|
||||||
*/
|
|
||||||
void _printInfoLine(String line = "");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send command to Nextion.
|
* Send command to Nextion.
|
||||||
*
|
*
|
||||||
* @param cmd - the string of command.
|
* @param cmd - the string of command.
|
||||||
* @param tail - end the string with tripple 0xFF byte
|
* @param tail - end the string with tripple 0xFF byte
|
||||||
* @param null_head - start the string with a single 0x00 byte
|
* @param null_head - start the string with a single 0x00 byte
|
||||||
*
|
*
|
||||||
* @return none.
|
* @return none.
|
||||||
*/
|
*/
|
||||||
void sendCommand(const char *cmd, bool tail = true, bool null_head = false);
|
void sendCommand(const char* cmd, bool tail = true, bool null_head = false);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Receive string data.
|
* Receive string data.
|
||||||
@@ -249,7 +240,7 @@ private: /* methods */
|
|||||||
* @return the length of string buffer.
|
* @return the length of string buffer.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
uint16_t recvRetString(String &string, uint32_t timeout = 500, bool recv_flag = false);
|
uint16_t recvRetString(std::string &string, uint32_t timeout = 500,bool recv_flag = false);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
@@ -261,25 +252,72 @@ private: /* methods */
|
|||||||
* @return time in us length of string buffer.
|
* @return time in us length of string buffer.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
uint32_t calculateTransmissionTimeMs(String message);
|
uint32_t calculateTransmissionTimeMs(std::string message);
|
||||||
|
|
||||||
void nexSerialBegin(uint32_t upload_baudrate, int line, int rx, int tx);
|
/*
|
||||||
|
* Setup UART for communication with display
|
||||||
|
*
|
||||||
|
* @param uart_num - UART number
|
||||||
|
* @param baud_rate - baud rate speed
|
||||||
|
* @param tx_io_num - GPIO TX pin
|
||||||
|
* @param rx_io_num - GPIO RX pin
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void setBaudrate(uart_port_t uart_num, uint32_t baud_rate, gpio_num_t tx_io_num, gpio_num_t rx_io_num);
|
||||||
|
|
||||||
private: /* data */
|
/*
|
||||||
uint32_t _baudrate; /* nextion serail baudrate */
|
* Check is UART is avaialble
|
||||||
uint32_t _undownloadByte; /* undownload byte of tft file */
|
*/
|
||||||
uint32_t _upload_baudrate; /* upload baudrate */
|
uint32_t uartAvailable();
|
||||||
uint16_t _sent_packets = 0; /* upload baudrate */
|
|
||||||
uint8_t _rx;
|
|
||||||
uint8_t _tx;
|
|
||||||
uint8_t _line;
|
|
||||||
THandlerFunction _updateProgressCallback;
|
|
||||||
|
|
||||||
#ifdef ESP8266
|
/*
|
||||||
SoftwareSerial* nexSerial;
|
* Read one RX byte
|
||||||
#else
|
*
|
||||||
Stream* nexSerial;
|
* @return one received UART byte
|
||||||
#endif
|
*/
|
||||||
|
uint8_t uartRead();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write one TX byte
|
||||||
|
*
|
||||||
|
* @param c - one byte
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void uartWrite(uint8_t c);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Write char string
|
||||||
|
*
|
||||||
|
* @param data - char string of data to send
|
||||||
|
* @param len - length of the string
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void uartWriteBuf(const char * data, size_t len);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Clear TX UART buffer
|
||||||
|
*/
|
||||||
|
void uartFlushTxOnly();
|
||||||
|
|
||||||
|
private: /* data */
|
||||||
|
bool protv2;
|
||||||
|
uint32_t _baudrate; /* nextion serail baudrate */
|
||||||
|
uint32_t _undownloadByte; /* undownload byte of tft file */
|
||||||
|
uart_port_t _upload_uart_num; /* upload uart port number */
|
||||||
|
uint32_t _upload_baudrate; /* upload baudrate */
|
||||||
|
gpio_num_t _upload_tx_io_num; /* upload gpio TX */
|
||||||
|
gpio_num_t _upload_rx_io_num; /* upload gpio RX */
|
||||||
|
xSemaphoreHandle _upload_uart_lock; /* semaphore to prevent double UART actions */
|
||||||
|
bool _upload_uart_has_peek; /* UART RX peek flag */
|
||||||
|
uint8_t _upload_uart_peek_byte; /* UART RX peek byte */
|
||||||
|
//uint16_t _sent_packets = 0; /* _sent_packets till 4096 bytes */
|
||||||
|
uint32_t _sent_packets_total = 0; /* total number of uploaded display firmware bytes */
|
||||||
|
bool _uart_diver_installed; /* flag, if true UART is installed */
|
||||||
|
|
||||||
|
std::string str_snprintf(const char *fmt, size_t len, ...);
|
||||||
|
/// Format the byte array \p data of length \p len in pretty-printed, human-readable hex.
|
||||||
|
std::string format_hex_pretty(const uint8_t *data, size_t length);
|
||||||
|
static char format_hex_pretty_char(uint8_t v);
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ private:
|
|||||||
bool _UpTelegram;
|
bool _UpTelegram;
|
||||||
char _inc;
|
char _inc;
|
||||||
String _inStr = ""; // буфер приема строк в режимах 0, 1, 2
|
String _inStr = ""; // буфер приема строк в режимах 0, 1, 2
|
||||||
|
bool _protv2;
|
||||||
|
|
||||||
// Выводим русские буквы на экран Nextion (преобразуем в кодировку ISO-8859-5)
|
// Выводим русские буквы на экран Nextion (преобразуем в кодировку ISO-8859-5)
|
||||||
String convertRUS(String text)
|
String convertRUS(String text)
|
||||||
@@ -65,6 +66,7 @@ public:
|
|||||||
jsonRead(parameters, "speed", _speed);
|
jsonRead(parameters, "speed", _speed);
|
||||||
jsonRead(parameters, "line", _line);
|
jsonRead(parameters, "line", _line);
|
||||||
jsonRead(parameters, "uploadTelegram", _UpTelegram);
|
jsonRead(parameters, "uploadTelegram", _UpTelegram);
|
||||||
|
jsonRead(parameters, "protv2", _protv2);
|
||||||
}
|
}
|
||||||
|
|
||||||
IoTValue execute(String command, std::vector<IoTValue> ¶m)
|
IoTValue execute(String command, std::vector<IoTValue> ¶m)
|
||||||
@@ -213,8 +215,7 @@ public:
|
|||||||
SerialPrint("I", F("NextionUpdate"), "connecting to " + (String)_host);
|
SerialPrint("I", F("NextionUpdate"), "connecting to " + (String)_host);
|
||||||
HTTPClient http;
|
HTTPClient http;
|
||||||
#if defined ESP8266
|
#if defined ESP8266
|
||||||
WiFiClient client;
|
if (!http.begin(_host, 80, _url))
|
||||||
if (!http.begin(client, _host, 80, _url))
|
|
||||||
SerialPrint("I", F("NextionUpdate"), "connection failed ");
|
SerialPrint("I", F("NextionUpdate"), "connection failed ");
|
||||||
#elif defined ESP32
|
#elif defined ESP32
|
||||||
if (!http.begin(String("http://") + _host + _url))
|
if (!http.begin(String("http://") + _host + _url))
|
||||||
@@ -269,29 +270,31 @@ public:
|
|||||||
int contentLength = http.getSize();
|
int contentLength = http.getSize();
|
||||||
SerialPrint("I", F("NextionUpdate"), "File received. Update Nextion... ");
|
SerialPrint("I", F("NextionUpdate"), "File received. Update Nextion... ");
|
||||||
bool result;
|
bool result;
|
||||||
ESPNexUpload nexUp(_speed, _line, _rx, _tx);
|
ESPNexUpload nexUp(_line, _speed, (gpio_num_t)_tx, (gpio_num_t)_rx);
|
||||||
nexUp.setUpdateProgressCallback([]()
|
// nexUp.setUpdateProgressCallback([]()
|
||||||
{ SerialPrint("I", F("NextionUpdate"), "... "); });
|
// { SerialPrint("I", F("NextionUpdate"), "... "); });
|
||||||
|
|
||||||
result = nexUp.prepareUpload(contentLength);
|
result = nexUp.prepareUpload(contentLength, _protv2);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
SerialPrint("I", F("NextionUpdate"), "Error: " + (String)nexUp.statusMessage);
|
SerialPrint("I", F("NextionUpdate"), "Error Connect in prepare upload");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
updated = true;
|
||||||
SerialPrint("I", F("NextionUpdate"), "Start upload. File size is: " + (String)contentLength);
|
SerialPrint("I", F("NextionUpdate"), "Start upload. File size is: " + (String)contentLength);
|
||||||
result = nexUp.upload(*http.getStreamPtr());
|
result = nexUp.upload(*http.getStreamPtr());
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
updated = true;
|
|
||||||
SerialPrint("I", F("NextionUpdate"), "Succesfully updated Nextion! ");
|
SerialPrint("I", F("NextionUpdate"), "Succesfully updated Nextion! ");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SerialPrint("I", F("NextionUpdate"), "Error updating Nextion: " + (String)nexUp.statusMessage);
|
SerialPrint("I", F("NextionUpdate"), "Error updating Nextion" );
|
||||||
}
|
}
|
||||||
nexUp.end();
|
nexUp.end();
|
||||||
|
updated = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//---------------------NEXTION-UPDATE---END------------------------
|
//---------------------NEXTION-UPDATE---END------------------------
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
"rx": 16,
|
"rx": 16,
|
||||||
"line": 2,
|
"line": 2,
|
||||||
"speed": 9600,
|
"speed": 9600,
|
||||||
|
"protv2": 1,
|
||||||
"uploadTelegram": 1
|
"uploadTelegram": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -28,8 +29,8 @@
|
|||||||
"moduleName": "Nextion",
|
"moduleName": "Nextion",
|
||||||
"moduleVersion": "2.0",
|
"moduleVersion": "2.0",
|
||||||
"usedRam": {
|
"usedRam": {
|
||||||
"esp32_4mb": 15,
|
"esp32_4mb": 152,
|
||||||
"esp8266_4mb": 15
|
"esp8266_4mb": 152
|
||||||
},
|
},
|
||||||
"title": "Nextion",
|
"title": "Nextion",
|
||||||
"moduleDesc": "загрузка прошивки в дисплей Nextion. Команда для запуска обновления дисплея: Nextion.Update(); ",
|
"moduleDesc": "загрузка прошивки в дисплей Nextion. Команда для запуска обновления дисплея: Nextion.Update(); ",
|
||||||
@@ -40,6 +41,7 @@
|
|||||||
"line": "Актуально только для ESP32: номер линии hardUART. =2 rx=16 tx=17, для SoftwarwSerial в ESP32 line = -1",
|
"line": "Актуально только для ESP32: номер линии hardUART. =2 rx=16 tx=17, для SoftwarwSerial в ESP32 line = -1",
|
||||||
"host": "Сервер обновления. Можно использовать LiveServer из VisualCode, указывать ip адрес",
|
"host": "Сервер обновления. Можно использовать LiveServer из VisualCode, указывать ip адрес",
|
||||||
"url": "файл прошивки экрана, указывать с расширением, например nextion.tft или iotm/test.tft",
|
"url": "файл прошивки экрана, указывать с расширением, например nextion.tft или iotm/test.tft",
|
||||||
|
"protv2": "1-использует быстрый протоколо прошивки v1.2, 0-использует оффициальный протокол прошивки",
|
||||||
"uploadTelegram": "1 - разрешает прошивать экран через модуль Telegram_v2",
|
"uploadTelegram": "1 - разрешает прошивать экран через модуль Telegram_v2",
|
||||||
"btn-uploadServer": "Кнопка загрузки прошивки с сервера LiveServer или другого по ip"
|
"btn-uploadServer": "Кнопка загрузки прошивки с сервера LiveServer или другого по ip"
|
||||||
},
|
},
|
||||||
@@ -87,7 +89,12 @@
|
|||||||
},
|
},
|
||||||
"defActive": false,
|
"defActive": false,
|
||||||
"usedLibs": {
|
"usedLibs": {
|
||||||
"esp32*": [],
|
"esp32_4mb": [],
|
||||||
"esp82*": []
|
"esp32_4mb3f": [],
|
||||||
|
"esp8266_4mb": [],
|
||||||
|
"esp8266_1mb": [],
|
||||||
|
"esp8266_1mb_ota": [],
|
||||||
|
"esp8285_1mb": [],
|
||||||
|
"esp8285_1mb_ota": []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -125,6 +125,8 @@ namespace _Broker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _debug;
|
||||||
|
|
||||||
class BrokerMQTT : public IoTItem
|
class BrokerMQTT : public IoTItem
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@@ -132,7 +134,7 @@ namespace _Broker
|
|||||||
int _port = 0;
|
int _port = 0;
|
||||||
String _user;
|
String _user;
|
||||||
String _pass;
|
String _pass;
|
||||||
bool _debug;
|
//bool _debug;
|
||||||
bool _brige;
|
bool _brige;
|
||||||
String _server;
|
String _server;
|
||||||
String _srvUser;
|
String _srvUser;
|
||||||
@@ -152,19 +154,6 @@ namespace _Broker
|
|||||||
jsonRead(parameters, "srvUser", _srvUser);
|
jsonRead(parameters, "srvUser", _srvUser);
|
||||||
jsonRead(parameters, "srvPass", _srvPass);
|
jsonRead(parameters, "srvPass", _srvPass);
|
||||||
jsonRead(parameters, "srvPort", _srvPort);
|
jsonRead(parameters, "srvPort", _srvPort);
|
||||||
|
|
||||||
if (_brige)
|
|
||||||
{
|
|
||||||
clientMqtt = new PicoMQTT::Client(_server.c_str(), _srvPort, nullptr, _srvUser.c_str(), _srvPass.c_str());
|
|
||||||
if (_debug)
|
|
||||||
{
|
|
||||||
SerialPrint("i", F("BrigeMQTT"), "Bridge mode : ON");
|
|
||||||
SerialPrint("i", F("BrigeMQTT"), "Bridge server: " + _server);
|
|
||||||
SerialPrint("i", F("BrigeMQTT"), "Bridge port: " + String(_srvPort));
|
|
||||||
SerialPrint("i", F("BrigeMQTT"), "Bridge user: " + _srvUser);
|
|
||||||
SerialPrint("i", F("BrigeMQTT"), "Bridge pass: " + _srvPass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void doByInterval()
|
void doByInterval()
|
||||||
@@ -178,11 +167,30 @@ namespace _Broker
|
|||||||
picoMqtt->begin();
|
picoMqtt->begin();
|
||||||
picoMqtt->setDebug(_debug);
|
picoMqtt->setDebug(_debug);
|
||||||
picoMqtt->setAuth(_user, _pass);
|
picoMqtt->setAuth(_user, _pass);
|
||||||
|
if (_brige)
|
||||||
|
{
|
||||||
|
clientMqtt = new PicoMQTT::Client(_server.c_str(), _srvPort, chipId.c_str(), _srvUser.c_str(), _srvPass.c_str());
|
||||||
|
clientMqtt->begin();
|
||||||
|
if (_debug)
|
||||||
|
{
|
||||||
|
SerialPrint("i", F("BrigeMQTT"), "Bridge mode : ON");
|
||||||
|
SerialPrint("i", F("BrigeMQTT"), "Bridge server: " + _server);
|
||||||
|
SerialPrint("i", F("BrigeMQTT"), "Bridge port: " + String(_srvPort));
|
||||||
|
SerialPrint("i", F("BrigeMQTT"), "Bridge user: " + _srvUser);
|
||||||
|
SerialPrint("i", F("BrigeMQTT"), "Bridge pass: " + _srvPass);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (_brige && picoMqtt && clientMqtt)
|
if (_brige && picoMqtt && clientMqtt)
|
||||||
{
|
{
|
||||||
picoMqtt->subscribe("#", [](const char *topic, const char *message)
|
picoMqtt->subscribe("#", [](const char *topic, const char *message)
|
||||||
{ clientMqtt->publish(topic, message);
|
{ clientMqtt->publish(topic, message);
|
||||||
SerialPrint("i", F("BrigeMQTT"), "client publish, topic: " + String(topic) + " msg: " + String(message) ); });
|
if (_debug)
|
||||||
|
SerialPrint("i", F("BrigeMQTT"), "Client publish, topic: " + String(topic) + " msg: " + String(message) ); });
|
||||||
|
|
||||||
|
clientMqtt->subscribe("#", [](const char *topic, const char *message)
|
||||||
|
{ picoMqtt->publish(topic, message);
|
||||||
|
if (_debug)
|
||||||
|
SerialPrint("i", F("BrigeMQTT"), "Server publish, topic: " + String(topic) + " msg: " + String(message) ); });
|
||||||
}
|
}
|
||||||
// picoMqtt.begin();
|
// picoMqtt.begin();
|
||||||
xTaskCreatePinnedToCore(
|
xTaskCreatePinnedToCore(
|
||||||
|
|||||||
@@ -686,7 +686,7 @@ public:
|
|||||||
{
|
{
|
||||||
_myBot->sendMessage("ID: " + chipId, _chatID);
|
_myBot->sendMessage("ID: " + chipId, _chatID);
|
||||||
_myBot->sendMessage("chatID: " + _chatID, _chatID);
|
_myBot->sendMessage("chatID: " + _chatID, _chatID);
|
||||||
_myBot->sendMessage("Command: /help - this text \n /all - inline menu get all values \n /allMenu - bottom menu get all values \n /menu - bottom USER menu from scenario \n /get_id - get value by ID \n /set_id_value - set value in ID \n /file_name_type - take file from esp \n /file_type - support file type \n /reboot - reboot esp \n\n send file and write download - \"download\" file to esp \n\n send *.tft file - flash Nextion \n\n send firmware.bin or littltfs.bin - firmware ESP ", _chatID);
|
_myBot->sendMessage("Command: /help - this text \n /all - inline menu get all values \n /allMenu - bottom menu get all values \n /menu - bottom USER menu from scenario \n /get_id - get value by ID \n /set_id_value - set value in ID \n /file_/path/name_type - take file from esp \n /file_type - support file type \n /reboot - reboot esp \n\n send file and write download - \"download\" file to esp \n\n send *.tft file - flash Nextion \n\n send firmware.bin or littltfs.bin - firmware ESP ", _chatID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (msg.text.indexOf("/reboot") != -1)
|
else if (msg.text.indexOf("/reboot") != -1)
|
||||||
|
|||||||
Reference in New Issue
Block a user