diff --git a/ui-ngx/src/app/shared/models/converter.models.ts b/ui-ngx/src/app/shared/models/converter.models.ts index 6951ae31c7..5c53483671 100644 --- a/ui-ngx/src/app/shared/models/converter.models.ts +++ b/ui-ngx/src/app/shared/models/converter.models.ts @@ -44,12 +44,14 @@ export const IntegrationJSDefaultConvertersUrl = new Map([ [IntegrationType.OPC_UA, '/assets/converters/tbel-opc-ua-encoder.raw'], [IntegrationType.TTI, '/assets/converters/tbel-tti-encoder.raw'], - [IntegrationType.TTN, '/assets/converters/tbel-ttn-encoder.raw'] + [IntegrationType.TTN, '/assets/converters/tbel-ttn-encoder.raw'], + [IntegrationType.MQTT, '/assets/converters/tbel-mqtt-encoder.raw'] ]) export const IntegrationJSDefaultEncodersUrl = new Map([ [IntegrationType.TTI, '/assets/converters/js-tti-encoder.raw'], - [IntegrationType.TTN, '/assets/converters/js-ttn-encoder.raw'] + [IntegrationType.TTN, '/assets/converters/js-ttn-encoder.raw'], + [IntegrationType.MQTT, '/assets/converters/js-mqtt-encoder.raw'] ]) export const jsDefaultConvertersUrl = new Map([ diff --git a/ui-ngx/src/assets/converters/js-mqtt-encoder.raw b/ui-ngx/src/assets/converters/js-mqtt-encoder.raw new file mode 100644 index 0000000000..28b7157b8f --- /dev/null +++ b/ui-ngx/src/assets/converters/js-mqtt-encoder.raw @@ -0,0 +1,20 @@ +// Encode downlink data from incoming Rule Engine message + +// msg - JSON message payload downlink message json +// msgType - type of message, for ex. 'ATTRIBUTES_UPDATED', 'POST_TELEMETRY_REQUEST', etc. +// metadata - list of key-value pairs with additional data about the message +// integrationMetadata - list of key-value pairs with additional data defined in Integration executing this converter + +/** Encoder **/ + +// Publish the ThingsBoard message as JSON to the device command topic. +// metadata.topic is read by the integration when Downlink topic pattern is ${topic}. +var result = { + contentType: "JSON", + data: JSON.stringify(msg), + metadata: { + topic: metadata['deviceType']+'/'+metadata['deviceName']+'/upload' + } +}; + +return result; diff --git a/ui-ngx/src/assets/converters/tbel-mqtt-encoder.raw b/ui-ngx/src/assets/converters/tbel-mqtt-encoder.raw new file mode 100644 index 0000000000..fae1cff169 --- /dev/null +++ b/ui-ngx/src/assets/converters/tbel-mqtt-encoder.raw @@ -0,0 +1,20 @@ +// Encode downlink data from incoming Rule Engine message + +// msg - JSON message payload downlink message json +// msgType - type of message, for ex. 'ATTRIBUTES_UPDATED', 'POST_TELEMETRY_REQUEST', etc. +// metadata - list of key-value pairs with additional data about the message +// integrationMetadata - list of key-value pairs with additional data defined in Integration executing this converter + +/** Encoder **/ + +// Publish the ThingsBoard message as JSON to the device command topic. +// metadata.topic is read by the integration when Downlink topic pattern is ${topic}. +var result = { + contentType: "JSON", + data: JSON.stringify(msg), + metadata: { + topic: metadata['deviceType'] + '/' + metadata['deviceName'] + '/upload' + } +}; + +return result;