optimizations

This commit is contained in:
proddy
2019-03-19 23:50:19 +01:00
parent ddcee120ed
commit a13e7f177f
5 changed files with 28 additions and 34 deletions

View File

@@ -1191,6 +1191,7 @@ bool MyESP::_fs_loadConfig() {
bool MyESP::fs_saveConfig() { bool MyESP::fs_saveConfig() {
bool ok = true; bool ok = true;
// call any custom functions before handling SPIFFS
if (_ota_pre_callback) { if (_ota_pre_callback) {
(_ota_pre_callback)(); (_ota_pre_callback)();
} }
@@ -1211,35 +1212,31 @@ bool MyESP::fs_saveConfig() {
// if file exists, remove it just to be safe // if file exists, remove it just to be safe
if (SPIFFS.exists(MYEMS_CONFIG_FILE)) { if (SPIFFS.exists(MYEMS_CONFIG_FILE)) {
// delete it
SPIFFS.remove(MYEMS_CONFIG_FILE); SPIFFS.remove(MYEMS_CONFIG_FILE);
} }
// open for writing
File configFile = SPIFFS.open(MYEMS_CONFIG_FILE, "w"); File configFile = SPIFFS.open(MYEMS_CONFIG_FILE, "w");
if (!configFile) { if (!configFile) {
myDebug_P(PSTR("[FS] Failed to open config file for writing")); myDebug_P(PSTR("[FS] Failed to open config file for writing"));
ok = false; return false;
} }
/*
if (ok) {
myDebug_P(PSTR("[FS] Writing config file"));
}
*/
// Serialize JSON to file // Serialize JSON to file
if (serializeJson(json, configFile) == 0) { if (serializeJson(json, configFile) == 0) {
myDebug_P(PSTR("[FS] Failed to write to file")); myDebug_P(PSTR("[FS] Failed to write config file"));
ok = false; ok = false;
} }
configFile.close(); configFile.close();
// call any custom functions before handling SPIFFS
if (_ota_post_callback) { if (_ota_post_callback) {
(_ota_post_callback)(); (_ota_post_callback)();
} }
return ok; return ok; // it worked
} }
// init the SPIFF file system and load the config // init the SPIFF file system and load the config

View File

@@ -1354,7 +1354,7 @@ void setup() {
MQTT_WILL_OFFLINE_PAYLOAD, MQTT_WILL_OFFLINE_PAYLOAD,
MQTTCallback); MQTTCallback);
// OTA callback which is called when OTA is starting // OTA callback which is called when OTA is starting and stopping
myESP.setOTA(OTACallback_pre, OTACallback_post); myESP.setOTA(OTACallback_pre, OTACallback_post);
// custom settings in SPIFFS // custom settings in SPIFFS

View File

@@ -781,7 +781,7 @@ void _ems_processTelegram(_EMS_RxTelegram EMS_RxTelegram) {
// call callback function to process it // call callback function to process it
// as we only handle complete telegrams (not partial) check that the offset is 0 // as we only handle complete telegrams (not partial) check that the offset is 0
if (offset == EMS_ID_NONE) { if (offset == EMS_ID_NONE) {
(void)EMS_Types[i].processType_cb(type, data, EMS_RxTelegram.length - 5); (void)EMS_Types[i].processType_cb(src, data, EMS_RxTelegram.length - 5);
} }
} }
} }
@@ -1247,7 +1247,6 @@ void _process_Version(uint8_t type, uint8_t * data, uint8_t length) {
} }
if (typeFound) { if (typeFound) {
// its a boiler
myDebug("Device found. Model %s with TypeID 0x%02X, Product ID %d, Version %s", myDebug("Device found. Model %s with TypeID 0x%02X, Product ID %d, Version %s",
Other_Types[i].model_string, Other_Types[i].model_string,
Other_Types[i].type_id, Other_Types[i].type_id,
@@ -1272,6 +1271,9 @@ void ems_discoverModels() {
// boiler // boiler
ems_doReadCommand(EMS_TYPE_Version, EMS_Boiler.type_id); // get version details of boiler ems_doReadCommand(EMS_TYPE_Version, EMS_Boiler.type_id); // get version details of boiler
// solar module
ems_doReadCommand(EMS_TYPE_Version, EMS_ID_SM10); // check if there is Solar Module available
// thermostat // thermostat
// if it hasn't been set, auto discover it // if it hasn't been set, auto discover it
if (EMS_Thermostat.type_id == EMS_ID_NONE) { if (EMS_Thermostat.type_id == EMS_ID_NONE) {
@@ -1588,27 +1590,22 @@ void ems_printAllTypes() {
uint8_t i; uint8_t i;
myDebug("\nThese %d boiler type devices are in the library:", _Boiler_Types_max); myDebug("\nThese %d boiler type devices are in the library:", _Boiler_Types_max);
for (i = 0; i < _Boiler_Types_max; i++) { for (i = 0; i < _Boiler_Types_max; i++) {
myDebug(" %s, type ID:0x%02X Product ID:%d", Boiler_Types[i].model_string, Boiler_Types[i].type_id, Boiler_Types[i].product_id); myDebug(" %s, type ID:0x%02X Product ID:%d", Boiler_Types[i].model_string, Boiler_Types[i].type_id, Boiler_Types[i].product_id);
} }
myDebug("\nThese telegram type IDs are recognized for the selected boiler:"); myDebug("\nThese %d EMS devices are in the library:", _Other_Types_max);
for (i = 0; i < _Other_Types_max; i++) {
myDebug(" %s, type ID:0x%02X Product ID:%d", Other_Types[i].model_string, Other_Types[i].type_id, Other_Types[i].product_id);
}
myDebug("\nThese telegram type IDs are recognized for the selected boiler:");
for (i = 0; i < _EMS_Types_max; i++) { for (i = 0; i < _EMS_Types_max; i++) {
if ((EMS_Types[i].model_id == EMS_MODEL_ALL) || (EMS_Types[i].model_id == EMS_MODEL_UBA)) { if ((EMS_Types[i].model_id == EMS_MODEL_ALL) || (EMS_Types[i].model_id == EMS_MODEL_UBA)) {
myDebug(" type %02X (%s)", EMS_Types[i].type, EMS_Types[i].typeString); myDebug(" type %02X (%s)", EMS_Types[i].type, EMS_Types[i].typeString);
} }
} }
myDebug("\nThese telegram type IDs are recognized for other EMS devices:");
for (i = 0; i < _EMS_Types_max; i++) {
if (EMS_Types[i].model_id == EMS_MODEL_OTHER) {
myDebug(" type %02X (%s)", EMS_Types[i].type, EMS_Types[i].typeString);
}
}
myDebug("\nThese %d thermostats models are supported:", _Thermostat_Types_max); myDebug("\nThese %d thermostats models are supported:", _Thermostat_Types_max);
for (i = 0; i < _Thermostat_Types_max; i++) { for (i = 0; i < _Thermostat_Types_max; i++) {
myDebug(" %s, type ID:0x%02X Product ID:%d Read/Write support:%c%c", myDebug(" %s, type ID:0x%02X Product ID:%d Read/Write support:%c%c",

View File

@@ -16,8 +16,7 @@
#define EMS_ID_NONE 0x00 // Fixed - used as a dest in broadcast messages and empty type IDs #define EMS_ID_NONE 0x00 // Fixed - used as a dest in broadcast messages and empty type IDs
#define EMS_ID_ME 0x0B // Fixed - our device, hardcoded as the "Service Key" #define EMS_ID_ME 0x0B // Fixed - our device, hardcoded as the "Service Key"
#define EMS_ID_DEFAULT_BOILER 0x08 #define EMS_ID_DEFAULT_BOILER 0x08
#define EMS_ID_SM10 0x30 // Solar Module SM10
#define EMS_ID_SM10 0x30
#define EMS_MIN_TELEGRAM_LENGTH 6 // minimal length for a validation telegram, including CRC #define EMS_MIN_TELEGRAM_LENGTH 6 // minimal length for a validation telegram, including CRC
@@ -323,4 +322,3 @@ extern _EMS_Sys_Status EMS_Sys_Status;
extern _EMS_Boiler EMS_Boiler; extern _EMS_Boiler EMS_Boiler;
extern _EMS_Thermostat EMS_Thermostat; extern _EMS_Thermostat EMS_Thermostat;
extern _EMS_Other EMS_Other; extern _EMS_Other EMS_Other;

View File

@@ -118,7 +118,7 @@ typedef enum {
// format is MODEL_ID, PRODUCT ID, TYPE_ID, DESCRIPTION // format is MODEL_ID, PRODUCT ID, TYPE_ID, DESCRIPTION
const _Boiler_Type Boiler_Types[] = { const _Boiler_Type Boiler_Types[] = {
{EMS_MODEL_UBA, 72, 0x08, "MC10"}, {EMS_MODEL_UBA, 72, 0x08, "MC10 Module"},
{EMS_MODEL_UBA, 123, 0x08, "Buderus GB172/Nefit Trendline"}, {EMS_MODEL_UBA, 123, 0x08, "Buderus GB172/Nefit Trendline"},
{EMS_MODEL_UBA, 115, 0x08, "Nefit Topline Compact"}, {EMS_MODEL_UBA, 115, 0x08, "Nefit Topline Compact"},
{EMS_MODEL_UBA, 203, 0x08, "Buderus Logamax U122"}, {EMS_MODEL_UBA, 203, 0x08, "Buderus Logamax U122"},
@@ -128,7 +128,9 @@ const _Boiler_Type Boiler_Types[] = {
}; };
// Other EMS devices which are not considered boilers or thermostats // Other EMS devices which are not considered boilers or thermostats
const _Other_Type Other_Types[] = {{EMS_MODEL_OTHER, 251, 0x21, "MM10 Mixer Module"}, // warning, fake product id! const _Other_Type Other_Types[] = {
{EMS_MODEL_OTHER, 251, 0x21, "MM10 Mixer Module"}, // warning, fake product id!
{EMS_MODEL_OTHER, 250, 0x11, "WM10 Switch Module"}, // warning, fake product id! {EMS_MODEL_OTHER, 250, 0x11, "WM10 Switch Module"}, // warning, fake product id!
{EMS_MODEL_OTHER, 68, 0x09, "RFM20 Receiver"}, {EMS_MODEL_OTHER, 68, 0x09, "RFM20 Receiver"},
{EMS_MODEL_OTHER, 190, 0x09, "BC10 Base Controller"}, {EMS_MODEL_OTHER, 190, 0x09, "BC10 Base Controller"},