Skip to content
Merged
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
2 changes: 2 additions & 0 deletions docs/source/Plugin/P037.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ When JSON is enabled, regular MQTT Topics will be processed normally.

The JSON Attribute column, when used, can be used to specify what data element to retrieve from a received JSON payload. If the resulting value is numeric it will be stored to the corresponding variable, and the regular event for that will be generated.

With the extended JSON processing, available in most ESP32 builds, the ``attribute`` to retrieve from the JSON can be longer than the input has space for (20 characters). To allow for longer JSON attributes, the requested JSON attribute can be stored in a String variable, using the ``LetStr`` command, like ``LetStr,timeLeft,printer_data.progress.printTimeLeft``, in f.e. the ``On System#Boot Do`` event handler rule, and then use in this input field like ``[str#timeLeft]``.

When receiving multiple-value attributes, like ``"svalue":"28.1;17.8;2;1010.3;0"``, an index can be appended to the attribute like ``svalue;4`` to get the 4th value, in this example ``1010.3`` (1-based index).

When receiving a JSON payload, an event can (in addition to the standard event when receiving a numeric value) be generated for the received Attribute, or for all attributes if no specific attribute is configured.
Expand Down
6 changes: 6 additions & 0 deletions src/_P037_MQTTImport.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// This task reads data from the MQTT Import input stream and saves the value

/**
* 2026-09-11 tonhuisman: Process variables to allow for longer JSON attribute names
* 2026-08-02 tonhuisman: Add better support for JSON parsing, that handles multiple levels and arrays
* 2025-08-20 tonhuisman: Generate events with numeric values using the configured decimals setting.
* 2025-06-14 tonhuisman: Add support for Custom Value Type per task value
Expand Down Expand Up @@ -555,7 +556,12 @@ boolean Plugin_037(uint8_t function, struct EventStruct *event, String& string)
jsonAttribute.trim();

if (!jsonAttribute.isEmpty()) {
# if FEATURE_STRING_VARIABLES
key = parseTemplate(jsonAttribute); // Process variables to allow for longer JSON attribute names
key.trim(); // The JSON parser is quite picky about extra spaces...
# else // if FEATURE_STRING_VARIABLES
key = jsonAttribute;
# endif // if FEATURE_STRING_VARIABLES

# if FEATURE_JSON_PARSE
Payload = getJsonValue(P037_data->root, key, false);
Expand Down