diff --git a/lib/MyESP/MyESP.cpp b/lib/MyESP/MyESP.cpp index a42996251..bddcf6e45 100644 --- a/lib/MyESP/MyESP.cpp +++ b/lib/MyESP/MyESP.cpp @@ -1191,6 +1191,7 @@ bool MyESP::_fs_loadConfig() { bool MyESP::fs_saveConfig() { bool ok = true; + // call any custom functions before handling SPIFFS if (_ota_pre_callback) { (_ota_pre_callback)(); } @@ -1211,35 +1212,31 @@ bool MyESP::fs_saveConfig() { // if file exists, remove it just to be safe if (SPIFFS.exists(MYEMS_CONFIG_FILE)) { - // delete it SPIFFS.remove(MYEMS_CONFIG_FILE); } + // open for writing File configFile = SPIFFS.open(MYEMS_CONFIG_FILE, "w"); if (!configFile) { 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 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; } configFile.close(); + // call any custom functions before handling SPIFFS if (_ota_post_callback) { (_ota_post_callback)(); } - return ok; + return ok; // it worked } // init the SPIFF file system and load the config diff --git a/src/ems-esp.ino b/src/ems-esp.ino index b663813ed..e4d1cd974 100644 --- a/src/ems-esp.ino +++ b/src/ems-esp.ino @@ -1354,7 +1354,7 @@ void setup() { MQTT_WILL_OFFLINE_PAYLOAD, 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); // custom settings in SPIFFS diff --git a/src/ems.cpp b/src/ems.cpp index 46cc614f1..666b80454 100644 --- a/src/ems.cpp +++ b/src/ems.cpp @@ -781,7 +781,7 @@ void _ems_processTelegram(_EMS_RxTelegram EMS_RxTelegram) { // call callback function to process it // as we only handle complete telegrams (not partial) check that the offset is 0 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) { - // its a boiler myDebug("Device found. Model %s with TypeID 0x%02X, Product ID %d, Version %s", Other_Types[i].model_string, Other_Types[i].type_id, @@ -1272,6 +1271,9 @@ void ems_discoverModels() { // 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 // if it hasn't been set, auto discover it if (EMS_Thermostat.type_id == EMS_ID_NONE) { @@ -1588,23 +1590,18 @@ void ems_printAllTypes() { uint8_t i; myDebug("\nThese %d boiler type devices are in the library:", _Boiler_Types_max); - 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("\nThese telegram type IDs are recognized for the selected boiler:"); - - 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)) { - myDebug(" type %02X (%s)", EMS_Types[i].type, EMS_Types[i].typeString); - } + 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 other EMS devices:"); - + myDebug("\nThese telegram type IDs are recognized for the selected boiler:"); for (i = 0; i < _EMS_Types_max; i++) { - if (EMS_Types[i].model_id == EMS_MODEL_OTHER) { + 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); } } diff --git a/src/ems.h b/src/ems.h index 581d297f5..04db7eaca 100644 --- a/src/ems.h +++ b/src/ems.h @@ -16,8 +16,7 @@ #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_DEFAULT_BOILER 0x08 - -#define EMS_ID_SM10 0x30 +#define EMS_ID_SM10 0x30 // Solar Module SM10 #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_Thermostat EMS_Thermostat; extern _EMS_Other EMS_Other; - diff --git a/src/ems_devices.h b/src/ems_devices.h index 7159071e7..84f650a3a 100644 --- a/src/ems_devices.h +++ b/src/ems_devices.h @@ -118,7 +118,7 @@ typedef enum { // format is MODEL_ID, PRODUCT ID, TYPE_ID, DESCRIPTION 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, 115, 0x08, "Nefit Topline Compact"}, {EMS_MODEL_UBA, 203, 0x08, "Buderus Logamax U122"}, @@ -128,14 +128,16 @@ const _Boiler_Type Boiler_Types[] = { }; // 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! - {EMS_MODEL_OTHER, 250, 0x11, "WM10 Switch Module"}, // warning, fake product id! - {EMS_MODEL_OTHER, 68, 0x09, "RFM20 Receiver"}, - {EMS_MODEL_OTHER, 190, 0x09, "BC10 Base Controller"}, - {EMS_MODEL_OTHER, 114, 0x09, "BC10 Base Controller"}, - {EMS_MODEL_OTHER, 125, 0x09, "BC25 Base Controller"}, - {EMS_MODEL_OTHER, 205, 0x02, "Nefit Moduline Easy Connect"}, - {EMS_MODEL_OTHER, 73, 0x02, "SM10 Solar Module"} +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, 68, 0x09, "RFM20 Receiver"}, + {EMS_MODEL_OTHER, 190, 0x09, "BC10 Base Controller"}, + {EMS_MODEL_OTHER, 114, 0x09, "BC10 Base Controller"}, + {EMS_MODEL_OTHER, 125, 0x09, "BC25 Base Controller"}, + {EMS_MODEL_OTHER, 205, 0x02, "Nefit Moduline Easy Connect"}, + {EMS_MODEL_OTHER, 73, 0x02, "SM10 Solar Module"} };