Browse Source

fixed pr comments

pull/16300/head
dashevchenko 5 months ago
committed by Viacheslav Klimov
parent
commit
2612e44bd6
Failed to extract signature
  1. 31
      ui-ngx/src/app/shared/models/converter.models.ts
  2. 11
      ui-ngx/src/assets/converters/js-chirpstack-encoder.raw
  3. 4
      ui-ngx/src/assets/converters/js-mqtt-encoder.raw
  4. 14
      ui-ngx/src/assets/converters/js-ttn-tti-encoder.raw
  5. 11
      ui-ngx/src/assets/converters/tbel-chirpstack-encoder.raw
  6. 2
      ui-ngx/src/assets/converters/tbel-mqtt-encoder.raw
  7. 38
      ui-ngx/src/assets/converters/tbel-tti-encoder.raw
  8. 38
      ui-ngx/src/assets/converters/tbel-ttn-encoder.raw
  9. 14
      ui-ngx/src/assets/converters/tbel-ttn-tti-encoder.raw

31
ui-ngx/src/app/shared/models/converter.models.ts

@ -43,16 +43,16 @@ export const IntegrationJSDefaultConvertersUrl = new Map<IntegrationType, string
export const IntegrationTbelDefaultEncodersUrl = new Map<IntegrationType, string>([ export const IntegrationTbelDefaultEncodersUrl = new Map<IntegrationType, string>([
[IntegrationType.OPC_UA, '/assets/converters/tbel-opc-ua-encoder.raw'], [IntegrationType.OPC_UA, '/assets/converters/tbel-opc-ua-encoder.raw'],
[IntegrationType.TTI, '/assets/converters/tbel-tti-encoder.raw'], [IntegrationType.TTI, '/assets/converters/tbel-ttn-tti-encoder.raw'],
[IntegrationType.TTN, '/assets/converters/tbel-ttn-encoder.raw'], [IntegrationType.TTN, '/assets/converters/tbel-ttn-tti-encoder.raw'],
[IntegrationType.MQTT, '/assets/converters/tbel-mqtt-encoder.raw'], [IntegrationType.MQTT, '/assets/converters/tbel-mqtt-encoder.raw'],
[IntegrationType.CHIRPSTACK, '/assets/converters/tbel-chirpstack-encoder.raw'], [IntegrationType.CHIRPSTACK, '/assets/converters/tbel-chirpstack-encoder.raw'],
[IntegrationType.LORIOT, '/assets/converters/tbel-loriot-encoder.raw'] [IntegrationType.LORIOT, '/assets/converters/tbel-loriot-encoder.raw']
]) ])
export const IntegrationJSDefaultEncodersUrl = new Map<IntegrationType, string>([ export const IntegrationJSDefaultEncodersUrl = new Map<IntegrationType, string>([
[IntegrationType.TTI, '/assets/converters/js-tti-encoder.raw'], [IntegrationType.TTI, '/assets/converters/js-ttn-tti-encoder.raw'],
[IntegrationType.TTN, '/assets/converters/js-ttn-encoder.raw'], [IntegrationType.TTN, '/assets/converters/js-ttn-tti-encoder.raw'],
[IntegrationType.MQTT, '/assets/converters/js-mqtt-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'] [IntegrationType.LORIOT, '/assets/converters/js-loriot-encoder.raw']
@ -275,18 +275,19 @@ export const getTargetField =
export const getTargetTemplateUrl = export const getTargetTemplateUrl =
(converterType: ConverterType, scriptLang: ScriptLanguage, (converterType: ConverterType, scriptLang: ScriptLanguage,
integrationType: IntegrationType, converterVersion: ConverterVersion = 1): string => { integrationType: IntegrationType, converterVersion: ConverterVersion = 1): string => {
if (scriptLang === ScriptLanguage.JS && converterType === ConverterType.UPLINK && IntegrationJSDefaultConvertersUrl.has(integrationType)) { const isJs = scriptLang === ScriptLanguage.JS;
return IntegrationJSDefaultConvertersUrl.get(integrationType) const isUplink = converterType === ConverterType.UPLINK;
} else if (scriptLang === ScriptLanguage.JS && converterType === ConverterType.DOWNLINK && IntegrationJSDefaultEncodersUrl.has(integrationType)) { // Integration-specific template map for this (language, direction); UPLINK -> decoders, DOWNLINK -> encoders.
return IntegrationJSDefaultEncodersUrl.get(integrationType); const integrationUrls = isJs
} else if (scriptLang === ScriptLanguage.JS) { ? (isUplink ? IntegrationJSDefaultConvertersUrl : IntegrationJSDefaultEncodersUrl)
return getJsTemplateUrl(converterType, converterVersion); : (isUplink ? IntegrationTbelDefaultConvertersUrl : IntegrationTbelDefaultEncodersUrl);
} else if (converterType === ConverterType.UPLINK && IntegrationTbelDefaultConvertersUrl.has(integrationType)) { if (integrationUrls.has(integrationType)) {
return IntegrationTbelDefaultConvertersUrl.get(integrationType); return integrationUrls.get(integrationType);
} else if (converterType === ConverterType.DOWNLINK && IntegrationTbelDefaultEncodersUrl.has(integrationType)) {
return IntegrationTbelDefaultEncodersUrl.get(integrationType);
} }
return getTbelTemplateUrl(converterType, converterVersion); // Fall back to the generic template for the script language.
return isJs
? getJsTemplateUrl(converterType, converterVersion)
: getTbelTemplateUrl(converterType, converterVersion);
} }
const getTbelConverterFunctionHeldId = (converterType: ConverterType, converterVersion: ConverterVersion): string => { const getTbelConverterFunctionHeldId = (converterType: ConverterType, converterVersion: ConverterVersion): string => {

11
ui-ngx/src/assets/converters/js-chirpstack-encoder.raw

@ -3,6 +3,11 @@
// msg - JSON message payload downlink message json // msg - JSON message payload downlink message json
// msgType - type of message, for ex. 'ATTRIBUTES_UPDATED', 'POST_TELEMETRY_REQUEST', etc. // msgType - type of message, for ex. 'ATTRIBUTES_UPDATED', 'POST_TELEMETRY_REQUEST', etc.
// metadata - list of key-value pairs with additional data about the message // metadata - list of key-value pairs with additional data about the message
// ChirpStack reads DevEUI and fPort from the metadata below to enqueue the downlink (POST .../devices/{DevEUI}/queue).
// Both are client-side device attributes that must be populated via an Originator attributes rule node.
// ThingsBoard prefixes client-scope attributes with "cs_":
// metadata.cs_eui — ChirpStack device EUI stored on first uplink (e.g. "466ECD510CF7B021")
// metadata.cs_fPort — LoRaWAN frame port stored on first uplink (e.g. "1")
// integrationMetadata - list of key-value pairs with additional data defined in Integration executing this converter // integrationMetadata - list of key-value pairs with additional data defined in Integration executing this converter
/** Encoder **/ /** Encoder **/
@ -12,10 +17,12 @@ var result = {
// downlink data content type: JSON, TEXT or BINARY (base64 format) // downlink data content type: JSON, TEXT or BINARY (base64 format)
contentType: "TEXT", contentType: "TEXT",
// downlink data // downlink data
data: btoa(msg), data: btoa(JSON.stringify(msg)),
// Optional metadata object presented in key/value format // Metadata required by ChirpStack for downlink delivery.
metadata: { metadata: {
// Target device EUI; ChirpStack rejects the downlink if this is missing.
DevEUI: metadata.cs_eui, DevEUI: metadata.cs_eui,
// LoRaWAN frame port (1-223); ChirpStack parses this as an integer.
fPort: metadata.cs_fPort fPort: metadata.cs_fPort
} }
}; };

4
ui-ngx/src/assets/converters/js-mqtt-encoder.raw

@ -7,13 +7,13 @@
/** Encoder **/ /** Encoder **/
// Publish the ThingsBoard message as JSON to the device command topic. // Publish the ThingsBoard message as JSON to the device upload topic.
// metadata.topic is read by the integration when Downlink topic pattern is ${topic}. // metadata.topic is read by the integration when Downlink topic pattern is ${topic}.
var result = { var result = {
contentType: "JSON", contentType: "JSON",
data: JSON.stringify(msg), data: JSON.stringify(msg),
metadata: { metadata: {
topic: metadata['deviceType']+'/'+metadata['deviceName']+'/upload' topic: metadata['deviceType'] + '/' + metadata['deviceName'] + '/upload'
} }
}; };

14
ui-ngx/src/assets/converters/js-tti-encoder.raw → ui-ngx/src/assets/converters/js-ttn-tti-encoder.raw

@ -1,4 +1,5 @@
// Encode downlink data from incoming Rule Engine message // Encode downlink data from incoming Rule Engine message
// Shared by the TTN and TTI integrations (The Things Stack).
// msg - JSON message payload downlink message json // msg - JSON message payload downlink message json
// msgType - type of message, for ex. 'ATTRIBUTES_UPDATED', 'POST_TELEMETRY_REQUEST', etc. // msgType - type of message, for ex. 'ATTRIBUTES_UPDATED', 'POST_TELEMETRY_REQUEST', etc.
@ -7,20 +8,23 @@
/** Encoder **/ /** Encoder **/
// Target device identifier used to build the TTN downlink topic (devId is assumed to be added via Originator fields rule node) // Target device identifier used to build the TTN/TTI downlink topic (devId is assumed to be added via Originator fields rule node)
var devId = metadata.devId; var devId = metadata.devId;
// LoRaWAN frame port the downlink is scheduled on (cs_fPort is assumed to be added via Originator attributes rule node, prefix 'cs_' (client-side) is added by rule node) // LoRaWAN frame port the downlink is scheduled on (cs_fPort is assumed to be added via Originator attributes rule node, prefix 'cs_' (client-side) is added by rule node)
var fPort = metadata.cs_fPort; // Default port to 1 when the device fPort attribute is missing or empty. parseInt keeps f_port a number, as the TTN/TTI API expects.
var fPort = (metadata.cs_fPort != null && metadata.cs_fPort != '')
? parseInt(metadata.cs_fPort)
: 1;
// The Things Network expects a 'downlinks' array; each entry is a single scheduled downlink. // The Things Stack (TTN/TTI) expects a 'downlinks' array; each entry is a single scheduled downlink.
var data = { var data = {
downlinks: [{ downlinks: [{
// Frame port to deliver the payload on (must match the device's expected port). // Frame port to deliver the payload on (must match the device's expected port).
f_port: fPort, f_port: fPort,
// false - best-effort downlink; set to true to request an acknowledgement from the device. // false - best-effort downlink; set to true to request an acknowledgement from the device.
confirmed: false, confirmed: false,
// Downlink payload, base64-encoded as required by the TTN API. // Downlink payload, base64-encoded as required by the TTN/TTI API.
frm_payload: btoa(msg), frm_payload: btoa(JSON.stringify(msg)),
// Scheduling priority for the network server: LOWEST, LOW, BELOW_NORMAL, NORMAL, ABOVE_NORMAL, HIGH, HIGHEST. // Scheduling priority for the network server: LOWEST, LOW, BELOW_NORMAL, NORMAL, ABOVE_NORMAL, HIGH, HIGHEST.
priority: "NORMAL" priority: "NORMAL"
}] }]

11
ui-ngx/src/assets/converters/tbel-chirpstack-encoder.raw

@ -3,6 +3,11 @@
// msg - JSON message payload downlink message json // msg - JSON message payload downlink message json
// msgType - type of message, for ex. 'ATTRIBUTES_UPDATED', 'POST_TELEMETRY_REQUEST', etc. // msgType - type of message, for ex. 'ATTRIBUTES_UPDATED', 'POST_TELEMETRY_REQUEST', etc.
// metadata - list of key-value pairs with additional data about the message // metadata - list of key-value pairs with additional data about the message
// ChirpStack reads DevEUI and fPort from the metadata below to enqueue the downlink (POST .../devices/{DevEUI}/queue).
// Both are client-side device attributes that could be populated via an Originator attributes rule node.
// ThingsBoard prefixes client-scope attributes with "cs_":
// metadata.cs_eui — ChirpStack device EUI stored on first uplink (e.g. "466ECD510CF7B021")
// metadata.cs_fPort — LoRaWAN frame port stored on first uplink (e.g. "1")
// integrationMetadata - list of key-value pairs with additional data defined in Integration executing this converter // integrationMetadata - list of key-value pairs with additional data defined in Integration executing this converter
/** Encoder **/ /** Encoder **/
@ -12,10 +17,12 @@ var result = {
// downlink data content type: JSON, TEXT or BINARY (base64 format) // downlink data content type: JSON, TEXT or BINARY (base64 format)
contentType: "TEXT", contentType: "TEXT",
// downlink data // downlink data
data: btoa(msg), data: btoa(JSON.stringify(msg)),
// Optional metadata object presented in key/value format // Metadata required by ChirpStack for downlink delivery.
metadata: { metadata: {
// Target device EUI; ChirpStack rejects the downlink if this is missing.
DevEUI: metadata.cs_eui, DevEUI: metadata.cs_eui,
// LoRaWAN frame port (1-223); ChirpStack parses this as an integer.
fPort: metadata.cs_fPort fPort: metadata.cs_fPort
} }
}; };

2
ui-ngx/src/assets/converters/tbel-mqtt-encoder.raw

@ -7,7 +7,7 @@
/** Encoder **/ /** Encoder **/
// Publish the ThingsBoard message as JSON to the device command topic. // Publish the ThingsBoard message as JSON to the device upload topic.
// metadata.topic is read by the integration when Downlink topic pattern is ${topic}. // metadata.topic is read by the integration when Downlink topic pattern is ${topic}.
var result = { var result = {
contentType: "JSON", contentType: "JSON",

38
ui-ngx/src/assets/converters/tbel-tti-encoder.raw

@ -1,38 +0,0 @@
// 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 **/
// Target device identifier used to build the TTN downlink topic (devId is assumed to be added via Originator fields rule node)
var devId = metadata.devId;
// LoRaWAN frame port the downlink is scheduled on (cs_fPort is assumed to be added via Originator attributes rule node, prefix 'cs_' (client-side) is added by rule node)
var fPort = metadata.cs_fPort;
// The Things Network expects a 'downlinks' array; each entry is a single scheduled downlink.
var data = {
downlinks: [{
// Frame port to deliver the payload on (must match the device's expected port).
f_port: fPort,
// false - best-effort downlink; set to true to request an acknowledgement from the device.
confirmed: false,
// Downlink payload, base64-encoded as required by the TTN API.
frm_payload: btoa(msg),
// Scheduling priority for the network server: LOWEST, LOW, BELOW_NORMAL, NORMAL, ABOVE_NORMAL, HIGH, HIGHEST.
priority: "NORMAL"
}]
};
// Result object with encoded downlink payload
var result = {
contentType: "JSON",
data: JSON.stringify(data),
metadata: {
devId: devId
}
};
return result;

38
ui-ngx/src/assets/converters/tbel-ttn-encoder.raw

@ -1,38 +0,0 @@
// 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 **/
// Target device identifier used to build the TTN downlink topic (devId is assumed to be added via Originator fields rule node)
var devId = metadata.devId;
// LoRaWAN frame port the downlink is scheduled on (cs_fPort is assumed to be added via Originator attributes rule node, prefix 'cs_' (client-side) is added by rule node)
var fPort = metadata.cs_fPort;
// The Things Network expects a 'downlinks' array; each entry is a single scheduled downlink.
var data = {
downlinks: [{
// Frame port to deliver the payload on (must match the device's expected port).
f_port: fPort,
// false - best-effort downlink; set to true to request an acknowledgement from the device.
confirmed: false,
// Downlink payload, base64-encoded as required by the TTN API.
frm_payload: btoa(msg),
// Scheduling priority for the network server: LOWEST, LOW, BELOW_NORMAL, NORMAL, ABOVE_NORMAL, HIGH, HIGHEST.
priority: "NORMAL"
}]
};
// Result object with encoded downlink payload
var result = {
contentType: "JSON",
data: JSON.stringify(data),
metadata: {
devId: devId
}
};
return result;

14
ui-ngx/src/assets/converters/js-ttn-encoder.raw → ui-ngx/src/assets/converters/tbel-ttn-tti-encoder.raw

@ -1,4 +1,5 @@
// Encode downlink data from incoming Rule Engine message // Encode downlink data from incoming Rule Engine message
// Shared by the TTN and TTI integrations (The Things Stack).
// msg - JSON message payload downlink message json // msg - JSON message payload downlink message json
// msgType - type of message, for ex. 'ATTRIBUTES_UPDATED', 'POST_TELEMETRY_REQUEST', etc. // msgType - type of message, for ex. 'ATTRIBUTES_UPDATED', 'POST_TELEMETRY_REQUEST', etc.
@ -7,20 +8,23 @@
/** Encoder **/ /** Encoder **/
// Target device identifier used to build the TTN downlink topic (devId is assumed to be added via Originator fields rule node) // Target device identifier used to build the TTN/TTI downlink topic (devId is assumed to be added via Originator fields rule node)
var devId = metadata.devId; var devId = metadata.devId;
// LoRaWAN frame port the downlink is scheduled on (cs_fPort is assumed to be added via Originator attributes rule node, prefix 'cs_' (client-side) is added by rule node) // LoRaWAN frame port the downlink is scheduled on (cs_fPort is assumed to be added via Originator attributes rule node, prefix 'cs_' (client-side) is added by rule node)
var fPort = metadata.cs_fPort; // Default port to 1 when the device fPort attribute is missing or empty. parseInt keeps f_port a number, as the TTN/TTI API expects.
var fPort = (metadata.cs_fPort != null && metadata.cs_fPort != '')
? parseInt(metadata.cs_fPort)
: 1;
// The Things Network expects a 'downlinks' array; each entry is a single scheduled downlink. // The Things Stack (TTN/TTI) expects a 'downlinks' array; each entry is a single scheduled downlink.
var data = { var data = {
downlinks: [{ downlinks: [{
// Frame port to deliver the payload on (must match the device's expected port). // Frame port to deliver the payload on (must match the device's expected port).
f_port: fPort, f_port: fPort,
// false - best-effort downlink; set to true to request an acknowledgement from the device. // false - best-effort downlink; set to true to request an acknowledgement from the device.
confirmed: false, confirmed: false,
// Downlink payload, base64-encoded as required by the TTN API. // Downlink payload, base64-encoded as required by the TTN/TTI API.
frm_payload: btoa(msg), frm_payload: btoa(JSON.stringify(msg)),
// Scheduling priority for the network server: LOWEST, LOW, BELOW_NORMAL, NORMAL, ABOVE_NORMAL, HIGH, HIGHEST. // Scheduling priority for the network server: LOWEST, LOW, BELOW_NORMAL, NORMAL, ABOVE_NORMAL, HIGH, HIGHEST.
priority: "NORMAL" priority: "NORMAL"
}] }]
Loading…
Cancel
Save