prep for syslog

This commit is contained in:
Paul
2019-11-19 23:11:26 +01:00
parent 9a0780ba77
commit a04b2ff708
10 changed files with 75 additions and 546 deletions

View File

@@ -42,6 +42,7 @@ There are breaking changes in this release. See `publish_time` below and make su
### Removed
- thermostat scan and autodetect deep functions
- removed Event Logging to SPIFFS (worried about wearing). Replaced with SysLog.
## [1.9.3] 2019-10-26

View File

@@ -16,9 +16,25 @@ default_envs = release
;custom_flags = -DFORCE_SERIAL -DMYESP_DEBUG
custom_flags =
;general_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH_LOW_FLASH -DVTABLES_IN_FLASH
general_flags = -fno-exceptions -lstdc++ -DNO_GLOBAL_EEPROM -DBEARSSL_SSL_BASIC
;general_flags =
#
# Available lwIP variants (macros):
# -DPIO_FRAMEWORK_ARDUINO_LWIP_HIGHER_BANDWIDTH = v1.4 Higher Bandwidth (default)
# -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY = v2 Lower Memory
# -DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH = v2 Higher Bandwidth
# -DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH_LOW_FLASH
# -DPIO_FRAMEWORK_ARDUINO_LWIP2_IPV6_LOW_MEMORY
# Other flags
# -DVTABLES_IN_FLASH
# -DNO_GLOBAL_EEPROM
# -DBEARSSL_SSL_BASIC
general_flags = -std=c++11 -DNO_GLOBAL_EEPROM -DBEARSSL_SSL_BASIC -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
# From https://github.com/esp8266/Arduino/blob/master/tools/sdk/ld
# eagle.flash.4m1m.ld = 1019 KB sketch, 1000 KB SPIFFS. 4KB EEPROM, 4KB RFCAL, 12KB WIFI stack, 2052 KB OTA & buffer
# eagle.flash.4m2m.ld = same as above but with 2024 KB SPIFFS
# eagle.flash.4m.ld = same as above but with no SPIFFS storage
build_flags_4m1m = -Wl,-Teagle.flash.4m1m.ld
build_flags = ${common.general_flags} ${common.build_flags_4m1m}
[env]
framework = arduino
@@ -26,13 +42,13 @@ platform = espressif8266
lib_deps =
https://github.com/rlogiacco/CircularBuffer
https://github.com/PaulStoffregen/OneWire
;https://github.com/me-no-dev/ESPAsyncWebServer
https://github.com/me-no-dev/ESPAsyncWebServer#b0c6144
https://github.com/me-no-dev/ESPAsyncWebServer
;https://github.com/me-no-dev/ESPAsyncWebServer#b0c6144
https://github.com/bakercp/CRC32
JustWifi@2.0.2
AsyncMqttClient@0.8.2
EEPROM_Rotate@0.9.2
ArduinoJson@6.12.0
ArduinoJson@6.13.0
ESPAsyncUDP
ESPAsyncTCP@1.2.2
upload_speed = 921600
@@ -51,27 +67,27 @@ upload_port = ems-esp.local
# Do not modify
[env:travis]
board = esp12e
build_flags = ${common.general_flags}
build_flags = ${common.build_flags}
extra_scripts = scripts/main_script.py
[env:esp12e]
board = esp12e
build_flags = ${common.general_flags}
build_flags = ${common.build_flags}
extra_scripts = scripts/main_script.py
[env:d1_mini]
board = d1_mini
build_flags = ${common.general_flags}
build_flags = ${common.build_flags}
extra_scripts = scripts/main_script.py
[env:nodemcuv2]
board = nodemcuv2
build_flags = ${common.general_flags}
build_flags = ${common.build_flags}
extra_scripts = scripts/main_script.py
[env:nodemcu]
board = nodemcu
build_flags = ${common.general_flags}
build_flags = ${common.build_flags}
extra_scripts = scripts/main_script.py
#
@@ -80,7 +96,7 @@ extra_scripts = scripts/main_script.py
[env:debug]
board = d1_mini
build_type = debug
build_flags = ${common.general_flags} ${common.custom_flags}
build_flags = ${common.build_flags} ${common.custom_flags}
extra_scripts =
pre:scripts/pre_script.py
scripts/main_script.py
@@ -88,7 +104,7 @@ extra_scripts =
[env:release]
board = d1_mini
build_type = release
build_flags = ${common.general_flags} ${common.custom_flags}
build_flags = ${common.build_flags} ${common.custom_flags}
extra_scripts =
pre:scripts/pre_script.py
scripts/main_script.py

View File

