mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
move buffers off heap
This commit is contained in:
@@ -27,6 +27,8 @@ union system_rtcmem_t {
|
|||||||
static char * _general_password = nullptr;
|
static char * _general_password = nullptr;
|
||||||
static bool _shouldRestart = false;
|
static bool _shouldRestart = false;
|
||||||
|
|
||||||
|
static char _debug_buffer[TELNET_MAX_BUFFER_LENGTH];
|
||||||
|
|
||||||
uint8_t RtcmemSize = (sizeof(RtcmemData) / 4u);
|
uint8_t RtcmemSize = (sizeof(RtcmemData) / 4u);
|
||||||
auto Rtcmem = reinterpret_cast<volatile RtcmemData *>(RTCMEM_ADDR);
|
auto Rtcmem = reinterpret_cast<volatile RtcmemData *>(RTCMEM_ADDR);
|
||||||
|
|
||||||
@@ -142,14 +144,14 @@ void MyESP::myDebug(const char * format, ...) {
|
|||||||
char test[1];
|
char test[1];
|
||||||
|
|
||||||
int len = ets_vsnprintf(test, 1, format, args) + 1;
|
int len = ets_vsnprintf(test, 1, format, args) + 1;
|
||||||
|
if (len > TELNET_MAX_BUFFER_LENGTH - 1) {
|
||||||
|
len = TELNET_MAX_BUFFER_LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
char * buffer = new char[len];
|
ets_vsnprintf(_debug_buffer, len, format, args);
|
||||||
ets_vsnprintf(buffer, len, format, args);
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
SerialAndTelnet.println(buffer);
|
SerialAndTelnet.println(_debug_buffer);
|
||||||
|
|
||||||
delete[] buffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for flashmemory. Must use PSTR()
|
// for flashmemory. Must use PSTR()
|
||||||
@@ -164,9 +166,11 @@ void MyESP::myDebug_P(PGM_P format_P, ...) {
|
|||||||
va_start(args, format_P);
|
va_start(args, format_P);
|
||||||
char test[1];
|
char test[1];
|
||||||
int len = ets_vsnprintf(test, 1, format, args) + 1;
|
int len = ets_vsnprintf(test, 1, format, args) + 1;
|
||||||
|
if (len > TELNET_MAX_BUFFER_LENGTH - 1) {
|
||||||
|
len = TELNET_MAX_BUFFER_LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
char * buffer = new char[len];
|
ets_vsnprintf(_debug_buffer, len, format, args);
|
||||||
ets_vsnprintf(buffer, len, format, args);
|
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
@@ -177,9 +181,7 @@ void MyESP::myDebug_P(PGM_P format_P, ...) {
|
|||||||
SerialAndTelnet.print(timestamp);
|
SerialAndTelnet.print(timestamp);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SerialAndTelnet.println(buffer);
|
SerialAndTelnet.println(_debug_buffer);
|
||||||
|
|
||||||
delete[] buffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// use Serial?
|
// use Serial?
|
||||||
@@ -450,7 +452,7 @@ void MyESP::_mqttOnConnect() {
|
|||||||
mqttPublish(MQTT_TOPIC_START, MQTT_TOPIC_START_PAYLOAD, false);
|
mqttPublish(MQTT_TOPIC_START, MQTT_TOPIC_START_PAYLOAD, false);
|
||||||
|
|
||||||
// send heartbeat if enabled
|
// send heartbeat if enabled
|
||||||
_heartbeatCheck(true);
|
_heartbeatCheck();
|
||||||
|
|
||||||
// call custom function to handle mqtt receives
|
// call custom function to handle mqtt receives
|
||||||
(_mqtt_callback_f)(MQTT_CONNECT_EVENT, nullptr, nullptr);
|
(_mqtt_callback_f)(MQTT_CONNECT_EVENT, nullptr, nullptr);
|
||||||
@@ -684,13 +686,13 @@ void MyESP::_kick() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// kick web
|
// kick web
|
||||||
myDebug_P(PSTR(" - Restart web server and web sockets"));
|
myDebug_P(PSTR(" - Restarting web server and web sockets"));
|
||||||
_ws->enable(false);
|
_ws->enable(false);
|
||||||
//_webServer->reset();
|
//_webServer->reset();
|
||||||
_ws->enable(true);
|
_ws->enable(true);
|
||||||
|
|
||||||
// kick mqtt
|
// kick mqtt
|
||||||
myDebug_P(PSTR(" - Restart MQTT"));
|
myDebug_P(PSTR(" - Restarting MQTT"));
|
||||||
mqttClient.disconnect();
|
mqttClient.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -848,8 +850,8 @@ void MyESP::_printSetCommands() {
|
|||||||
// reset / restart
|
// reset / restart
|
||||||
void MyESP::resetESP() {
|
void MyESP::resetESP() {
|
||||||
myDebug_P(PSTR("* Restart ESP..."));
|
myDebug_P(PSTR("* Restart ESP..."));
|
||||||
_deferredReset(500, CUSTOM_RESET_TERMINAL);
|
|
||||||
end();
|
end();
|
||||||
|
_deferredReset(500, CUSTOM_RESET_TERMINAL);
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
#else
|
#else
|
||||||
@@ -1440,16 +1442,7 @@ void MyESP::showSystemStats() {
|
|||||||
myDebug_P(PSTR(" [MEM] Firmware size: %d"), ESP.getSketchSize());
|
myDebug_P(PSTR(" [MEM] Firmware size: %d"), ESP.getSketchSize());
|
||||||
myDebug_P(PSTR(" [MEM] Max OTA size: %d"), (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000);
|
myDebug_P(PSTR(" [MEM] Max OTA size: %d"), (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000);
|
||||||
myDebug_P(PSTR(" [MEM] OTA Reserved: %d"), 4 * SPI_FLASH_SEC_SIZE);
|
myDebug_P(PSTR(" [MEM] OTA Reserved: %d"), 4 * SPI_FLASH_SEC_SIZE);
|
||||||
|
_printHeap(" [MEM]");
|
||||||
uint32_t total_memory = _getInitialFreeHeap();
|
|
||||||
uint32_t free_memory = ESP.getFreeHeap();
|
|
||||||
|
|
||||||
myDebug(" [MEM] Free Heap: %d bytes initially | %d bytes used (%2u%%) | %d bytes free (%2u%%)",
|
|
||||||
total_memory,
|
|
||||||
total_memory - free_memory,
|
|
||||||
100 * (total_memory - free_memory) / total_memory,
|
|
||||||
free_memory,
|
|
||||||
100 * free_memory / total_memory);
|
|
||||||
|
|
||||||
myDebug_P(PSTR(""));
|
myDebug_P(PSTR(""));
|
||||||
}
|
}
|
||||||
@@ -1457,14 +1450,19 @@ void MyESP::showSystemStats() {
|
|||||||
/*
|
/*
|
||||||
* Send heartbeat via MQTT with all system data
|
* Send heartbeat via MQTT with all system data
|
||||||
*/
|
*/
|
||||||
void MyESP::_heartbeatCheck(bool force = false) {
|
void MyESP::_heartbeatCheck(bool force) {
|
||||||
static uint32_t last_heartbeat = 0;
|
static uint32_t last_heartbeat = 0;
|
||||||
|
|
||||||
if ((millis() - last_heartbeat > MYESP_HEARTBEAT_INTERVAL) || force) {
|
if ((millis() - last_heartbeat > MYESP_HEARTBEAT_INTERVAL) || force) {
|
||||||
last_heartbeat = millis();
|
last_heartbeat = millis();
|
||||||
|
|
||||||
|
// print to log if force is set, so at bootup
|
||||||
|
if (force) {
|
||||||
|
_printHeap("[SYSTEM]");
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef MYESP_DEBUG
|
#ifdef MYESP_DEBUG
|
||||||
_printHeap("HEARTBEAT");
|
_printHeap("[HEARTBEAT] ");
|
||||||
#endif
|
#endif
|
||||||
if (!isMQTTConnected() || !(_mqtt_heartbeat)) {
|
if (!isMQTTConnected() || !(_mqtt_heartbeat)) {
|
||||||
return;
|
return;
|
||||||
@@ -2666,12 +2664,12 @@ void MyESP::_webserver_setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// print memory
|
// print memory
|
||||||
void MyESP::_printHeap(const char * s) {
|
void MyESP::_printHeap(const char * prefix) {
|
||||||
uint32_t total_memory = _getInitialFreeHeap();
|
uint32_t total_memory = _getInitialFreeHeap();
|
||||||
uint32_t free_memory = ESP.getFreeHeap();
|
uint32_t free_memory = ESP.getFreeHeap();
|
||||||
|
|
||||||
myDebug(" [%s] Free Heap: %d bytes initially | %d bytes used (%2u%%) | %d bytes free (%2u%%)",
|
myDebug("%s Free Heap: %d bytes initially | %d bytes used (%2u%%) | %d bytes free (%2u%%)",
|
||||||
s,
|
prefix,
|
||||||
total_memory,
|
total_memory,
|
||||||
total_memory - free_memory,
|
total_memory - free_memory,
|
||||||
100 * (total_memory - free_memory) / total_memory,
|
100 * (total_memory - free_memory) / total_memory,
|
||||||
@@ -2831,7 +2829,7 @@ void MyESP::_syslog_setup() {
|
|||||||
syslog.mark_interval(3600);
|
syslog.mark_interval(3600);
|
||||||
|
|
||||||
IPAddress syslog_ip;
|
IPAddress syslog_ip;
|
||||||
syslog_ip.fromString("192.168.1.4");
|
syslog_ip.fromString(_general_log_ip);
|
||||||
syslog.destination(syslog_ip);
|
syslog.destination(syslog_ip);
|
||||||
|
|
||||||
logger.info(F("Application started"));
|
logger.info(F("Application started"));
|
||||||
@@ -2874,7 +2872,7 @@ void MyESP::begin(const char * app_hostname, const char * app_name, const char *
|
|||||||
_webserver_setup(); // init web server
|
_webserver_setup(); // init web server
|
||||||
|
|
||||||
_setSystemCheck(false); // reset system check
|
_setSystemCheck(false); // reset system check
|
||||||
_heartbeatCheck(true); // force heartbeat
|
_heartbeatCheck(true); // force heartbeat, will send out message to log too
|
||||||
|
|
||||||
_setSystemDropoutCounter(0); // reset # TCP dropouts
|
_setSystemDropoutCounter(0); // reset # TCP dropouts
|
||||||
|
|
||||||
@@ -2925,7 +2923,7 @@ void MyESP::loop() {
|
|||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(MYESP_DELAY); // some time to WiFi and everything else to catch up, and prevent overheating
|
delay(MYESP_DELAY); // some time to WiFi and everything else to catch up, calls yield, and also prevent overheating
|
||||||
}
|
}
|
||||||
|
|
||||||
MyESP myESP;
|
MyESP myESP;
|
||||||
|
|||||||
17
src/MyESP.h
17
src/MyESP.h
@@ -9,7 +9,7 @@
|
|||||||
#ifndef MyESP_h
|
#ifndef MyESP_h
|
||||||
#define MyESP_h
|
#define MyESP_h
|
||||||
|
|
||||||
#define MYESP_VERSION "1.2.21"
|
#define MYESP_VERSION "1.2.22"
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
@@ -113,6 +113,7 @@ extern struct rst_info resetInfo;
|
|||||||
// Telnet
|
// Telnet
|
||||||
#define TELNET_SERIAL_BAUD 115200
|
#define TELNET_SERIAL_BAUD 115200
|
||||||
#define TELNET_MAX_COMMAND_LENGTH 80 // length of a command
|
#define TELNET_MAX_COMMAND_LENGTH 80 // length of a command
|
||||||
|
#define TELNET_MAX_BUFFER_LENGTH 300 // max length of telnet string
|
||||||
#define TELNET_EVENT_CONNECT 1
|
#define TELNET_EVENT_CONNECT 1
|
||||||
#define TELNET_EVENT_DISCONNECT 0
|
#define TELNET_EVENT_DISCONNECT 0
|
||||||
#define TELNET_EVENT_SHOWCMD 10
|
#define TELNET_EVENT_SHOWCMD 10
|
||||||
@@ -252,12 +253,9 @@ constexpr size_t ArraySize(T (&)[N]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define MYESP_UPTIME_OVERFLOW 4294967295 // Uptime overflow value
|
#define MYESP_UPTIME_OVERFLOW 4294967295 // Uptime overflow value
|
||||||
|
#define MYESP_MAX_STR_LEN 16 // web min and max length of wifi ssid and password
|
||||||
// web min and max length of wifi ssid and password
|
#define MYESP_BOOTUP_FLASHDELAY 50 // flash duration for LED at bootup sequence
|
||||||
#define MYESP_MAX_STR_LEN 16
|
#define MYESP_BOOTUP_DELAY 2000 // time before we open the window to reset. This is to stop resetting values when uploading firmware via USB
|
||||||
|
|
||||||
#define MYESP_BOOTUP_FLASHDELAY 50 // flash duration for LED at bootup sequence
|
|
||||||
#define MYESP_BOOTUP_DELAY 2000 // time before we open the window to reset. This is to stop resetting values when uploading firmware via USB
|
|
||||||
|
|
||||||
// class definition
|
// class definition
|
||||||
class MyESP {
|
class MyESP {
|
||||||
@@ -480,7 +478,7 @@ class MyESP {
|
|||||||
uint32_t _getUsedHeap();
|
uint32_t _getUsedHeap();
|
||||||
|
|
||||||
// heartbeat
|
// heartbeat
|
||||||
void _heartbeatCheck(bool force);
|
void _heartbeatCheck(bool force = false);
|
||||||
|
|
||||||
// web
|
// web
|
||||||
web_callback_f _web_callback_f;
|
web_callback_f _web_callback_f;
|
||||||
@@ -494,9 +492,6 @@ class MyESP {
|
|||||||
void _printScanResult(int networksFound);
|
void _printScanResult(int networksFound);
|
||||||
void _sendTime();
|
void _sendTime();
|
||||||
void _webserver_setup();
|
void _webserver_setup();
|
||||||
void _webRootPage();
|
|
||||||
void _webResetPage();
|
|
||||||
void _webResetAllPage();
|
|
||||||
|
|
||||||
// ntp
|
// ntp
|
||||||
char * _ntp_server;
|
char * _ntp_server;
|
||||||
|
|||||||
@@ -151,7 +151,7 @@
|
|||||||
#ifndef TelnetSpy_h
|
#ifndef TelnetSpy_h
|
||||||
#define TelnetSpy_h
|
#define TelnetSpy_h
|
||||||
|
|
||||||
#define TELNETSPY_BUFFER_LEN 3000
|
#define TELNETSPY_BUFFER_LEN 1000 // was 3000
|
||||||
#define TELNETSPY_MIN_BLOCK_SIZE 64
|
#define TELNETSPY_MIN_BLOCK_SIZE 64
|
||||||
#define TELNETSPY_COLLECTING_TIME 100
|
#define TELNETSPY_COLLECTING_TIME 100
|
||||||
#define TELNETSPY_MAX_BLOCK_SIZE 512
|
#define TELNETSPY_MAX_BLOCK_SIZE 512
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#define EMSUART_CONFIG 0x1C // 8N1 (8 bits, no stop bits, 1 parity)
|
#define EMSUART_CONFIG 0x1C // 8N1 (8 bits, no stop bits, 1 parity)
|
||||||
#define EMSUART_BAUD 9600 // uart baud rate for the EMS circuit
|
#define EMSUART_BAUD 9600 // uart baud rate for the EMS circuit
|
||||||
|
|
||||||
#define EMS_MAXBUFFERS 5 // buffers for circular filling to avoid collisions
|
#define EMS_MAXBUFFERS 3 // buffers for circular filling to avoid collisions
|
||||||
#define EMS_MAXBUFFERSIZE (EMS_MAX_TELEGRAM_LENGTH + 2) // max size of the buffer. EMS packets are max 32 bytes, plus extra 2 for BRKs
|
#define EMS_MAXBUFFERSIZE (EMS_MAX_TELEGRAM_LENGTH + 2) // max size of the buffer. EMS packets are max 32 bytes, plus extra 2 for BRKs
|
||||||
|
|
||||||
#define EMSUART_BIT_TIME 104 // bit time @9600 baud
|
#define EMSUART_BIT_TIME 104 // bit time @9600 baud
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
#define APP_VERSION "1.9.4b16"
|
#define APP_VERSION "1.9.4b17"
|
||||||
|
|||||||
Reference in New Issue
Block a user