Skip to content
Open
Show file tree
Hide file tree
Changes from all 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

#ifdef BUILD_GIT
# undef BUILD_GIT
Expand Down
35 changes: 35 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,41 @@ 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"));

if (!event->kvWriter) break;
event->kvWriter->write({ F("OnOff"), PCONFIG(6) });
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.

There is a #define P043_SIMPLE_VALUE PCONFIG(6) at the top of the file for this setting, so that name should (better) be used here


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

if (ExtraTaskSettings.TaskIndex != event->TaskIndex) {
LoadTaskSettings(event->TaskIndex);
}

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
19 changes: 19 additions & 0 deletions src/src/CustomBuild/define_plugin_sets.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -4559,4 +4562,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 0
#endif
#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
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.kvWriter = taskWriter.get();

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