@@ -380,7 +380,9 @@ bool MyESP::mqttSubscribe(const char * topic) {
char * topic_s = _mqttTopic(topic);
uint16_t packet_id = mqttClient.subscribe(topic_s, _mqtt_qos);
// myDebug_P(PSTR("[MQTT] Subscribing to %s"), topic_s);
#ifdef MYESP_DEBUG
myDebug_P(PSTR("[MQTT] Subscribing to %s"), topic_s);
#endif
if (packet_id) {
// add to mqtt log
@@ -497,7 +499,6 @@ void MyESP::_mqtt_setup() {
// last will
if (_hasValue(_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
}
@@ -650,7 +651,9 @@ void MyESP::_telnetConnected() {
}
void MyESP::_telnetDisconnected() {
// myDebug_P(PSTR("[TELNET] Telnet connection closed"));
#ifdef MYESP_DEBUG
myDebug_P(PSTR("[TELNET] Telnet connection closed"));
#endif
if (_telnet_callback_f) {
(_telnet_callback_f)(TELNET_EVENT_DISCONNECT); // call callback
}
@@ -1144,7 +1147,6 @@ void MyESP::_setSystemBootStatus(uint8_t status) {
data.value = Rtcmem->sys;
data.parts.boot_status = status;
Rtcmem->sys = data.value;
// myDebug("*** setting boot status to %d", data.parts.boot_status);
}
uint8_t MyESP::_getSystemStabilityCounter() {
@@ -1677,104 +1679,6 @@ size_t MyESP::_fs_validateConfigFile(const char * filename, size_t maxsize, Json
return size;
}
// validates the event log file in SPIFFS
// returns true if all OK
size_t MyESP::_fs_validateLogFile(const char * filename) {
// exit if we have disabled logging
if (!_general_log_events) {
return 0;
}
// see if we can open it
File eventlog = SPIFFS.open(filename, "r");
if (!eventlog) {
myDebug_P(PSTR("[FS] File %s not found"), filename);
return 0;
}
// check sizes
size_t size = eventlog.size();
size_t maxsize = ESP.getFreeHeap() - 2000; // reserve some buffer
#ifdef MYESP_DEBUG
myDebug_P(PSTR("[FS] Checking file %s (%d/%d bytes)"), filename, size, maxsize);
#endif
if (size > maxsize) {
eventlog.close();
myDebug_P(PSTR("[FS] File %s size %d is too large"), filename, size);
return 0;
} else if (size == 0) {
eventlog.close();
myDebug_P(PSTR("[FS] Corrupted file %s"), filename);
return 0;
}
/*
// check integrity by reading file from SPIFFS into the char array
char * buffer = new char[size + 2]; // reserve some memory to read in the file
size_t real_size = file.readBytes(buffer, size);
if (real_size != size) {
file.close();
myDebug_P(PSTR("[FS] Error, file %s sizes don't match (%d/%d), looks corrupted"), filename, real_size, size);
delete[] buffer;
return false;
}
file.close();
delete[] buffer;
*/
/*
File configFile = SPIFFS.open(filename, "r");
myDebug_P(PSTR("[FS] File: "));
while (configFile.available()) {
SerialAndTelnet.print((char)configFile.read());
}
myDebug_P(PSTR("[FS] end")); // newline
configFile.close();
*/
// parse it to check JSON validity
// its slow but the only reliable way to check integrity of the file
uint16_t char_count = 0;
bool abort = false;
char char_buffer[MYESP_JSON_LOG_MAXSIZE];
StaticJsonDocument<MYESP_JSON_LOG_MAXSIZE> doc;
// eventlog.seek(0);
while (eventlog.available() && !abort) {
char c = eventlog.read(); // read a char
// see if we have reached the end of the string
if (c == '\0' || c == '\n') {
char_buffer[char_count] = '\0'; // terminate and add it to the list
#ifdef MYESP_DEBUG
Serial.printf("Got line: %s\n", char_buffer);
#endif
// validate it by looking at JSON structure
DeserializationError error = deserializeJson(doc, char_buffer);
if (error) {
myDebug_P(PSTR("[FS] Event log has a corrupted entry (error %s)"), error.c_str());
abort = true;
}
char_count = 0; // start new record
} else {
// add the char to the buffer if recording, checking for overrun
if (char_count < MYESP_JSON_LOG_MAXSIZE) {
char_buffer[char_count++] = c;
} else {
abort = true; // reached limit of our line buffer
}
}
}
eventlog.close();
if (abort) {
return 0;
}
return size;
}
// format File System
void MyESP::_fs_eraseConfig() {
myDebug_P(PSTR("[FS] Performing a factory reset..."));
@@ -1795,12 +1699,6 @@ void MyESP::setSettings(fs_loadsave_callback_f loadsave, fs_setlist_callback_f s
// load system config from SPIFFS
// returns false on error or the file needs to be recreated
bool MyESP::_fs_loadConfig() {
// see if old file exists and delete it
if (SPIFFS.exists("/config.json")) {
SPIFFS.remove("/config.json");
myDebug_P(PSTR("[FS] Removed old config version"));
}
StaticJsonDocument<MYESP_SPIFFS_MAXSIZE_CONFIG> doc;
// set to true to print out contents of file
@@ -1973,20 +1871,9 @@ bool MyESP::fs_saveCustomConfig(JsonObject root) {
configFile.close();
if (n) {
/*
// reload the settings, not sure why?
if (_fs_loadsave_callback_f) {
if (!(_fs_loadsave_callback_f)(MYESP_FSACTION_LOAD, root)) {
myDebug_P(PSTR("[FS] Error parsing custom config json"));
}
}
*/
if (_general_log_events) {
_writeEvent("INFO", "system", "Custom config stored in the SPIFFS", "");
_writeLogEvent("INFO", "system", "Custom config stored in the SPIFFS", "");
}
// myDebug_P(PSTR("[FS] custom config saved"));
ok = true;
}
}
@@ -2020,9 +1907,8 @@ bool MyESP::fs_saveConfig(JsonObject root) {
if (n) {
if (_general_log_events) {
_writeEvent("INFO", "system", "System config stored in the SPIFFS", "");
_writeLogEvent("INFO", "system", "System config stored in the SPIFFS", "");
}
// myDebug_P(PSTR("[FS] system config saved"));
ok = true;
}
@@ -2122,30 +2008,16 @@ void MyESP::_fs_setup() {
}
}
/*
// fill event log with tests
SPIFFS.remove(MYESP_EVENTLOG_FILE);
File fs = SPIFFS.open(MYESP_EVENTLOG_FILE, "w");
fs.close();
char logs[100];
for (uint8_t i = 1; i < 143; i++) {
sprintf(logs, "Record #%d", i);
_writeEvent("WARN", "system", "test data", logs);
// see if old files exists from previous versions and delete it
if (SPIFFS.exists(MYESP_OLD_CONFIG_FILE)) {
SPIFFS.remove(MYESP_OLD_CONFIG_FILE);
myDebug_P(PSTR("[FS] Removed old config settings"));
}
*/
// validate the event log. Sometimes it can can corrupted.
size_t size = _fs_validateLogFile(MYESP_EVENTLOG_FILE);
if (size) {
myDebug_P(PSTR("[FS] Event log loaded (%d bytes)"), size);
} else {
#ifndef MYESP_DEBUG
myDebug_P(PSTR("[FS] Resetting event log"));
SPIFFS.remove(MYESP_EVENTLOG_FILE);
if (_general_log_events) {
_writeEvent("WARN", "system", "Event Log", "Log was erased due to probable file corruption");
}
#endif
// see if old file exists and delete it
if (SPIFFS.exists(MYESP_OLD_CONFIG_FILE)) {
SPIFFS.remove(MYESP_OLD_CONFIG_FILE);
myDebug_P(PSTR("[FS] Removed old config settings"));
}
// load the main system config file if we can. Otherwise create it and expect user to configure in web interface
@@ -2380,127 +2252,13 @@ void MyESP::crashInfo() {
}
#endif
// write a log entry to SPIFFS
// write a log entry to SysLog via UDP
// assumes we have "log_events" on
void MyESP::_writeEvent(const char * type, const char * src, const char * desc, const char * data) {
// this will also create the file if its doesn't exist
File eventlog = SPIFFS.open(MYESP_EVENTLOG_FILE, "a");
if (!eventlog) {
void MyESP::_writeLogEvent(const char * type, const char * src, const char * desc, const char * data) {
// TODO: finish function
#ifdef MYESP_DEBUG
Serial.println("[SYSTEM] Error opening event log for writing");
Serial.printf("%s: %s\n", type, desc);
#endif
eventlog.close();
return;
}
StaticJsonDocument<MYESP_JSON_LOG_MAXSIZE> root;
root["type"] = type;
root["src"] = src;
root["desc"] = desc;
root["data"] = data;
root["time"] = now(); // is relative if we're not using NTP
// Serialize JSON to file
(void)serializeJson(root, eventlog);
eventlog.print("\n"); // this indicates end of the entry
eventlog.close();
}
// send a paged list (10 items) to the ws
void MyESP::_sendEventLog(uint8_t page) {
if (_ota_pre_callback_f) {
(_ota_pre_callback_f)(); // call custom function
}
File eventlog;
// if its missing create it, it'll be empty though
if (!SPIFFS.exists(MYESP_EVENTLOG_FILE)) {
myDebug_P(PSTR("[FS] Event log is missing. Creating it."));
eventlog = SPIFFS.open(MYESP_EVENTLOG_FILE, "w");
eventlog.close();
}
eventlog = SPIFFS.open(MYESP_EVENTLOG_FILE, "r");
// the size of the json will be quite big so best not to use stack (StaticJsonDocument)
// it only covers 10 log entries
DynamicJsonDocument doc(MYESP_JSON_MAXSIZE);
JsonObject root = doc.to<JsonObject>();
root["command"] = "eventlist";
root["page"] = page;
JsonArray list = doc.createNestedArray("list");
size_t static lastPos;
// if first page, reset the file pointer
if (page == 1) {
lastPos = 0;
}
eventlog.seek(lastPos); // move to position in file
uint8_t char_count = 0;
uint8_t line_count = 0;
bool abort = false;
char char_buffer[MYESP_JSON_LOG_MAXSIZE];
float pages;
// start at top and read until we find the page we want (sets of 10)
while (eventlog.available() && !abort) {
char c = eventlog.read();
// see if we have reached the end of the string
if (c == '\0' || c == '\n') {
char_buffer[char_count] = '\0'; // terminate and add it to the list
#ifdef MYESP_DEBUG
Serial.printf("Got line %d: %s\n", line_count + 1, char_buffer);
#endif
list.add(char_buffer);
// increment line counter and check if we've reached 10 records, if so abort
if (++line_count == 10) {
abort = true;
}
char_count = 0; // start new record
} else {
// add the char to the buffer if recording, checking for overrun
if (char_count < MYESP_JSON_LOG_MAXSIZE) {
char_buffer[char_count++] = c;
} else {
abort = true; // reached limit of our line buffer
}
}
}
lastPos = eventlog.position(); // remember last position for next cycle
// calculate remaining pages, as needed for footable
if (eventlog.available()) {
float totalPagesRoughly = eventlog.size() / (float)(lastPos / page);
pages = totalPagesRoughly < page ? page + 1 : totalPagesRoughly;
} else {
pages = page; // this was the last page
}
eventlog.close(); // close SPIFFS
root["haspages"] = ceil(pages);
char buffer[MYESP_JSON_MAXSIZE];
size_t len = serializeJson(root, buffer);
#ifdef MYESP_DEBUG
Serial.printf("\nEVENTLOG: page %d, length=%d\n", page, len);
serializeJson(root, Serial);
#endif
_ws->textAll(buffer, len);
_ws->textAll("{\"command\":\"result\",\"resultof\":\"eventlist\",\"result\": true}");
if (_ota_post_callback_f) {
(_ota_post_callback_f)(); // call custom function
}
}
// Handles WebSocket Events
@@ -2556,7 +2314,7 @@ void MyESP::_procMsg(AsyncWebSocketClient * client, size_t sz) {
const char * command = doc["command"];
#ifdef MYESP_DEBUG
Serial.printf("*** Got command: %s\n", command);
myDebug("*** Got command: %s\n", command);
#endif
// Check whatever the command is and act accordingly
@@ -2574,19 +2332,10 @@ void MyESP::_procMsg(AsyncWebSocketClient * client, size_t sz) {
_formatreq = true;
} else if (strcmp(command, "forcentp") == 0) {
NTP.getNtpTime();
} else if (strcmp(command, "geteventlog") == 0) {
uint8_t page = doc["page"];
_sendEventLog(page);
} else if (strcmp(command, "clearevent") == 0) {
_emptyEventLog();
} else if (strcmp(command, "scan") == 0) {
WiFi.scanNetworksAsync(std::bind(&MyESP::_printScanResult, this, std::placeholders::_1), true);
} else if (strcmp(command, "gettime") == 0) {
_timerequest = true;
} else if (strcmp(command, "settime") == 0) {
time_t t = doc["epoch"];
setTime(t);
_timerequest = true;
} else if (strcmp(command, "getconf") == 0) {
_fs_sendConfig();
}
@@ -2595,22 +2344,6 @@ void MyESP::_procMsg(AsyncWebSocketClient * client, size_t sz) {
client->_tempObject = NULL;
}
// delete the event log
void MyESP::_emptyEventLog() {
if (_ota_pre_callback_f) {
(_ota_pre_callback_f)(); // call custom function
}
if (SPIFFS.remove(MYESP_EVENTLOG_FILE)) {
_writeEvent("WARN", "system", "Event log cleared", "");
myDebug_P(PSTR("[WEB] Event log cleared"));
} else {
myDebug_P(PSTR("[WEB] Could not clear event log"));
}
if (_ota_post_callback_f) {
(_ota_post_callback_f)(); // call custom function
}
}
// read both system config and the custom config and send as json to web socket
bool MyESP::_fs_sendConfig() {
File configFile;
@@ -2632,7 +2365,7 @@ bool MyESP::_fs_sendConfig() {
configFile.close();
#ifdef MYESP_DEBUG
Serial.printf("_fs_sendConfig() sending system (%d): %s\n", size, json);
myDebug("_fs_sendConfig() sending system (%d): %s\n", size, json);
#endif
_ws->textAll(json, size);
@@ -2653,7 +2386,7 @@ bool MyESP::_fs_sendConfig() {
configFile.close();
#ifdef MYESP_DEBUG
Serial.printf("_fs_sendConfig() sending custom (%d): %s\n", size, json);
myDebug("_fs_sendConfig() sending custom (%d): %s\n", size, json);
#endif
_ws->textAll(json, size);
@@ -2684,7 +2417,7 @@ void MyESP::_sendCustomStatus() {
size_t len = serializeJson(root, buffer);
#ifdef MYESP_DEBUG
Serial.printf("_sendCustomStatus() sending: %s\n", buffer);
myDebug("_sendCustomStatus() sending: %s\n", buffer);
#endif
_ws->textAll(buffer, len);
@@ -2836,13 +2569,10 @@ void MyESP::_webserver_setup() {
}
if (!index) {
ETS_UART_INTR_DISABLE(); // disable all UART interrupts to be safe
_writeEvent("INFO", "system", "Firmware update started", "");
#ifdef MYESP_DEBUG
Serial.printf("[SYSTEM] Firmware update started: %s\n", filename.c_str());
#endif
_writeLogEvent("INFO", "system", "Firmware update started", "");
Update.runAsync(true);
if (!Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000)) {
_writeEvent("ERRO", "system", "Not enough space to update", "");
_writeLogEvent("ERRO", "system", "Not enough space to update", "");
#ifdef MYESP_DEBUG
Update.printError(Serial);
#endif
@@ -2850,7 +2580,7 @@ void MyESP::_webserver_setup() {
}
if (!Update.hasError()) {
if (Update.write(data, len) != len) {
_writeEvent("ERRO", "system", "Writing to flash failed", "");
_writeLogEvent("ERRO", "system", "Writing to flash failed", "");
#ifdef MYESP_DEBUG
Update.printError(Serial);
#endif
@@ -2858,10 +2588,10 @@ void MyESP::_webserver_setup() {
}
if (final) {
if (Update.end(true)) {
_writeEvent("INFO", "system", "Firmware update finished", "");
_writeLogEvent("INFO", "system", "Firmware update finished", "");
_shouldRestart = !Update.hasError();
} else {
_writeEvent("ERRO", "system", "Firmware update failed", "");
_writeLogEvent("ERRO", "system", "Firmware update failed", "");
#ifdef MYESP_DEBUG
Update.printError(Serial);
#endif
@@ -3036,7 +2766,7 @@ void MyESP::_bootupSequence() {
if ((_ntp_enabled) && (now() > 10000) && !_have_ntp_time) {
_have_ntp_time = true;
if (_general_log_events) {
_writeEvent("INFO", "system", "System booted", "");
_writeLogEvent("INFO", "system", "System booted", "");
}
}
return;
@@ -3068,7 +2798,7 @@ void MyESP::_bootupSequence() {
// write a log message if we're not using NTP, otherwise wait for the internet time to arrive
if (!_ntp_enabled) {
if (_general_log_events) {
_writeEvent("INFO", "system", "System booted", "");
_writeLogEvent("INFO", "system", "System booted", "");
}
}
}
@@ -3151,7 +2881,7 @@ void MyESP::loop() {
if (_shouldRestart) {
if (_general_log_events) {
_writeEvent("INFO", "system", "System is restarting", "");
_writeLogEvent("INFO", "system", "System is restarting", "");
}
myDebug("[SYSTEM] Restarting...");
_deferredReset(500, CUSTOM_RESET_TERMINAL);

View File

@@ -9,7 +9,7 @@
#ifndef MyESP_h
#define MyESP_h
#define MYESP_VERSION "1.2.19"
#define MYESP_VERSION "1.2.20"
#include <ArduinoJson.h>
#include <ArduinoOTA.h>
@@ -53,7 +53,8 @@ extern struct rst_info resetInfo;
#define MYESP_CONFIG_FILE "/myesp.json"
#define MYESP_CUSTOMCONFIG_FILE "/customconfig.json"
#define MYESP_EVENTLOG_FILE "/eventlog.json"
#define MYESP_EVENTLOG_FILE "/eventlog.json" // depreciated
#define MYESP_OLD_CONFIG_FILE "/config.json" // depreciated
#define MYESP_HTTP_USERNAME "admin" // HTTP username
#define MYESP_HTTP_PASSWORD "admin" // default password
@@ -67,7 +68,6 @@ extern struct rst_info resetInfo;
#define MYESP_WIFI_RECONNECT_INTERVAL 600000 // If could not connect to WIFI, retry after this time in ms. 10 minutes
// set to value >0 if the ESP is overheating or there are timing issues. Recommend a value of 1.
// initially set to 0 for no delay. Change to 1 if getting WDT resets from wifi
#define MYESP_DELAY 1
// MQTT
@@ -266,8 +266,8 @@ class MyESP {
MyESP();
~MyESP();
// write event called from within lambda classs
static void _writeEvent(const char * type, const char * src, const char * desc, const char * data);
// write event called from within lambda class
static void _writeLogEvent(const char * type, const char * src, const char * desc, const char * data);
// wifi
void setWIFICallback(void (*callback)());
@@ -475,10 +475,6 @@ class MyESP {
web_callback_f _web_callback_f;
const char * _http_username;
// log
void _sendEventLog(uint8_t page);
void _emptyEventLog();
// web
void _onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t * data, size_t len);
void _procMsg(AsyncWebSocketClient * client, size_t sz);

View File

@@ -1702,7 +1702,7 @@ void WebCallback(JsonObject root) {
}
} else {
emsbus["ok"] = false;
emsbus["msg"] = "EMS Bus is not connected. Check event logs for errors.";
emsbus["msg"] = "EMS Bus is not connected.";
}
}

View File

@@ -1323,7 +1323,6 @@ void _process_UBAMonitorFast(_EMS_RxTelegram * EMS_RxTelegram) {
*/
void _process_UBAMonitorFast2(_EMS_RxTelegram * EMS_RxTelegram) {
EMS_Boiler.selFlowTemp = _toByte(6);
// EMS_Boiler.retTemp = _toShort(13);
EMS_Boiler.burnGas = _bitRead(11, 0);
EMS_Boiler.wWHeat = _bitRead(11, 2);
@@ -1331,23 +1330,21 @@ void _process_UBAMonitorFast2(_EMS_RxTelegram * EMS_RxTelegram) {
EMS_Boiler.curBurnPow = _toByte(10);
EMS_Boiler.selBurnPow = _toByte(9); // burn power max setting
// set boiler temp only if we actually have a real value
if (_toShort(7) != EMS_VALUE_USHORT_NOTSET) {
EMS_Boiler.boilTemp = _toShort(7); // 0x8000 if not available
EMS_Boiler.curFlowTemp = _toShort(7); // 0x8000 if not available
}
EMS_Boiler.flameCurr = _toShort(19);
// system pressure. FF means missing
// EMS_Boiler.sysPress = _toByte(17); // this is *10
// read the service code / installation status as appears on the display
EMS_Boiler.serviceCodeChar[0] = char(_toByte(4)); // ascii character 1
EMS_Boiler.serviceCodeChar[1] = char(_toByte(5)); // ascii character 2
EMS_Boiler.serviceCodeChar[2] = '\0'; // null terminate string
// read error code
// EMS_Boiler.serviceCode = _toShort(20);
// still to figure out:
// EMS_Boiler.serviceCode
// EMS_Boiler.retTemp
// EMS_Boiler.sysPress
// at this point do a quick check to see if the hot water or heating is active
_checkActive();
@@ -1363,8 +1360,7 @@ void _process_UBAMonitorSlow(_EMS_RxTelegram * EMS_RxTelegram) {
EMS_Boiler.extTemp = _toShort(0);
}
EMS_Boiler.curFlowTemp = _toShort(2);
EMS_Boiler.boilTemp = _toShort(2); // 0x8000 if not available
EMS_Boiler.pumpMod = _toByte(9);
EMS_Boiler.burnStarts = _toLong(10);
EMS_Boiler.burnWorkMin = _toLong(13);

View File

@@ -52,9 +52,6 @@
</li>
</ul>
</li>
<li>
<a href="#" id="eventlog"><i class="glyphicon glyphicon-transfer"></i>Event Log</a>
</li>
<li>
<a href="#" id="backup"><i class="glyphicon glyphicon-floppy-disk"></i>Backup & Restore</a>
</li>

View File

@@ -119,7 +119,7 @@
<div class="row form-group">
<label class="col-xs-3">Event Logging<i style="margin-left: 10px;" class="glyphicon glyphicon-info-sign"
aria-hidden="true" data-toggle="popover" data-trigger="hover" data-placement="right"
data-content="Enabling logging of all events to the device's storage"></i></label>
data-content="Enabling logging of all events to a remote SysLog"></i></label>
<div class="col-xs-9">
<form>
<label class="radio-inline">
@@ -142,32 +142,6 @@
<br>
</div>
<div id="eventcontent">
<div class="text-center" id="loading-img">
<h5>Loading Logs. Please wait...<span id="loadpages"></span></h5>
<br>
</div>
<div>
<br>
<legend>Event Log</legend>
<h6 class="text-muted">Dates shown in () represent elapsed time in seconds when NTP Time is disabled</h6>
<div id="logevents" class="label label-danger">Event Logging has been disabled. See Settings->General Settings.
</div>
<br>
<div class="panel panel-default">
<div>
<table id="eventtable" class="table" data-paging="true" data-filtering="true" data-sorting="true"
data-editing="false" data-state="true"></table>
</div>
</div>
<button onclick="clearevent()" class="btn btn-primary btn-sm">Clear Log</button>
<div style="clear:both;">
<br>
<br>
</div>
</div>
</div>
<div id="mqttcontent">
<br>
<legend>MQTT Settings</legend>
@@ -386,14 +360,6 @@
</div>
</div>
<div class="row form-group">
<label class="col-xs-3">Browser Time</label>
<span id="rtc" class="col-xs-9 col-md-5"></span>
<div class="col-xs-3">
<button onclick="syncBrowserTime()" class="btn btn-info btn-sm">Sync Browser Time to Device</button>
</div>
</div>
<div class="row form-group">
<label class="col-xs-3">NTP<i style="margin-left: 10px;" class="glyphicon glyphicon-info-sign"
aria-hidden="true" data-toggle="popover" data-trigger="hover" data-placement="right"

View File

@@ -28,30 +28,12 @@ var nextIsNotJson = false;
var config = {};
function browserTime() {
var d = new Date(0); // The 0 there is the key, which sets the date to the epoch
var c = new Date();
var timestamp = Math.floor((c.getTime() / 1000) + ((c.getTimezoneOffset() * 60) * -1));
d.setUTCSeconds(timestamp);
document.getElementById("rtc").innerHTML = d.toUTCString().slice(0, -3);
}
function deviceTime() {
var t = new Date(0); // The 0 there is the key, which sets the date to the epoch
t.setUTCSeconds(ntpSeconds);
document.getElementById("utc").innerHTML = t.toUTCString().slice(0, -3);
}
function syncBrowserTime() {
var d = new Date();
var timestamp = Math.floor((d.getTime() / 1000));
var datatosend = {};
datatosend.command = "settime";
datatosend.epoch = timestamp;
websock.send(JSON.stringify(datatosend));
$("#ntp").click();
}
function handleNTPON() {
document.getElementById("forcentp").style.display = "block";
}
@@ -360,10 +342,6 @@ function scanWifi() {
}
}
function getEvents() {
websock.send("{\"command\":\"geteventlog\", \"page\":" + page + "}");
}
function isVisible(e) {
return !!(e.offsetWidth || e.offsetHeight || e.getClientRects().length);
}
@@ -382,10 +360,6 @@ function getnextpage(mode) {
}
}
function builddata(obj) {
data = data.concat(obj.list);
}
function colorStatusbar(ref) {
var percentage = ref.style.width.slice(0, -1);
if (percentage > 50) { ref.className = "progress-bar progress-bar-success"; } else if (percentage > 25) { ref.className = "progress-bar progress-bar-warning"; } else { ref.class = "progress-bar progress-bar-danger"; }
@@ -588,87 +562,6 @@ function twoDigits(value) {
return value;
}
function initEventTable() {
var newlist = [];
for (var i = 0; i < data.length; i++) {
newlist[i] = {};
newlist[i].options = {};
newlist[i].value = {};
try {
var dup = JSON.parse(data[i]);
dup.uid = i + 1;
} catch (e) {
var dup = { "uid": i + 1, "type": "ERRO", "src": "SYS", "desc": "Error in log file", "data": data[i], "time": 1 }
}
newlist[i].value = dup;
var c = dup.type;
switch (c) {
case "WARN":
newlist[i].options.classes = "warning";
break;
case "INFO":
newlist[i].options.classes = "info";
break;
case "ERRO":
newlist[i].options.classes = "danger";
break;
default:
break;
}
}
jQuery(function ($) {
window.FooTable.init("#eventtable", {
columns: [{
"name": "uid",
"title": "ID",
"type": "text",
"sorted": true,
"direction": "DESC"
},
{
"name": "type",
"title": "Event Type",
"type": "text"
},
{
"name": "src",
"title": "Source"
},
{
"name": "desc",
"title": "Description"
},
{
"name": "data",
"title": "Additional Data",
"breakpoints": "xs sm"
},
{
"name": "time",
"title": "Date/Time",
"parser": function (value) {
if (value < 1563300000) {
return "(" + value + ")";
} else {
var vuepoch = new Date(value * 1000);
var formatted = vuepoch.getUTCFullYear() +
"-" + twoDigits(vuepoch.getUTCMonth() + 1) +
"-" + twoDigits(vuepoch.getUTCDate()) +
" " + twoDigits(vuepoch.getUTCHours()) +
":" + twoDigits(vuepoch.getUTCMinutes()) +
":" + twoDigits(vuepoch.getUTCSeconds());
return formatted;
}
},
"breakpoints": "xs sm"
}
],
rows: newlist
});
});
}
function initMQTTLogTable() {
var newlist = [];
for (var i = 0; i < ajaxobj.mqttlog.length; i++) {
@@ -732,15 +625,6 @@ function socketMessageListener(evt) {
ajaxobj = obj;
getContent("#custom_statuscontent");
break;
case "eventlist":
haspages = obj.haspages;
if (haspages === 0) {
document.getElementById("loading-img").style.display = "none";
initEventTable();
break;
}
builddata(obj);
break;
case "gettime":
ntpSeconds = obj.epoch;
deviceTime();
@@ -758,26 +642,6 @@ function socketMessageListener(evt) {
break;
}
}
if (obj.hasOwnProperty("resultof")) {
switch (obj.resultof) {
case "eventlist":
if (page < haspages && obj.result === true) {
getnextpage("geteventlog");
} else if (page === haspages) {
initEventTable();
document.getElementById("loading-img").style.display = "none";
}
break;
default:
break;
}
}
}
function clearevent() {
websock.send("{\"command\":\"clearevent\"}");
$("#eventlog").click();
}
function compareDestroy() {
@@ -990,7 +854,6 @@ $("#ntp").click(function () { getContent("#ntpcontent"); return false; });
$("#backup").click(function () { getContent("#backupcontent"); return false; });
$("#reset").click(function () { $("#destroy").modal("show"); return false; });
$("#restart").click(function () { $("#reboot").modal("show"); return false; });
$("#eventlog").click(function () { getContent("#eventcontent"); return false; });
$(".noimp").on("click", function () { $("#noimp").modal("show"); });
$("#update").on("shown.bs.modal", function (e) { getLatestReleaseInfo(); });

View File

@@ -47,18 +47,6 @@ var networks = {
]
}
var eventlog = {
"command": "eventlist",
"page": 1,
"haspages": 1,
"list": [
"{\"type\":\"WARN\",\"src\":\"system\",\"desc\":\"test data\",\"data\":\"Record #1\",\"time\": 1563371160}",
"{\"type\":\"WARN\",\"src\":\"system\",\"desc\":\"test data\",\"data\":\"Record #2\",\"time\":0}",
"{\"type\":\"INFO\",\"src\":\"system\",\"desc\":\"System booted Local Time is 13:02:54 CET\",\"data\":\"\",\"time\":1572613374}",
"{\"type\":\"WARN\",\"src\":\"system\",\"desc\":\"test data\",\"data\":\"Record #3\",\"time\":0}"
]
}
var configfile = {
"command": "configfile",
"network": {
@@ -113,16 +101,6 @@ var custom_configfile = {
}
};
function sendEventLog() {
wss.broadcast(eventlog);
var res = {
"command": "result",
"resultof": "eventlist",
"result": true
};
wss.broadcast(res);
}
function sendStatus() {
var stats = {
"command": "status",
@@ -252,24 +230,10 @@ wss.on('connection', function connection(ws) {
res.epoch = 1572613374; // this is 13:02:54 CET
wss.broadcast(res);
break;
case "settime":
console.log("[INFO] Setting time (fake)");
var res = {};
res.command = "gettime";
res.epoch = Math.floor((new Date).getTime() / 1000);
wss.broadcast(res);
break;
case "getconf":
console.log("[INFO] Sending system configuration file (if set any)");
wss.broadcast(configfile);
break;
case "geteventlog":
console.log("[INFO] Sending eventlog");
sendEventLog();
break;
case "clearevent":
console.log("[INFO] Clearing eventlog");
break;
case "restart":
console.log("[INFO] Restart");
break;