From cd2e4b5c88630b524d4b054d4abc40cf30dbe1fe Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Wed, 8 Apr 2026 00:29:56 +0200 Subject: [PATCH 1/5] [P043] [JSON] Add feature to output times in JSON --- src/src/CustomBuild/define_plugin_sets.h | 5 +++++ src/src/WebServer/JSON.cpp | 25 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/src/CustomBuild/define_plugin_sets.h b/src/src/CustomBuild/define_plugin_sets.h index 04748d003d..a25334e7eb 100644 --- a/src/src/CustomBuild/define_plugin_sets.h +++ b/src/src/CustomBuild/define_plugin_sets.h @@ -4556,4 +4556,9 @@ To create/register a plugin, you have to : #endif #endif // if !FEATURE_SPI && !FEATURE_I2C && !FEATURE_MODBUS && !FEATURE_CAN && !FEATURE_WRMBUS && !FEATURE_WIMBUS + +#if defined(FEATURE_P043_CLK_TIMES_JSON) && !defined(USES_P043) + #undef FEATURE_P043_CLK_TIMES_JSON +#endif + #endif // CUSTOMBUILD_DEFINE_PLUGIN_SETS_H diff --git a/src/src/WebServer/JSON.cpp b/src/src/WebServer/JSON.cpp index 90eb4ed797..7e43a4afbc 100644 --- a/src/src/WebServer/JSON.cpp +++ b/src/src/WebServer/JSON.cpp @@ -575,6 +575,31 @@ void handle_json() } } +#if FEATURE_P043_CLK_TIMES_JSON + if (Settings.getPluginID_for_task(TaskIndex).value == 43) { + taskWriter->write({ (F("OnOff")), Settings.TaskDevicePluginConfig[TaskIndex][(6)] }); + auto timesWriter = taskWriter->createChildArray(F("Times")); + + if (timesWriter) + { + int count = Settings.TaskDevicePluginConfig[TaskIndex][7]; + const int16_t offset = (validGpio(Settings.TaskDevicePin[1][TaskIndex]) || + (count == 1)) ? 1 : 0; + + for (int x = 0; x < count; x++) { + auto timeWriter = timesWriter->createChild(); + long value = Cache.getTaskDevicePluginConfigLong(TaskIndex, x); + int val = ExtraTaskSettings.TaskDevicePluginConfig[x] - offset; + + if (timeWriter) { + timeWriter->write({ F("Time"), timeLong2String(value) }); + timeWriter->write({ F("Value"), val }); + } + } + } + } +#endif // FEATURE_P043_CLK_TIMES_JSON + #if FEATURE_PLUGIN_STATS && FEATURE_CHART_JS if (showPluginStats && Device[DeviceIndex].PluginStats) { From e5d85ac35763996e2a3d5f4e170d4103f9ce34ce Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Wed, 8 Apr 2026 00:36:40 +0200 Subject: [PATCH 2/5] [P043] [JSON] Update JSON.cpp --- src/src/WebServer/JSON.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/src/WebServer/JSON.cpp b/src/src/WebServer/JSON.cpp index 7e43a4afbc..7b8ea2908c 100644 --- a/src/src/WebServer/JSON.cpp +++ b/src/src/WebServer/JSON.cpp @@ -582,8 +582,8 @@ void handle_json() if (timesWriter) { - int count = Settings.TaskDevicePluginConfig[TaskIndex][7]; - const int16_t offset = (validGpio(Settings.TaskDevicePin[1][TaskIndex]) || + const int count = Settings.TaskDevicePluginConfig[TaskIndex][7]; + const int offset = (validGpio(Settings.TaskDevicePin[1][TaskIndex]) || (count == 1)) ? 1 : 0; for (int x = 0; x < count; x++) { From f1bb011ad3ab39ccf3579e1016d997c0cebb04dc Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Wed, 8 Apr 2026 15:02:06 +0200 Subject: [PATCH 3/5] [P043] [JSON] Adding suggested changes --- src/Custom-sample.h | 1 + src/_P043_ClkOutput.ino | 33 ++++++++++++++++++++ src/src/CustomBuild/define_plugin_sets.h | 10 ++++-- src/src/DataTypes/ESPEasy_plugin_functions.h | 3 ++ src/src/Globals/Plugins.cpp | 3 ++ src/src/WebServer/JSON.cpp | 32 +++++-------------- 6 files changed, 56 insertions(+), 26 deletions(-) diff --git a/src/Custom-sample.h b/src/Custom-sample.h index 11bf1af843..04b71ebb30 100644 --- a/src/Custom-sample.h +++ b/src/Custom-sample.h @@ -30,6 +30,7 @@ #define FEATURE_JSON_EVENT 0 // Generates an event with the values of a JSON repsonse of an HTTP call. Keys are stored in json.keys one key per line (e.g.: Body.Data.DAY_ENERGY.Values.1) // #define FEATURE_SD 1 // Enable SD card support // #define FEATURE_DOWNLOAD 1 // Enable downloading a file from an url +#define FEATURE_P043_CLK_TIMES_JSON 1 // When defined, Plugin 043 will add the time settings to the JSON output #ifdef BUILD_GIT # undef BUILD_GIT diff --git a/src/_P043_ClkOutput.ino b/src/_P043_ClkOutput.ino index c9c60b330f..976f7c0b6c 100644 --- a/src/_P043_ClkOutput.ino +++ b/src/_P043_ClkOutput.ino @@ -366,6 +366,39 @@ boolean Plugin_043(uint8_t function, struct EventStruct *event, String& string) # undef P043_GETVALUE_LENGTH break; } + + #if FEATURE_P043_CLK_TIMES_JSON + case PLUGIN_TASK_JSON: + { + addLog(LOG_LEVEL_INFO, F("P043 JSON CALLED")); + auto taskWriter = reinterpret_cast(event->Par1); + if (!taskWriter) break; + taskWriter->write({ F("OnOff"), PCONFIG(6) }); + + auto timesWriter = taskWriter->createChildArray(F("Times")); + if (!timesWriter) break; + + LoadTaskSettings(event->TaskIndex); + + const int offset = + (validGpio(CONFIG_PIN1) || (PCONFIG(7) == 1)) ? 1 : 0; + + for (int x = 0; x < PCONFIG(7); x++) { + + auto timeWriter = timesWriter->createChild(); + if (!timeWriter) continue; + + long value = Cache.getTaskDevicePluginConfigLong(event->TaskIndex, x); + int val = ExtraTaskSettings.TaskDevicePluginConfig[x] - offset; + + timeWriter->write({ F("Time"), timeLong2String(value) }); + timeWriter->write({ F("Value"), val }); + } + + success = true; + break; + } + #endif // FEATURE_P043_CLK_TIMES_JSON } return success; } diff --git a/src/src/CustomBuild/define_plugin_sets.h b/src/src/CustomBuild/define_plugin_sets.h index a25334e7eb..c68d19cf71 100644 --- a/src/src/CustomBuild/define_plugin_sets.h +++ b/src/src/CustomBuild/define_plugin_sets.h @@ -4557,8 +4557,14 @@ To create/register a plugin, you have to : #endif // if !FEATURE_SPI && !FEATURE_I2C && !FEATURE_MODBUS && !FEATURE_CAN && !FEATURE_WRMBUS && !FEATURE_WIMBUS -#if defined(FEATURE_P043_CLK_TIMES_JSON) && !defined(USES_P043) - #undef FEATURE_P043_CLK_TIMES_JSON +#ifndef FEATURE_P043_CLK_TIMES_JSON + #define FEATURE_P043_CLK_TIMES_JSON (defined(PLUGIN_BUILD_MAX_ESP32) ? 1 : 0) #endif +#if defined(FEATURE_P043_CLK_TIMES_JSON) && defined(USES_P043) + # ifndef FEATURE_ADDITIONAL_JSON_FROM_PLUGIN + # define FEATURE_ADDITIONAL_JSON_FROM_PLUGIN 1 + # endif +#endif // if defined(FEATURE_P043_CLK_TIMES_JSON) && defined(USES_P043) + #endif // CUSTOMBUILD_DEFINE_PLUGIN_SETS_H diff --git a/src/src/DataTypes/ESPEasy_plugin_functions.h b/src/src/DataTypes/ESPEasy_plugin_functions.h index 7090c90ecb..fbd1419eef 100644 --- a/src/src/DataTypes/ESPEasy_plugin_functions.h +++ b/src/src/DataTypes/ESPEasy_plugin_functions.h @@ -38,6 +38,9 @@ enum PluginFunctions_e { PLUGIN_GET_DEVICEGPIONAMES, // Allow for specific formatting of the label for standard pin configuration (e.g. "GPIO <- TX") PLUGIN_EXIT, // Called when a task no longer is enabled (or deleted) PLUGIN_GET_CONFIG_VALUE, // Similar to PLUGIN_WRITE, but meant to fetch some information. Must return success = true when it + #if FEATURE_ADDITIONAL_JSON_FROM_PLUGIN + PLUGIN_TASK_JSON, // Called when generating the JSON for a task, allowing the plugin to add some custom values to the JSON output for that task. + #endif //FEATURE_ADDITIONAL_JSON_FROM_PLUGIN // can handle the command. Can also be used to access extra unused task values. // PLUGIN_UNCONDITIONAL_POLL , // Used to be called 10x per sec, but no longer used as GPIO related plugins now use a different // technique. diff --git a/src/src/Globals/Plugins.cpp b/src/src/Globals/Plugins.cpp index dc6e7e542d..c22f09ad25 100644 --- a/src/src/Globals/Plugins.cpp +++ b/src/src/Globals/Plugins.cpp @@ -992,6 +992,9 @@ bool PluginCall(uint8_t Function, struct EventStruct *event, String& str) // Call to specific task not interacting with hardware case PLUGIN_GET_CONFIG_VALUE: +#if FEATURE_ADDITIONAL_JSON_FROM_PLUGIN + case PLUGIN_TASK_JSON: +#endif //FEATURE_ADDITIONAL_JSON_FROM_PLUGIN case PLUGIN_GET_DEVICEVALUENAMES: case PLUGIN_GET_DEVICEGPIONAMES: case PLUGIN_WEBFORM_SAVE: diff --git a/src/src/WebServer/JSON.cpp b/src/src/WebServer/JSON.cpp index 7b8ea2908c..b4cbcbf6c1 100644 --- a/src/src/WebServer/JSON.cpp +++ b/src/src/WebServer/JSON.cpp @@ -575,30 +575,14 @@ void handle_json() } } -#if FEATURE_P043_CLK_TIMES_JSON - if (Settings.getPluginID_for_task(TaskIndex).value == 43) { - taskWriter->write({ (F("OnOff")), Settings.TaskDevicePluginConfig[TaskIndex][(6)] }); - auto timesWriter = taskWriter->createChildArray(F("Times")); - - if (timesWriter) - { - const int count = Settings.TaskDevicePluginConfig[TaskIndex][7]; - const int offset = (validGpio(Settings.TaskDevicePin[1][TaskIndex]) || - (count == 1)) ? 1 : 0; - - for (int x = 0; x < count; x++) { - auto timeWriter = timesWriter->createChild(); - long value = Cache.getTaskDevicePluginConfigLong(TaskIndex, x); - int val = ExtraTaskSettings.TaskDevicePluginConfig[x] - offset; - - if (timeWriter) { - timeWriter->write({ F("Time"), timeLong2String(value) }); - timeWriter->write({ F("Value"), val }); - } - } - } - } -#endif // FEATURE_P043_CLK_TIMES_JSON +# if FEATURE_ADDITIONAL_JSON_FROM_PLUGIN + + EventStruct TempEvent(TaskIndex); + TempEvent.Par1 = reinterpret_cast(taskWriter.get()); + + String dummy; + PluginCall(PLUGIN_TASK_JSON, &TempEvent, dummy); +# endif // FEATURE_ADDITIONAL_JSON_FROM_PLUGIN #if FEATURE_PLUGIN_STATS && FEATURE_CHART_JS From e72c8b77abb74a5162f4782809fddb5f25a6ed44 Mon Sep 17 00:00:00 2001 From: chromoxdor <33860956+chromoxdor@users.noreply.github.com> Date: Fri, 10 Apr 2026 21:37:55 +0200 Subject: [PATCH 4/5] [P043] [JSON] Adding suggested changes 2 --- src/Custom-sample.h | 2 +- src/src/CustomBuild/define_plugin_sets.h | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Custom-sample.h b/src/Custom-sample.h index 04b71ebb30..06147dee7f 100644 --- a/src/Custom-sample.h +++ b/src/Custom-sample.h @@ -30,7 +30,7 @@ #define FEATURE_JSON_EVENT 0 // Generates an event with the values of a JSON repsonse of an HTTP call. Keys are stored in json.keys one key per line (e.g.: Body.Data.DAY_ENERGY.Values.1) // #define FEATURE_SD 1 // Enable SD card support // #define FEATURE_DOWNLOAD 1 // Enable downloading a file from an url -#define FEATURE_P043_CLK_TIMES_JSON 1 // When defined, Plugin 043 will add the time settings to the JSON output +//#define FEATURE_P043_CLK_TIMES_JSON 1 // When defined, Plugin 043 will add the time settings to the JSON output #ifdef BUILD_GIT # undef BUILD_GIT diff --git a/src/src/CustomBuild/define_plugin_sets.h b/src/src/CustomBuild/define_plugin_sets.h index c68d19cf71..4d6cfed82d 100644 --- a/src/src/CustomBuild/define_plugin_sets.h +++ b/src/src/CustomBuild/define_plugin_sets.h @@ -1300,6 +1300,9 @@ To create/register a plugin, you have to : // FIXME TD-er: Should this be enabled on non-Custom builds??? #define FEATURE_CUSTOM_PROVISIONING 1 + #ifdef USES_P043 + #define FEATURE_P043_CLK_TIMES_JSON 1 + #endif // See also PLUGIN_SET_MAX section at end, to include any disabled plugins from other definitions // See also PLUGIN_SET_COLLECTION_ESP32 section at end, @@ -4556,15 +4559,20 @@ To create/register a plugin, you have to : #endif #endif // if !FEATURE_SPI && !FEATURE_I2C && !FEATURE_MODBUS && !FEATURE_CAN && !FEATURE_WRMBUS && !FEATURE_WIMBUS - +//-------------------Additional JSON per Plugin Section---------------- #ifndef FEATURE_P043_CLK_TIMES_JSON - #define FEATURE_P043_CLK_TIMES_JSON (defined(PLUGIN_BUILD_MAX_ESP32) ? 1 : 0) + #define FEATURE_P043_CLK_TIMES_JSON 0 #endif - -#if defined(FEATURE_P043_CLK_TIMES_JSON) && defined(USES_P043) - # ifndef FEATURE_ADDITIONAL_JSON_FROM_PLUGIN - # define FEATURE_ADDITIONAL_JSON_FROM_PLUGIN 1 - # endif -#endif // if defined(FEATURE_P043_CLK_TIMES_JSON) && defined(USES_P043) +#if FEATURE_P043_CLK_TIMES_JSON && !defined(USES_P043) + #undef FEATURE_P043_CLK_TIMES_JSON + #define FEATURE_P043_CLK_TIMES_JSON 0 +#endif +#if FEATURE_P043_CLK_TIMES_JSON + #define FEATURE_ADDITIONAL_JSON_FROM_PLUGIN 1 +#endif +#ifndef FEATURE_ADDITIONAL_JSON_FROM_PLUGIN + #define FEATURE_ADDITIONAL_JSON_FROM_PLUGIN 0 +#endif +//---------------End of Additional JSON per Plugin Section------------- #endif // CUSTOMBUILD_DEFINE_PLUGIN_SETS_H From fc1ad04b9f78c70a0af12284ef5b24f291afb3d3 Mon Sep 17 00:00:00 2001 From: TD-er Date: Sat, 18 Apr 2026 22:53:33 +0200 Subject: [PATCH 5/5] [P043] Use proper kvWriter member of event --- src/_P043_ClkOutput.ino | 12 +++++++----- src/src/WebServer/JSON.cpp | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/_P043_ClkOutput.ino b/src/_P043_ClkOutput.ino index 976f7c0b6c..6070fbb961 100644 --- a/src/_P043_ClkOutput.ino +++ b/src/_P043_ClkOutput.ino @@ -371,14 +371,16 @@ boolean Plugin_043(uint8_t function, struct EventStruct *event, String& string) case PLUGIN_TASK_JSON: { addLog(LOG_LEVEL_INFO, F("P043 JSON CALLED")); - auto taskWriter = reinterpret_cast(event->Par1); - if (!taskWriter) break; - taskWriter->write({ F("OnOff"), PCONFIG(6) }); - auto timesWriter = taskWriter->createChildArray(F("Times")); + if (!event->kvWriter) break; + event->kvWriter->write({ F("OnOff"), PCONFIG(6) }); + + auto timesWriter = event->kvWriter->createChildArray(F("Times")); if (!timesWriter) break; - LoadTaskSettings(event->TaskIndex); + if (ExtraTaskSettings.TaskIndex != event->TaskIndex) { + LoadTaskSettings(event->TaskIndex); + } const int offset = (validGpio(CONFIG_PIN1) || (PCONFIG(7) == 1)) ? 1 : 0; diff --git a/src/src/WebServer/JSON.cpp b/src/src/WebServer/JSON.cpp index b4cbcbf6c1..7771f0a743 100644 --- a/src/src/WebServer/JSON.cpp +++ b/src/src/WebServer/JSON.cpp @@ -578,7 +578,7 @@ void handle_json() # if FEATURE_ADDITIONAL_JSON_FROM_PLUGIN EventStruct TempEvent(TaskIndex); - TempEvent.Par1 = reinterpret_cast(taskWriter.get()); + TempEvent.kvWriter = taskWriter.get(); String dummy; PluginCall(PLUGIN_TASK_JSON, &TempEvent, dummy);