mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-01-29 18:19:09 +03:00
1.1.7
This commit is contained in:
@@ -343,11 +343,10 @@ void TelnetSpy::flush(void) {
|
|||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
|
|
||||||
void TelnetSpy::begin(unsigned long baud, SerialConfig config, SerialMode mode, uint8_t tx_pin) {
|
void TelnetSpy::begin(unsigned long baud, SerialConfig config, SerialMode mode, uint8_t tx_pin) {
|
||||||
|
|
||||||
if (usedSer) {
|
if (usedSer) {
|
||||||
usedSer->begin(baud, config, mode, tx_pin);
|
usedSer->begin(baud, config, mode, tx_pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
started = true;
|
started = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -435,10 +434,8 @@ TelnetSpy::operator bool() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TelnetSpy::setDebugOutput(bool en) {
|
void TelnetSpy::setDebugOutput(bool en) {
|
||||||
|
|
||||||
debugOutput = en;
|
debugOutput = en;
|
||||||
|
|
||||||
// TODO: figure out how to disable system printing for the ESP32
|
|
||||||
if (debugOutput) {
|
if (debugOutput) {
|
||||||
actualObject = this;
|
actualObject = this;
|
||||||
|
|
||||||
@@ -449,7 +446,6 @@ void TelnetSpy::setDebugOutput(bool en) {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (actualObject == this) {
|
if (actualObject == this) {
|
||||||
|
|
||||||
#ifdef ESP8266
|
#ifdef ESP8266
|
||||||
system_set_os_print(false);
|
system_set_os_print(false);
|
||||||
os_install_putc1((void *)TelnetSpy_ignore_putc); // Ignore system printing
|
os_install_putc1((void *)TelnetSpy_ignore_putc); // Ignore system printing
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -9,27 +9,32 @@
|
|||||||
#ifndef MyEMS_h
|
#ifndef MyEMS_h
|
||||||
#define MyEMS_h
|
#define MyEMS_h
|
||||||
|
|
||||||
#define MYESP_VERSION "1.1.5"
|
#define MYESP_VERSION "1.1.7"
|
||||||
|
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
#include <AsyncMqttClient.h> // https://github.com/marvinroger/async-mqtt-client and for ESP32 see https://github.com/marvinroger/async-mqtt-client/issues/127
|
#include <AsyncMqttClient.h> // https://github.com/marvinroger/async-mqtt-client and for ESP32 see https://github.com/marvinroger/async-mqtt-client/issues/127
|
||||||
#include <DNSServer.h>
|
#include <DNSServer.h>
|
||||||
|
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
#include <JustWifi.h> // https://github.com/xoseperez/justwifi
|
#include <JustWifi.h> // https://github.com/xoseperez/justwifi
|
||||||
#include <TelnetSpy.h> // modified from https://github.com/yasheena/telnetspy
|
#include <TelnetSpy.h> // modified from https://github.com/yasheena/telnetspy
|
||||||
|
|
||||||
|
#ifdef CRASH
|
||||||
|
#include <EEPROM_Rotate.h>
|
||||||
|
extern "C" {
|
||||||
|
void custom_crash_callback(struct rst_info *, uint32_t, uint32_t);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
#include <ESPmDNS.h>
|
//#include <ESPmDNS.h>
|
||||||
#include <SPIFFS.h> // added for ESP32
|
#include <SPIFFS.h> // added for ESP32
|
||||||
#define ets_vsnprintf vsnprintf // added for ESP32
|
#define ets_vsnprintf vsnprintf // added for ESP32
|
||||||
#define OTA_PORT 8266
|
#define OTA_PORT 8266
|
||||||
#else
|
#else
|
||||||
#include <ESP8266HTTPUpdateServer.h>
|
//#include <ESP8266mDNS.h>
|
||||||
#include <ESP8266WebServer.h>
|
|
||||||
#include <ESP8266mDNS.h>
|
|
||||||
#include <ESPAsyncTCP.h>
|
#include <ESPAsyncTCP.h>
|
||||||
#define OTA_PORT 8266
|
#define OTA_PORT 3232
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MYEMS_CONFIG_FILE "/config.json"
|
#define MYEMS_CONFIG_FILE "/config.json"
|
||||||
@@ -45,8 +50,10 @@
|
|||||||
#define MQTT_RECONNECT_DELAY_MIN 2000 // Try to reconnect in 3 seconds upon disconnection
|
#define MQTT_RECONNECT_DELAY_MIN 2000 // Try to reconnect in 3 seconds upon disconnection
|
||||||
#define MQTT_RECONNECT_DELAY_STEP 3000 // Increase the reconnect delay in 3 seconds after each failed attempt
|
#define MQTT_RECONNECT_DELAY_STEP 3000 // Increase the reconnect delay in 3 seconds after each failed attempt
|
||||||
#define MQTT_RECONNECT_DELAY_MAX 120000 // Set reconnect time to 2 minutes at most
|
#define MQTT_RECONNECT_DELAY_MAX 120000 // Set reconnect time to 2 minutes at most
|
||||||
#define MQTT_MAX_SIZE 600 // max length of MQTT message
|
|
||||||
#define MQTT_MAX_TOPIC_SIZE 50 // max length of MQTT message
|
#define MQTT_MAX_TOPIC_SIZE 50 // max length of MQTT message
|
||||||
|
#define MQTT_TOPIC_START "start"
|
||||||
|
#define MQTT_TOPIC_START_PAYLOAD "start"
|
||||||
|
#define MQTT_TOPIC_RESTART "restart"
|
||||||
|
|
||||||
// Internal MQTT events
|
// Internal MQTT events
|
||||||
#define MQTT_CONNECT_EVENT 0
|
#define MQTT_CONNECT_EVENT 0
|
||||||
@@ -69,6 +76,8 @@
|
|||||||
#define COLOR_MAGENTA "\x1B[0;35m"
|
#define COLOR_MAGENTA "\x1B[0;35m"
|
||||||
#define COLOR_CYAN "\x1B[0;36m"
|
#define COLOR_CYAN "\x1B[0;36m"
|
||||||
#define COLOR_WHITE "\x1B[0;37m"
|
#define COLOR_WHITE "\x1B[0;37m"
|
||||||
|
#define COLOR_BOLD_ON "\x1B[1m"
|
||||||
|
#define COLOR_BOLD_OFF "\x1B[22m"
|
||||||
#define COLOR_BRIGHT_BLACK "\x1B[0;90m"
|
#define COLOR_BRIGHT_BLACK "\x1B[0;90m"
|
||||||
#define COLOR_BRIGHT_RED "\x1B[0;91m"
|
#define COLOR_BRIGHT_RED "\x1B[0;91m"
|
||||||
#define COLOR_BRIGHT_GREEN "\x1B[0;92m"
|
#define COLOR_BRIGHT_GREEN "\x1B[0;92m"
|
||||||
@@ -77,14 +86,43 @@
|
|||||||
#define COLOR_BRIGHT_MAGENTA "\x1B[0;95m"
|
#define COLOR_BRIGHT_MAGENTA "\x1B[0;95m"
|
||||||
#define COLOR_BRIGHT_CYAN "\x1B[0;96m"
|
#define COLOR_BRIGHT_CYAN "\x1B[0;96m"
|
||||||
#define COLOR_BRIGHT_WHITE "\x1B[0;97m"
|
#define COLOR_BRIGHT_WHITE "\x1B[0;97m"
|
||||||
#define COLOR_BOLD_ON "\x1B[1m"
|
|
||||||
#define COLOR_BOLD_OFF "\x1B[22m" // fixed by Scott Arlott
|
|
||||||
|
|
||||||
// SPIFFS
|
// SPIFFS
|
||||||
#define SPIFFS_MAXSIZE 500 // https://arduinojson.org/v5/assistant/
|
#define SPIFFS_MAXSIZE 600 // https://arduinojson.org/v6/assistant/
|
||||||
|
|
||||||
|
// CRASH
|
||||||
|
/**
|
||||||
|
* Structure of the single crash data set
|
||||||
|
*
|
||||||
|
* 1. Crash time
|
||||||
|
* 2. Restart reason
|
||||||
|
* 3. Exception cause
|
||||||
|
* 4. epc1
|
||||||
|
* 5. epc2
|
||||||
|
* 6. epc3
|
||||||
|
* 7. excvaddr
|
||||||
|
* 8. depc
|
||||||
|
* 9. address of stack start
|
||||||
|
* 10. address of stack end
|
||||||
|
* 11. stack trace bytes
|
||||||
|
* ...
|
||||||
|
*/
|
||||||
|
#define SAVE_CRASH_EEPROM_OFFSET 0x0100 // initial address for crash data
|
||||||
|
#define SAVE_CRASH_CRASH_TIME 0x00 // 4 bytes
|
||||||
|
#define SAVE_CRASH_RESTART_REASON 0x04 // 1 byte
|
||||||
|
#define SAVE_CRASH_EXCEPTION_CAUSE 0x05 // 1 byte
|
||||||
|
#define SAVE_CRASH_EPC1 0x06 // 4 bytes
|
||||||
|
#define SAVE_CRASH_EPC2 0x0A // 4 bytes
|
||||||
|
#define SAVE_CRASH_EPC3 0x0E // 4 bytes
|
||||||
|
#define SAVE_CRASH_EXCVADDR 0x12 // 4 bytes
|
||||||
|
#define SAVE_CRASH_DEPC 0x16 // 4 bytes
|
||||||
|
#define SAVE_CRASH_STACK_START 0x1A // 4 bytes
|
||||||
|
#define SAVE_CRASH_STACK_END 0x1E // 4 bytes
|
||||||
|
#define SAVE_CRASH_STACK_TRACE 0x22 // variable
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char key[40];
|
bool set; // is it a set command
|
||||||
|
char key[50];
|
||||||
char description[100];
|
char description[100];
|
||||||
} command_t;
|
} command_t;
|
||||||
|
|
||||||
@@ -104,6 +142,8 @@ constexpr size_t ArraySize(T (&)[N]) {
|
|||||||
return N;
|
return N;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define UPTIME_OVERFLOW 4294967295 // Uptime overflow value
|
||||||
|
|
||||||
// class definition
|
// class definition
|
||||||
class MyESP {
|
class MyESP {
|
||||||
public:
|
public:
|
||||||
@@ -114,8 +154,10 @@ class MyESP {
|
|||||||
void setWIFICallback(void (*callback)());
|
void setWIFICallback(void (*callback)());
|
||||||
void setWIFI(const char * wifi_ssid, const char * wifi_password, wifi_callback_f callback);
|
void setWIFI(const char * wifi_ssid, const char * wifi_password, wifi_callback_f callback);
|
||||||
bool isWifiConnected();
|
bool isWifiConnected();
|
||||||
|
bool isAPmode();
|
||||||
|
|
||||||
// mqtt
|
// mqtt
|
||||||
|
bool isMQTTConnected();
|
||||||
void mqttSubscribe(const char * topic);
|
void mqttSubscribe(const char * topic);
|
||||||
void mqttUnsubscribe(const char * topic);
|
void mqttUnsubscribe(const char * topic);
|
||||||
void mqttPublish(const char * topic, const char * payload);
|
void mqttPublish(const char * topic, const char * payload);
|
||||||
@@ -132,18 +174,25 @@ class MyESP {
|
|||||||
mqtt_callback_f callback);
|
mqtt_callback_f callback);
|
||||||
|
|
||||||
// OTA
|
// OTA
|
||||||
void setOTA(ota_callback_f OTACallback);
|
void setOTA(ota_callback_f OTACallback_pre, ota_callback_f OTACallback_post);
|
||||||
|
|
||||||
// debug & telnet
|
// debug & telnet
|
||||||
void myDebug(const char * format, ...);
|
void myDebug(const char * format, ...);
|
||||||
void myDebug_P(PGM_P format_P, ...);
|
void myDebug_P(PGM_P format_P, ...);
|
||||||
void setTelnet(command_t * cmds, uint8_t count, telnetcommand_callback_f callback_cmd, telnet_callback_f callback);
|
void setTelnet(command_t * cmds, uint8_t count, telnetcommand_callback_f callback_cmd, telnet_callback_f callback);
|
||||||
bool getUseSerial();
|
bool getUseSerial();
|
||||||
|
void setUseSerial(bool toggle);
|
||||||
|
|
||||||
// FS
|
// FS
|
||||||
void setSettings(fs_callback_f callback, fs_settings_callback_f fs_settings_callback);
|
void setSettings(fs_callback_f callback, fs_settings_callback_f fs_settings_callback);
|
||||||
bool fs_saveConfig();
|
bool fs_saveConfig();
|
||||||
|
|
||||||
|
// Crash
|
||||||
|
void crashClear();
|
||||||
|
void crashDump();
|
||||||
|
void crashTest(uint8_t t);
|
||||||
|
void crashInfo();
|
||||||
|
|
||||||
// general
|
// general
|
||||||
void end();
|
void end();
|
||||||
void loop();
|
void loop();
|
||||||
@@ -152,7 +201,7 @@ class MyESP {
|
|||||||
void resetESP();
|
void resetESP();
|
||||||
uint16_t getSystemLoadAverage();
|
uint16_t getSystemLoadAverage();
|
||||||
int getWifiQuality();
|
int getWifiQuality();
|
||||||
|
void showSystemStats();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// mqtt
|
// mqtt
|
||||||
@@ -187,19 +236,24 @@ class MyESP {
|
|||||||
char * _wifi_ssid;
|
char * _wifi_ssid;
|
||||||
char * _wifi_password;
|
char * _wifi_password;
|
||||||
bool _wifi_connected;
|
bool _wifi_connected;
|
||||||
|
String _getESPhostname();
|
||||||
|
|
||||||
// ota
|
// ota
|
||||||
ota_callback_f _ota_callback;
|
ota_callback_f _ota_pre_callback;
|
||||||
|
ota_callback_f _ota_post_callback;
|
||||||
void _ota_setup();
|
void _ota_setup();
|
||||||
void _OTACallback();
|
void _OTACallback();
|
||||||
|
|
||||||
|
// crash
|
||||||
|
void _eeprom_setup();
|
||||||
|
|
||||||
// telnet & debug
|
// telnet & debug
|
||||||
TelnetSpy SerialAndTelnet;
|
TelnetSpy SerialAndTelnet;
|
||||||
void _telnetConnected();
|
void _telnetConnected();
|
||||||
void _telnetDisconnected();
|
void _telnetDisconnected();
|
||||||
void _telnetHandle();
|
void _telnetHandle();
|
||||||
void _telnetCommand(char * commandLine);
|
void _telnetCommand(char * commandLine);
|
||||||
char * _telnet_readWord();
|
char * _telnet_readWord(bool allow_all_chars);
|
||||||
void _telnet_setup();
|
void _telnet_setup();
|
||||||
char _command[TELNET_MAX_COMMAND_LENGTH]; // the input command from either Serial or Telnet
|
char _command[TELNET_MAX_COMMAND_LENGTH]; // the input command from either Serial or Telnet
|
||||||
command_t * _helpProjectCmds; // Help of commands setted by project
|
command_t * _helpProjectCmds; // Help of commands setted by project
|
||||||
@@ -207,8 +261,7 @@ class MyESP {
|
|||||||
void _consoleShowHelp();
|
void _consoleShowHelp();
|
||||||
telnetcommand_callback_f _telnetcommand_callback; // Callable for projects commands
|
telnetcommand_callback_f _telnetcommand_callback; // Callable for projects commands
|
||||||
telnet_callback_f _telnet_callback; // callback for connect/disconnect
|
telnet_callback_f _telnet_callback; // callback for connect/disconnect
|
||||||
void _changeSetting(uint8_t wc, const char * setting, const char * value);
|
bool _changeSetting(uint8_t wc, const char * setting, const char * value);
|
||||||
void _changeSetting2(const char * setting, const char * value1, const char * value2);
|
|
||||||
|
|
||||||
// fs
|
// fs
|
||||||
void _fs_setup();
|
void _fs_setup();
|
||||||
@@ -216,17 +269,20 @@ class MyESP {
|
|||||||
void _fs_printConfig();
|
void _fs_printConfig();
|
||||||
void _fs_eraseConfig();
|
void _fs_eraseConfig();
|
||||||
|
|
||||||
|
// settings
|
||||||
fs_callback_f _fs_callback;
|
fs_callback_f _fs_callback;
|
||||||
fs_settings_callback_f _fs_settings_callback;
|
fs_settings_callback_f _fs_settings_callback;
|
||||||
|
void _printSetCommands();
|
||||||
|
|
||||||
// general
|
// general
|
||||||
char * _app_hostname;
|
char * _app_hostname;
|
||||||
char * _app_name;
|
char * _app_name;
|
||||||
char * _app_version;
|
char * _app_version;
|
||||||
char * _boottime;
|
char * _boottime;
|
||||||
bool _suspendOutput;
|
bool _suspendOutput;
|
||||||
bool _use_serial;
|
bool _use_serial;
|
||||||
void _printBuildTime(unsigned long unix);
|
unsigned long _getUptime();
|
||||||
|
String _buildTime();
|
||||||
|
|
||||||
// load average (0..100)
|
// load average (0..100)
|
||||||
void _calculateLoad();
|
void _calculateLoad();
|
||||||
|
|||||||
Reference in New Issue
Block a user