mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-08 00:39:50 +03:00
1.5.6
This commit is contained in:
@@ -106,14 +106,14 @@ void TelnetSpy::setPort(uint16_t portToUse) {
|
||||
}
|
||||
}
|
||||
|
||||
void TelnetSpy::setWelcomeMsg(char * msg) {
|
||||
void TelnetSpy::setWelcomeMsg(const char * msg) {
|
||||
if (welcomeMsg) {
|
||||
free(welcomeMsg);
|
||||
}
|
||||
welcomeMsg = strdup(msg);
|
||||
}
|
||||
|
||||
void TelnetSpy::setRejectMsg(char * msg) {
|
||||
void TelnetSpy::setRejectMsg(const char * msg) {
|
||||
if (rejectMsg) {
|
||||
free(rejectMsg);
|
||||
}
|
||||
@@ -434,22 +434,24 @@ TelnetSpy::operator bool() const {
|
||||
|
||||
void TelnetSpy::setDebugOutput(bool en) {
|
||||
debugOutput = en;
|
||||
|
||||
// TODO: figure out how to disable system printing for the ESP32
|
||||
if (debugOutput) {
|
||||
actualObject = this;
|
||||
|
||||
#ifdef ESP8266
|
||||
os_install_putc1((void *)TelnetSpy_putc); // Set system printing (os_printf) to TelnetSpy
|
||||
system_set_os_print(true);
|
||||
#else // ESP32 \
|
||||
// ToDo: How can be done this for ESP32 ?
|
||||
#endif
|
||||
|
||||
} else {
|
||||
if (actualObject == this) {
|
||||
|
||||
#ifdef ESP8266
|
||||
system_set_os_print(false);
|
||||
os_install_putc1((void *)TelnetSpy_ignore_putc); // Ignore system printing
|
||||
#else // ESP32 \
|
||||
// ToDo: How can be done this for ESP32 ?
|
||||
#endif
|
||||
|
||||
actualObject = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,8 +174,8 @@ class TelnetSpy : public Stream {
|
||||
~TelnetSpy();
|
||||
void handle(void);
|
||||
void setPort(uint16_t portToUse);
|
||||
void setWelcomeMsg(char * msg);
|
||||
void setRejectMsg(char * msg);
|
||||
void setWelcomeMsg(const char * msg);
|
||||
void setRejectMsg(const char * msg);
|
||||
void setMinBlockSize(uint16_t minSize);
|
||||
void setCollectingTime(uint16_t colTime);
|
||||
void setMaxBlockSize(uint16_t maxSize);
|
||||
|
||||
@@ -33,7 +33,6 @@ MyESP::MyESP() {
|
||||
|
||||
_helpProjectCmds = NULL;
|
||||
_helpProjectCmds_count = 0;
|
||||
_command = (char *)malloc(TELNET_MAX_COMMAND_LENGTH); // reserve buffer for Serial/Telnet commands
|
||||
|
||||
_use_serial = false;
|
||||
_mqtt_host = NULL;
|
||||
@@ -65,7 +64,6 @@ MyESP::~MyESP() {
|
||||
|
||||
// end
|
||||
void MyESP::end() {
|
||||
free(_command);
|
||||
SerialAndTelnet.end();
|
||||
jw.disconnect();
|
||||
}
|
||||
@@ -266,7 +264,8 @@ void MyESP::_mqtt_setup() {
|
||||
mqttClient.onDisconnect([this](AsyncMqttClientDisconnectReason reason) {
|
||||
if (reason == AsyncMqttClientDisconnectReason::TCP_DISCONNECTED) {
|
||||
myDebug_P(PSTR("[MQTT] TCP Disconnected. Check mqtt logs."));
|
||||
(_mqtt_callback)(MQTT_DISCONNECT_EVENT, NULL, NULL); // call callback with disconnect
|
||||
(_mqtt_callback)(MQTT_DISCONNECT_EVENT, NULL,
|
||||
NULL); // call callback with disconnect
|
||||
}
|
||||
if (reason == AsyncMqttClientDisconnectReason::MQTT_IDENTIFIER_REJECTED) {
|
||||
myDebug_P(PSTR("[MQTT] Identifier Rejected"));
|
||||
@@ -391,7 +390,7 @@ void MyESP::_telnetDisconnected() {
|
||||
|
||||
// Initialize the telnet server
|
||||
void MyESP::_telnet_setup() {
|
||||
SerialAndTelnet.setWelcomeMsg((char *)"");
|
||||
SerialAndTelnet.setWelcomeMsg("");
|
||||
SerialAndTelnet.setCallbackOnConnect([this]() { _telnetConnected(); });
|
||||
SerialAndTelnet.setCallbackOnDisconnect([this]() { _telnetDisconnected(); });
|
||||
SerialAndTelnet.setDebugOutput(false);
|
||||
@@ -738,9 +737,7 @@ void MyESP::_telnetHandle() {
|
||||
while (SerialAndTelnet.available()) {
|
||||
char c = SerialAndTelnet.read();
|
||||
|
||||
if (_use_serial) {
|
||||
SerialAndTelnet.serialPrint(c); // echo to Serial if connected
|
||||
}
|
||||
SerialAndTelnet.serialPrint(c); // echo to Serial if connected
|
||||
|
||||
switch (c) {
|
||||
case '\r': // likely have full command in buffer now, commands are terminated by CR and/or LF
|
||||
@@ -750,17 +747,24 @@ void MyESP::_telnetHandle() {
|
||||
charsRead = 0; // is static, so have to reset
|
||||
_suspendOutput = false;
|
||||
if (_use_serial) {
|
||||
SerialAndTelnet.println(); // force newline if in Telnet
|
||||
SerialAndTelnet.serialPrint('\n'); // force newline if in Serial
|
||||
}
|
||||
_telnetCommand(_command);
|
||||
}
|
||||
break;
|
||||
case '\b': // handle backspace in input: put a space in last char
|
||||
|
||||
case '\b': // (^H) handle backspace in input: put a space in last char - coded by Simon Arlott
|
||||
case 0x7F: // (^?)
|
||||
|
||||
if (charsRead > 0) {
|
||||
_command[--charsRead] = '\0';
|
||||
SerialAndTelnet << byte('\b') << byte(' ') << byte('\b');
|
||||
|
||||
SerialAndTelnet.write(' ');
|
||||
SerialAndTelnet.write('\b');
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case '?':
|
||||
if (!_suspendOutput) {
|
||||
_consoleShowHelp();
|
||||
@@ -814,7 +818,8 @@ void MyESP::_mqttConnect() {
|
||||
// last will
|
||||
if (_mqtt_will_topic) {
|
||||
//myDebug_P(PSTR("[MQTT] Setting last will topic %s"), _mqttTopic(_mqtt_will_topic));
|
||||
mqttClient.setWill(_mqttTopic(_mqtt_will_topic), 1, true, _mqtt_will_offline_payload); // retain always true
|
||||
mqttClient.setWill(_mqttTopic(_mqtt_will_topic), 1, true,
|
||||
_mqtt_will_offline_payload); // retain always true
|
||||
}
|
||||
|
||||
if (_mqtt_username && _mqtt_password) {
|
||||
@@ -955,7 +960,8 @@ void MyESP::_fs_printConfig() {
|
||||
|
||||
// format File System
|
||||
void MyESP::_fs_eraseConfig() {
|
||||
myDebug_P(PSTR("[FS] Erasing settings, please wait a few seconds. ESP will automatically restart when finished."));
|
||||
myDebug_P(PSTR("[FS] Erasing settings, please wait a few seconds. ESP will "
|
||||
"automatically restart when finished."));
|
||||
|
||||
if (SPIFFS.format()) {
|
||||
delay(1000); // wait 1 seconds
|
||||
@@ -1037,6 +1043,12 @@ bool MyESP::fs_saveConfig() {
|
||||
// callback for saving custom settings
|
||||
(void)(_fs_callback)(MYESP_FSACTION_SAVE, json);
|
||||
|
||||
// if file exists, remove it just to be safe
|
||||
if (SPIFFS.exists(MYEMS_CONFIG_FILE)) {
|
||||
// delete it
|
||||
SPIFFS.remove(MYEMS_CONFIG_FILE);
|
||||
}
|
||||
|
||||
File configFile = SPIFFS.open(MYEMS_CONFIG_FILE, "w");
|
||||
if (!configFile) {
|
||||
Serial.println("[FS] Failed to open config file for writing");
|
||||
@@ -1069,7 +1081,7 @@ void MyESP::_fs_setup() {
|
||||
fs_saveConfig();
|
||||
}
|
||||
|
||||
// _fs_printConfig(); // TODO: for debugging
|
||||
//_fs_printConfig(); // TODO: for debugging
|
||||
}
|
||||
|
||||
uint16_t MyESP::getSystemLoadAverage() {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#ifndef MyEMS_h
|
||||
#define MyEMS_h
|
||||
|
||||
#define MYESP_VERSION "1.1.4"
|
||||
#define MYESP_VERSION "1.1.5"
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <ArduinoOTA.h>
|
||||
@@ -68,7 +68,7 @@
|
||||
#define COLOR_CYAN "\x1B[0;36m"
|
||||
#define COLOR_WHITE "\x1B[0;37m"
|
||||
#define COLOR_BOLD_ON "\x1B[1m"
|
||||
#define COLOR_BOLD_OFF "\x1B[21m"
|
||||
#define COLOR_BOLD_OFF "\x1B[22m" // fixed by Scott Arlott
|
||||
|
||||
// SPIFFS
|
||||
#define SPIFFS_MAXSIZE 500 // https://arduinojson.org/v5/assistant/
|
||||
@@ -191,9 +191,9 @@ class MyESP {
|
||||
void _telnetCommand(char * commandLine);
|
||||
char * _telnet_readWord();
|
||||
void _telnet_setup();
|
||||
char * _command; // the input command from either Serial or Telnet
|
||||
command_t * _helpProjectCmds; // Help of commands setted by project
|
||||
uint8_t _helpProjectCmds_count; // # available commands
|
||||
char _command[TELNET_MAX_COMMAND_LENGTH]; // the input command from either Serial or Telnet
|
||||
command_t * _helpProjectCmds; // Help of commands setted by project
|
||||
uint8_t _helpProjectCmds_count; // # available commands
|
||||
void _consoleShowHelp();
|
||||
telnetcommand_callback_f _telnetcommand_callback; // Callable for projects commands
|
||||
telnet_callback_f _telnet_callback; // callback for connect/disconnect
|
||||
|
||||
Reference in New Issue
Block a user