Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Custom-sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Comment thread
chromoxdor marked this conversation as resolved.
Outdated
#ifdef BUILD_GIT
# undef BUILD_GIT
Expand Down
33 changes: 33 additions & 0 deletions src/_P043_ClkOutput.ino
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect this new feature to deserve a mention in the Changelog at the top of _P043_ClkOutput.ino 😉

Original file line number Diff line number Diff line change
Expand Up @@ -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<KeyValueWriter *>(event->Par1);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, please use the already present KeyValueWriter* kvWriter in the EventStruct

if (!taskWriter) break;
taskWriter->write({ F("OnOff"), PCONFIG(6) });

auto timesWriter = taskWriter->createChildArray(F("Times"));
if (!timesWriter) break;

LoadTaskSettings(event->TaskIndex);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure this is needed as the Cache also does quite a lot of checking.
This is potentially quite a resource intensive operation and should only be done when absolutely needed.


const int offset =
(validGpio(CONFIG_PIN1) || (PCONFIG(7) == 1)) ? 1 : 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto for P043_MAX_SETTINGS


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;
}
Expand Down
11 changes: 11 additions & 0 deletions src/src/CustomBuild/define_plugin_sets.h
Original file line number Diff line number Diff line change
Expand Up @@ -4556,4 +4556,15 @@ To create/register a plugin, you have to :
#endif
#endif // if !FEATURE_SPI && !FEATURE_I2C && !FEATURE_MODBUS && !FEATURE_CAN && !FEATURE_WRMBUS && !FEATURE_WIMBUS


#ifndef FEATURE_P043_CLK_TIMES_JSON
#define FEATURE_P043_CLK_TIMES_JSON (defined(PLUGIN_BUILD_MAX_ESP32) ? 1 : 0)
Comment thread
chromoxdor marked this conversation as resolved.
Outdated
#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
Comment thread
chromoxdor marked this conversation as resolved.
Outdated
#endif // if defined(FEATURE_P043_CLK_TIMES_JSON) && defined(USES_P043)

#endif // CUSTOMBUILD_DEFINE_PLUGIN_SETS_H
3 changes: 3 additions & 0 deletions src/src/DataTypes/ESPEasy_plugin_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/src/Globals/Plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions src/src/WebServer/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,15 @@ void handle_json()
}
}

# if FEATURE_ADDITIONAL_JSON_FROM_PLUGIN

EventStruct TempEvent(TaskIndex);
TempEvent.Par1 = reinterpret_cast<intptr_t>(taskWriter.get());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't do nasty things like this. There is a proper pointer in the EventStruct for this.

KeyValueWriter* kvWriter = nullptr;


String dummy;
PluginCall(PLUGIN_TASK_JSON, &TempEvent, dummy);
# endif // FEATURE_ADDITIONAL_JSON_FROM_PLUGIN

#if FEATURE_PLUGIN_STATS && FEATURE_CHART_JS

if (showPluginStats && Device[DeviceIndex].PluginStats) {
Expand Down