diff --git a/ui-ngx/src/app/shared/models/converter.models.ts b/ui-ngx/src/app/shared/models/converter.models.ts index d088b86539..fc9d2a985e 100644 --- a/ui-ngx/src/app/shared/models/converter.models.ts +++ b/ui-ngx/src/app/shared/models/converter.models.ts @@ -46,14 +46,16 @@ export const IntegrationTbelDefaultEncodersUrl = new Map([ [IntegrationType.TTI, '/assets/converters/js-tti-encoder.raw'], [IntegrationType.TTN, '/assets/converters/js-ttn-encoder.raw'], [IntegrationType.MQTT, '/assets/converters/js-mqtt-encoder.raw'], - [IntegrationType.CHIRPSTACK, '/assets/converters/js-chirpstack-encoder.raw'] + [IntegrationType.CHIRPSTACK, '/assets/converters/js-chirpstack-encoder.raw'], + [IntegrationType.LORIOT, '/assets/converters/js-loriot-encoder.raw'] ]) export const jsDefaultConvertersUrl = new Map([ diff --git a/ui-ngx/src/assets/converters/js-loriot-decoder.raw b/ui-ngx/src/assets/converters/js-loriot-decoder.raw index 8021611b56..1e18fbe019 100644 --- a/ui-ngx/src/assets/converters/js-loriot-decoder.raw +++ b/ui-ngx/src/assets/converters/js-loriot-decoder.raw @@ -52,6 +52,13 @@ function decodePayload(input) { // }; } +// Process only LORIOT uplink messages (cmd == 'rx'). +// Skip downlink confirmations (e.g. cmd == 'txd') and other events so they +// are not stored as telemetry. Returning an empty array yields no uplink data. +if (metadata.cmd != 'rx') { + return []; +} + var result = decodePayload(payload); // Uncomment this code block to overwrite values set in the main configuration window. Useful if you extract device/asset/customer/group names from the payload; // result.type = 'DEVICE'; // Entity type allows you to choose type of created entity. Can be 'DEVICE' or 'ASSET'. diff --git a/ui-ngx/src/assets/converters/js-loriot-encoder.raw b/ui-ngx/src/assets/converters/js-loriot-encoder.raw new file mode 100644 index 0000000000..5c58ffbe54 --- /dev/null +++ b/ui-ngx/src/assets/converters/js-loriot-encoder.raw @@ -0,0 +1,30 @@ +// Encode downlink data from incoming Rule Engine message. +// msg - JSON message payload (e.g. { "state": "on" }) +// msgType - message type, e.g. 'ATTRIBUTES_UPDATED' +// metadata - enriched by the Originator attributes node with device client attributes. +// ThingsBoard prefixes client-scope attributes with "cs_": +// metadata.cs_eui — LORIOT device EUI stored on first uplink (e.g. "466ECD510CF7B021") +// metadata.cs_fPort — LoRaWAN frame port stored on first uplink (e.g. "1") + +var eui = metadata.cs_eui; + +// Default port to 1 when the device fPort attribute is missing or empty. +var port = (metadata.cs_fPort != null && metadata.cs_fPort != '') + ? parseInt(metadata.cs_fPort) + : 1; + +var result = { + // Downlink data content type: JSON, TEXT, or BINARY (base64 format). + contentType: "JSON", + + // Downlink data — serialise the full message payload as a JSON string. + data: JSON.stringify(msg), + + // Metadata required by LORIOT for downlink delivery. + metadata: { + "EUI": eui, + "port": port + } +}; + +return result; diff --git a/ui-ngx/src/assets/converters/tbel-loriot-decoder.raw b/ui-ngx/src/assets/converters/tbel-loriot-decoder.raw index 5628a2f6c4..ab2dfa83b4 100644 --- a/ui-ngx/src/assets/converters/tbel-loriot-decoder.raw +++ b/ui-ngx/src/assets/converters/tbel-loriot-decoder.raw @@ -52,6 +52,13 @@ function decodePayload(input) { // }; } +// Process only LORIOT uplink messages (cmd == 'rx'). +// Skip downlink confirmations (e.g. cmd == 'txd') and other events so they +// are not stored as telemetry. Returning an empty array yields no uplink data. +if (metadata.cmd != 'rx') { + return []; +} + var result = decodePayload(payload); // Uncomment this code block to overwrite values set in the main configuration window. Useful if you extract device/asset/customer/group names from the payload; // result.type = 'DEVICE'; // Entity type allows you to choose type of created entity. Can be 'DEVICE' or 'ASSET'. diff --git a/ui-ngx/src/assets/converters/tbel-loriot-encoder.raw b/ui-ngx/src/assets/converters/tbel-loriot-encoder.raw new file mode 100644 index 0000000000..5c58ffbe54 --- /dev/null +++ b/ui-ngx/src/assets/converters/tbel-loriot-encoder.raw @@ -0,0 +1,30 @@ +// Encode downlink data from incoming Rule Engine message. +// msg - JSON message payload (e.g. { "state": "on" }) +// msgType - message type, e.g. 'ATTRIBUTES_UPDATED' +// metadata - enriched by the Originator attributes node with device client attributes. +// ThingsBoard prefixes client-scope attributes with "cs_": +// metadata.cs_eui — LORIOT device EUI stored on first uplink (e.g. "466ECD510CF7B021") +// metadata.cs_fPort — LoRaWAN frame port stored on first uplink (e.g. "1") + +var eui = metadata.cs_eui; + +// Default port to 1 when the device fPort attribute is missing or empty. +var port = (metadata.cs_fPort != null && metadata.cs_fPort != '') + ? parseInt(metadata.cs_fPort) + : 1; + +var result = { + // Downlink data content type: JSON, TEXT, or BINARY (base64 format). + contentType: "JSON", + + // Downlink data — serialise the full message payload as a JSON string. + data: JSON.stringify(msg), + + // Metadata required by LORIOT for downlink delivery. + metadata: { + "EUI": eui, + "port": port + } +}; + +return result;