mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-09 01:09:51 +03:00
Merged changes for the new dev
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,7 @@
|
||||
#ifndef MyEMS_h
|
||||
#define MyEMS_h
|
||||
|
||||
#define MYESP_VERSION "1.1.6b"
|
||||
#define MYESP_VERSION "1.1.7"
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <ArduinoOTA.h>
|
||||
@@ -19,10 +19,12 @@
|
||||
#include <JustWifi.h> // https://github.com/xoseperez/justwifi
|
||||
#include <TelnetSpy.h> // modified from https://github.com/yasheena/telnetspy
|
||||
|
||||
#include "EEPROM.h"
|
||||
#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)
|
||||
//#include <ESPmDNS.h>
|
||||
@@ -48,7 +50,6 @@ void custom_crash_callback(struct rst_info *, uint32_t, uint32_t);
|
||||
#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_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
|
||||
|
||||
// Internal MQTT events
|
||||
@@ -81,14 +82,34 @@ void custom_crash_callback(struct rst_info *, uint32_t, uint32_t);
|
||||
#define COLOR_BRIGHT_CYAN "\x1B[0;96m"
|
||||
#define COLOR_BRIGHT_WHITE "\x1B[0;97m"
|
||||
#define COLOR_BOLD_ON "\x1B[1m"
|
||||
#define COLOR_BOLD_OFF "\x1B[22m" // fixed by Scott Arlott
|
||||
#define COLOR_BOLD_OFF "\x1B[22m" // fix by Scott Arlott to support Linux
|
||||
|
||||
// SPIFFS
|
||||
#define SPIFFS_MAXSIZE 500 // https://arduinojson.org/v5/assistant/
|
||||
#define SPIFFS_MAXSIZE 600 // https://arduinojson.org/v6/assistant/
|
||||
|
||||
// CRASH
|
||||
<<<<<<< HEAD
|
||||
#define SAVE_CRASH_EEPROM_OFFSET 0x0100 // initial address for crash data
|
||||
#define SAVE_CRASH_EEPROM_SIZE 0x0200 // size
|
||||
=======
|
||||
/**
|
||||
* 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
|
||||
>>>>>>> upstream/dev
|
||||
#define SAVE_CRASH_CRASH_TIME 0x00 // 4 bytes
|
||||
#define SAVE_CRASH_RESTART_REASON 0x04 // 1 byte
|
||||
#define SAVE_CRASH_EXCEPTION_CAUSE 0x05 // 1 byte
|
||||
@@ -102,7 +123,8 @@ void custom_crash_callback(struct rst_info *, uint32_t, uint32_t);
|
||||
#define SAVE_CRASH_STACK_TRACE 0x22 // variable
|
||||
|
||||
typedef struct {
|
||||
char key[40];
|
||||
bool set; // is it a set command
|
||||
char key[50];
|
||||
char description[100];
|
||||
} command_t;
|
||||
|
||||
@@ -122,6 +144,8 @@ constexpr size_t ArraySize(T (&)[N]) {
|
||||
return N;
|
||||
}
|
||||
|
||||
#define UPTIME_OVERFLOW 4294967295 // Uptime overflow value
|
||||
|
||||
// class definition
|
||||
class MyESP {
|
||||
public:
|
||||
@@ -132,6 +156,7 @@ class MyESP {
|
||||
void setWIFICallback(void (*callback)());
|
||||
void setWIFI(const char * wifi_ssid, const char * wifi_password, wifi_callback_f callback);
|
||||
bool isWifiConnected();
|
||||
bool isAPmode();
|
||||
|
||||
// mqtt
|
||||
bool isMQTTConnected();
|
||||
@@ -142,7 +167,7 @@ class MyESP {
|
||||
const char * mqtt_username,
|
||||
const char * mqtt_password,
|
||||
const char * mqtt_base,
|
||||
unsigned long mqtt_keepalive,
|
||||
uint32_t mqtt_keepalive,
|
||||
unsigned char mqtt_qos,
|
||||
bool mqtt_retain,
|
||||
const char * mqtt_will_topic,
|
||||
@@ -151,22 +176,24 @@ class MyESP {
|
||||
mqtt_callback_f callback);
|
||||
|
||||
// OTA
|
||||
void setOTA(ota_callback_f OTACallback);
|
||||
void setOTA(ota_callback_f OTACallback_pre, ota_callback_f OTACallback_post);
|
||||
|
||||
// debug & telnet
|
||||
void myDebug(const char * format, ...);
|
||||
void myDebug_P(PGM_P format_P, ...);
|
||||
void setTelnet(command_t * cmds, uint8_t count, telnetcommand_callback_f callback_cmd, telnet_callback_f callback);
|
||||
bool getUseSerial();
|
||||
void setUseSerial(bool toggle);
|
||||
|
||||
// FS
|
||||
void setSettings(fs_callback_f callback, fs_settings_callback_f fs_settings_callback);
|
||||
bool fs_saveConfig();
|
||||
|
||||
// CRASH
|
||||
// Crash
|
||||
void crashClear();
|
||||
void crashDump();
|
||||
void crashTest(uint8_t t);
|
||||
void crashInfo();
|
||||
|
||||
// general
|
||||
void end();
|
||||
@@ -176,12 +203,12 @@ class MyESP {
|
||||
void resetESP();
|
||||
uint16_t getSystemLoadAverage();
|
||||
int getWifiQuality();
|
||||
|
||||
void showSystemStats();
|
||||
|
||||
private:
|
||||
// mqtt
|
||||
AsyncMqttClient mqttClient;
|
||||
unsigned long _mqtt_reconnect_delay;
|
||||
uint32_t _mqtt_reconnect_delay;
|
||||
void _mqttOnMessage(char * topic, char * payload, size_t len);
|
||||
void _mqttConnect();
|
||||
void _mqtt_setup();
|
||||
@@ -193,14 +220,14 @@ class MyESP {
|
||||
char * _mqtt_username;
|
||||
char * _mqtt_password;
|
||||
char * _mqtt_base;
|
||||
unsigned long _mqtt_keepalive;
|
||||
unsigned char _mqtt_qos;
|
||||
uint32_t _mqtt_keepalive;
|
||||
uint8_t _mqtt_qos;
|
||||
bool _mqtt_retain;
|
||||
char * _mqtt_will_topic;
|
||||
char * _mqtt_will_online_payload;
|
||||
char * _mqtt_will_offline_payload;
|
||||
char * _mqtt_topic;
|
||||
unsigned long _mqtt_last_connection;
|
||||
uint32_t _mqtt_last_connection;
|
||||
bool _mqtt_connecting;
|
||||
|
||||
// wifi
|
||||
@@ -211,19 +238,24 @@ class MyESP {
|
||||
char * _wifi_ssid;
|
||||
char * _wifi_password;
|
||||
bool _wifi_connected;
|
||||
String _getESPhostname();
|
||||
|
||||
// ota
|
||||
ota_callback_f _ota_callback;
|
||||
ota_callback_f _ota_pre_callback;
|
||||
ota_callback_f _ota_post_callback;
|
||||
void _ota_setup();
|
||||
void _OTACallback();
|
||||
|
||||
// crash
|
||||
void _eeprom_setup();
|
||||
|
||||
// telnet & debug
|
||||
TelnetSpy SerialAndTelnet;
|
||||
void _telnetConnected();
|
||||
void _telnetDisconnected();
|
||||
void _telnetHandle();
|
||||
void _telnetCommand(char * commandLine);
|
||||
char * _telnet_readWord();
|
||||
char * _telnet_readWord(bool allow_all_chars);
|
||||
void _telnet_setup();
|
||||
char _command[TELNET_MAX_COMMAND_LENGTH]; // the input command from either Serial or Telnet
|
||||
command_t * _helpProjectCmds; // Help of commands setted by project
|
||||
@@ -231,8 +263,7 @@ class MyESP {
|
||||
void _consoleShowHelp();
|
||||
telnetcommand_callback_f _telnetcommand_callback; // Callable for projects commands
|
||||
telnet_callback_f _telnet_callback; // callback for connect/disconnect
|
||||
void _changeSetting(uint8_t wc, const char * setting, const char * value);
|
||||
void _changeSetting2(const char * setting, const char * value1, const char * value2);
|
||||
bool _changeSetting(uint8_t wc, const char * setting, const char * value);
|
||||
|
||||
// fs
|
||||
void _fs_setup();
|
||||
@@ -240,17 +271,20 @@ class MyESP {
|
||||
void _fs_printConfig();
|
||||
void _fs_eraseConfig();
|
||||
|
||||
// settings
|
||||
fs_callback_f _fs_callback;
|
||||
fs_settings_callback_f _fs_settings_callback;
|
||||
void _printSetCommands();
|
||||
|
||||
// general
|
||||
char * _app_hostname;
|
||||
char * _app_name;
|
||||
char * _app_version;
|
||||
char * _boottime;
|
||||
bool _suspendOutput;
|
||||
bool _use_serial;
|
||||
void _printBuildTime(unsigned long rawTime);
|
||||
char * _app_hostname;
|
||||
char * _app_name;
|
||||
char * _app_version;
|
||||
char * _boottime;
|
||||
bool _suspendOutput;
|
||||
bool _use_serial;
|
||||
uint32_t _getUptime();
|
||||
String _buildTime();
|
||||
|
||||
// load average (0..100)
|
||||
void _calculateLoad();
|
||||
|
||||
Reference in New Issue
Block a user