How to setup Multiple BACnet Read

I am trying to use BACnet Read node to read multiple BACnet Object. Seems one Inject node and one BACnet Read node can only accept one object. If I create 10 read nodes to read from the same BACnet server, there will be timeout issue. how to resolve it? I want to read multiple objects in every 15 minutes


.

A few things this node is Beta and hasn't been developed.
But underlying nodejs node-bacnet seems to be regular used form download figures.

If you look at the node info you have to create an array.
To do that you you construct multiple requests in function node.
I've never got this to work but surprised that 10 reads would cause a problem.
You can have an inject node as you poller then use a delay node to each read.
BTW the response is quite a deep json object as you know so might be good to process before publishing vai MQTT.

var requestArray = [
    {objectId: {type: 0, instance: 1}, properties: [{id: 85}]},
    {objectId: {type: 0, instance: 2}, properties: [{id: 85}]}
];

The only way I've got it to work is calling the underlying node-bacnet node
If your using NR v2.+ you can reference external nodejs modules from the function node config
see Version 2.0 released : Node-RED

Here is my code to read PV of two analog inputs

function node UI config
[ module name: node-bacnet, import a nodeBACnet]

var BACnet = global.get('nodeBACnet');  
var client = new BACnet();

var requestArray = [
   {objectId: {type: 0, instance: 1}, properties: [{id: 85}]},
   {objectId: {type: 0, instance: 2}, properties: [{id: 85}]}
];

client.readPropertyMultiple('192.168.1.72', requestArray, (err, value) => {
  if(err){
    msg.payload = err;
  } else {
    msg.payload = value;
 }
 node.send(msg);
});

hula888 I've tested with 20 items from one controller polling every 1 min no problem.

Hi Lawrence,

thanks a lot for your post, it is quite useful. I am going to test it on the actual BACnet device today. what I am going to do next is to split the Array message coming out of the BACnet Read node by the fix length


Split array message to different message and copy Key to Topic
image
Then to switch base on the message topic, after that each message is published to a broker via an individual MQTT Topic
really new to Node-red and not into Java Script and hope this can work, will post the result here for the knowledge sharing.

thanks

The read return array is the same for the BACnet - READ and the javascript.
It's very deep you might want to search the forum/google for "traverse nested array"
I did and it didn't yield much so if create another function node after the read-function node and drop this in it. It will send a message for each BACnet point value and it's topic has the point index.

let readResults = msg.payload.values;
readResults.forEach(getPVs);

function getPVs(item, index) {
  msg.topic = 'pointNo_'+ index;
  msg.payload = item.values[0].value[0].value;
  node.send(msg);
}

Here is my flow you can set the inject node to Repeat - Interval: x mins etc as your poller.


[{"id":"eed52276.cb3ac","type":"inject","z":"300fd127.935c9e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":115,"y":80,"wires":[["901ea33e.12652"]],"l":false},{"id":"901ea33e.12652","type":"function","z":"300fd127.935c9e","name":"CC Analog 1 to","func":"var BACnet = global.get('nodeBACnet');\nvar client = new BACnet();\n\nvar requestArray = [\n    {objectId: {type: 0, instance: 1}, properties: [{id: 85}]},\n    {objectId: {type: 0, instance: 2}, properties: [{id: 85}]},\n    {objectId: {type: 0, instance: 4}, properties: [{id: 85}]},\n    {objectId: {type: 0, instance: 5}, properties: [{id: 85}]},\n    {objectId: {type: 0, instance: 6}, properties: [{id: 85}]},\n    {objectId: {type: 1, instance: 7}, properties: [{id: 85}]},\n    {objectId: {type: 1, instance: 8}, properties: [{id: 85}]},\n    {objectId: {type: 2, instance: 201}, properties: [{id: 85}]},\n    {objectId: {type: 2, instance: 202}, properties: [{id: 85}]},\n    {objectId: {type: 2, instance: 203}, properties: [{id: 85}]},\n    {objectId: {type: 2, instance: 204}, properties: [{id: 85}]},\n    {objectId: {type: 2, instance: 205}, properties: [{id: 85}]},\n    {objectId: {type: 2, instance: 206}, properties: [{id: 85}]},\n    {objectId: {type: 2, instance: 207}, properties: [{id: 85}]},\n    {objectId: {type: 2, instance: 208}, properties: [{id: 85}]},\n    {objectId: {type: 2, instance: 209}, properties: [{id: 85}]},\n    {objectId: {type: 2, instance: 210}, properties: [{id: 85}]},\n    {objectId: {type: 2, instance: 211}, properties: [{id: 85}]},\n    {objectId: {type: 3, instance: 3}, properties: [{id: 85}]},\n    {objectId: {type: 4, instance: 9}, properties: [{id: 85}]}\n];\nmsg.topic = \"BASpi-2755\"\nclient.readPropertyMultiple('192.168.1.72', requestArray, (err, value) => {\n if(err){\n  msg.payload = err;\n  node.send(msg);\n } else {\n   msg.payload = value;\n  node.send(msg);\n }\n  \n});\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":175,"y":80,"wires":[["47a618cd.5eeb58","51045570.e3ca1c"]],"icon":"node-red-contrib-bacnet/bacnet-icon.png","l":false},{"id":"51045570.e3ca1c","type":"function","z":"300fd127.935c9e","name":"BACnet read array","func":"let readResults = msg.payload.values;\nreadResults.forEach(getPVs);\n\nfunction getPVs(item, index) {\n  msg.topic = 'pointNo_'+ index;\n  msg.payload = item.values[0].value[0].value;\n  node.send(msg);\n}\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":264,"y":81,"wires":[["642b3639.73c2d8"]],"icon":"node-red-contrib-bacnet/bacnet-icon.png","l":false},{"id":"642b3639.73c2d8","type":"debug","z":"300fd127.935c9e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":335,"y":81,"wires":[],"l":false}]

I've installed v2.1 and slight change to code as the new library import feature which is supper neat addition make like so much easier!!

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.