prepare for ems plujs updates

This commit is contained in:
proddy
2019-04-04 21:02:20 +02:00
parent f87c5a3d66
commit b31f3118d1
12 changed files with 107 additions and 75 deletions

View File

@@ -155,8 +155,6 @@ void MyESP::_wifiCallback(justwifi_messages_t code, char * parameter) {
// finally if we don't want Serial anymore, turn it off
if (!_use_serial) {
myDebug_P(PSTR("Disabling serial port"));
Serial.flush();
Serial.end();
SerialAndTelnet.setSerial(NULL);
} else {
myDebug_P(PSTR("Using serial port output"));
@@ -679,6 +677,19 @@ bool MyESP::_changeSetting(uint8_t wc, const char * setting, const char * value)
return ok;
}
// force the serial on/off
void MyESP::setUseSerial(bool toggle) {
//(void)fs_saveConfig(); // save the setting for next reboot
if (toggle) {
SerialAndTelnet.setSerial(&Serial);
_use_serial = true;
} else {
SerialAndTelnet.setSerial(NULL);
_use_serial = false;
}
}
void MyESP::_telnetCommand(char * commandLine) {
char * str = commandLine;
bool state = false;
@@ -792,14 +803,14 @@ String MyESP::_buildTime() {
}
// returns system uptime in seconds - copied for espurna. see (c)
unsigned long MyESP::_getUptime() {
static unsigned long last_uptime = 0;
uint32_t MyESP::_getUptime() {
static uint32_t last_uptime = 0;
static unsigned char uptime_overflows = 0;
if (millis() < last_uptime)
++uptime_overflows;
last_uptime = millis();
unsigned long uptime_seconds = uptime_overflows * (UPTIME_OVERFLOW / 1000) + (last_uptime / 1000);
last_uptime = millis();
uint32_t uptime_seconds = uptime_overflows * (UPTIME_OVERFLOW / 1000) + (last_uptime / 1000);
return uptime_seconds;
}
@@ -884,9 +895,7 @@ void MyESP::showSystemStats() {
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] Free Heap: %d"), ESP.getFreeHeap());
#if defined(ESP8266)
myDebug_P(PSTR(" [MEM] Stack: %d"), ESP.getFreeContStack());
#endif
myDebug_P(PSTR(""));
}
@@ -1019,8 +1028,8 @@ void MyESP::setMQTT(const char * mqtt_host,
const char * mqtt_username,
const char * mqtt_password,
const char * mqtt_base,
unsigned long mqtt_keepalive,
unsigned char mqtt_qos,
uint32_t mqtt_keepalive,
uint8_t mqtt_qos,
bool mqtt_retain,
const char * mqtt_will_topic,
const char * mqtt_will_online_payload,
@@ -1155,7 +1164,7 @@ bool MyESP::_fs_loadConfig() {
// Deserialize the JSON document
DeserializationError error = deserializeJson(doc, configFile);
if (error) {
Serial.println(F("[FS] Failed to read file"));
myDebug_P(PSTR("[FS] Failed to read config file"));
return false;
}
@@ -1264,13 +1273,13 @@ uint16_t MyESP::getSystemLoadAverage() {
// calculate load average
void MyESP::_calculateLoad() {
static unsigned long last_loadcheck = 0;
static unsigned long load_counter_temp = 0;
static uint32_t last_loadcheck = 0;
static uint32_t load_counter_temp = 0;
load_counter_temp++;
if (millis() - last_loadcheck > LOADAVG_INTERVAL) {
static unsigned long load_counter = 0;
static unsigned long load_counter_max = 1;
static uint32_t load_counter = 0;
static uint32_t load_counter_max = 1;
load_counter = load_counter_temp;
load_counter_temp = 0;
@@ -1478,7 +1487,7 @@ void MyESP::begin(const char * app_hostname, const char * app_name, const char *
_eeprom_setup(); // set up eeprom for storing crash data
_fs_setup(); // SPIFFS setup, do this first to get values
_wifi_setup(); // WIFI setup
_ota_setup();
_ota_setup(); // init OTA
}
/*
@@ -1490,12 +1499,10 @@ void MyESP::loop() {
jw.loop(); // WiFi
/*
// do nothing else until we've got a wifi connection
if (WiFi.getMode() & WIFI_AP) {
return;
}
*/
ArduinoOTA.handle(); // OTA
_mqttConnect(); // MQTT

View File

@@ -9,7 +9,7 @@
#ifndef MyEMS_h
#define MyEMS_h
#define MYESP_VERSION "1.1.6"
#define MYESP_VERSION "1.1.7"
#include <ArduinoJson.h>
#include <ArduinoOTA.h>
@@ -50,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
@@ -155,7 +154,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,
@@ -171,6 +170,7 @@ class MyESP {
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);
@@ -195,7 +195,7 @@ class MyESP {
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();
@@ -207,14 +207,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
@@ -264,14 +264,14 @@ class MyESP {
void _printSetCommands();
// general
char * _app_hostname;
char * _app_name;
char * _app_version;
char * _boottime;
bool _suspendOutput;
bool _use_serial;
unsigned long _getUptime();
String _buildTime();
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();