Schreibe Code für einen nodered Funktionsknoten, um die openbeken config payload in einzelne Nachrichten aufzuteilen.
Czy wolisz polską wersję strony elektroda?
Nie, dziękuję Przekieruj mnie tam{
"dev": {
"ids": [
"Pow_187"
],
"name": "Pow_187",
"sw": "1.17.293",
"mf": "Beken Corporation",
"mdl": "BK7231N",
"cu": "http://192.168.178.187/index"
},
"name": "voltage",
"~": "pow_187",
"avty_t": "~/connected",
"uniq_id": "Pow_187_sensor_0",
"qos": 1,
"dev_cla": "voltage",
"unit_of_meas": "V",
"stat_t": "~/voltage/get",
"stat_cla": "measurement"
}
erhardfalkenberg hat geschrieben:Hallo,(...) ation",
"mdl": "BK7231N",
"cu": "http://192.168.178.187/index"
},
"name": "voltage",
"~": "pow_187",
"avty_t": "~/connected",
"uniq_id": "Pow_187_sensor_0",
"qos": 1,
"dev_cla": "voltage",
"unit_of_meas": "V",
"stat_t": "~/voltage/get",
"stat_cla": "measurement"
}
{
"dev": {
"ids": [
"Pow_187"
],
"name": "Pow_187",
"sw": "1.17.293",
"mf": "Beken Corporation",
"mdl": "BK7231N",
"cu": "http://192.168.178.187/index"
},
"name": "voltage",
"~": "pow_187",
"avty_t": "~/connected",
"uniq_id": "Pow_187_sensor_0",
"qos": 1,
"dev_cla": "voltage",
"unit_of_meas": "V",
"stat_t": "~/voltage/get",
"stat_cla": "measurement"
}
// Get the input JSON payload from the message
var inputPayload = msg.payload;
// Check if the payload is an array
if (Array.isArray(inputPayload)) {
// If it's an array, split it into individual messages
for (var i = 0; i < inputPayload.length; i++) {
// Create a new message for each element in the array
var newMsg = {
payload: inputPayload[i]
};
// Send the new message to the appropriate output
if (i < node.outputs) {
// Send to the corresponding output if available
node.send([newMsg, null]);
} else {
// If there are more elements than outputs, send the remaining elements to the last output
node.send([null, newMsg]);
}
}
} else {
// If the payload is not an array, just pass it through
node.send([msg, null]);
}
return null; // Return null to end the function node[/i]
erhardfalkenberg hat geschrieben:Es sieht so aus, als hättest du gerade einen JavaScript-Code für Node-RED geteilt, der eine eingehende Nachricht verarbeitet. Der Code überprüft, ob die eingehende Payload ein Array ist. Wenn ja, wird jedes Element des Arrays in eine separate Nachricht aufgeteilt und an die entsprechenden Ausgänge weitergeleitet. Wenn es mehr Array-Elemente als Ausgänge gibt, werden die zusätzlichen Nachrichten alle zum letzten Ausgang gesendet. Wenn die eingehende Payload kein Array ist, wird die Nachricht unverändert durchgelassen.(...) If there are more elements than outputs, send the remaining elements to the last output
node.send([null, newMsg]);
}
}
} else {
// If the payload is not an array, just pass it through
node.send([msg, null]);
}
return null; // Return null to end the function node