committed by
Viacheslav Klimov
9 changed files with 55 additions and 108 deletions
@ -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; |
|
||||
@ -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; |
|
||||
Loading…
Reference in new issue