Custom Node code

I have tried to recreate the error but now I am able to install the module with some hard coded variables and it works, but only on the last node placed on the flow. When a second node is added the first node msg.payload is empty, so on a flow with multiple of the same node only the last one works. If I test the similar normal function node with similar code it is possible to have many of these all working. I suspect it may have to do with client.close() and possibly the function node is automatically doing something after it has passed the message. The code examples are earlier in this post. Thanks for the help

A key difference between your Function code and your custom Node code is that the Function code creates a new instance of the backstack client object for every message. Your Node code creates a single backstack client object for each node and reuses it for each message a node receives.

I cannot comment on why that does not behave as you expect as I do not know the bacstack module.

You may want to look at the inner workings of one of the existing bacnet modules - they may not do exactly what you want, but they will provide a proven starting point.

Thanks for the help, this makes sense so I will carry on in this direction:grinning:

whether can support MS/TP ?

@Chris you'll need to explain what MS/TP is... And how that relates to this topic.

@Chris no, the node red bacnet module only supports bacnet IP. The Node Red bacnet node is based on Bacstack which does not support Bacnet MS/TP

Hi, based on existing bacstack whether can add BACnet MS/TP(Master Slave/Token Passing) function which is very popular in BAS. I hope the node-red-contrib-bacnet which seems like node-red-contrib-modbus both support TCP AND SERIAL(RTU) interface. Maybe how to implement the 5ms timers for token is the key issue in bacstack with JS.

Can you please share the read and write function you built!!
Thanks

1 Like

@mtoko

Can you share the write Function that you got to work and any steps you had to do before running the function. IE i get an error stating bacnet1 is not a function.

Hi
You can see the workaround (example flow and settings.js) on this link

You need to add the bacstack library to the settings.js
I could not resolve this, it is possible the issue is with the bacstack library.

I would be interested if you make any progress

How do I do that? My bacstack is located on my pi home area and my node red modules are located under shares. When I move the folder to the node red modules folder it breaks everything and I have to rebuild the Pi. I think I am missing a very obvious step lol.

@Navybrandon, our community guideline recommends

Don’t sign your posts — every post has your profile information attached to it.

I believe this is even more important when your signature states that the distribution of the content is strictly prohibited. :wink:

2 Likes

@Andrei lol thanks that's what I get for responding on my mobile. Thank you for the heads up!

@Navybrandon

You install bacstack using npm see this link

I have now been able to get the Read and Write working with Analog Values. Next i am working on Multi state Values.

write Flow
[{"id":"9ad64572.489168","type":"function","z":"b7b77216.e21bd","name":"Set Damper Position","func":"//var msg = {};\nconst bacnet1 = global.get('bacnet');\n// Initialize BACStack\nvar client = bacnet1({adpuTimeout: 6000});\nvar state = msg.payload;\n\nconst values = [\n {objectId: {type: 2, instance: 3001617}, values: [\n {property: {id: 85, index: 4294967295}, value: [{type: bacnet1.enum.ApplicationTags.BACNET_APPLICATION_TAG_REAL, value: state}], priority: 15}\n ]}\n];\n\nclient.writePropertyMultiple('192.168.1.41', values, (err, value) => {\n msg.payload = {value: value} ;\n if(err) { msg.payload = {error: err} ; }\n node.send(msg);\n});\n\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":100,"wires":[["6c59cbbe.8ec304"]]}]

read
[{"id":"d9941367.52bb8","type":"function","z":"b37e3b86.8e0538","name":"Read Damper Position","func":"//var msg = {};\nconst bacnet1 = global.get('bacnet');\n// Initialize BACStack\nvar client = bacnet1({adpuTimeout: 6000});\nvar state = msg.payload;\n\nconst values = [\n {objectId: {type: 2, instance: 3001594}, values: [\n {property: {id: 85, index: 4294967295}, value: [{type: bacnet1.enum.ApplicationTags.BACNET_APPLICATION_TAG_REAL, value: state}], priority: 15}\n ]}\n];\n\nclient.readProperty('192.168.1.41', {type: 2, instance: 3001594}, 85, (err, value) => {\n msg.payload = {value: value} ;\n node.send(msg);\n});\nreturn msg;","outputs":1,"noerr":0,"x":780.5,"y":111,"wires":[["c2bf18d.b3c5ae8","b38824cc.bbd1c8"]]}]

Can you share your flow?

@mtoko Once I get it perfect I will. Right now i am trying to figure out how to get the Bacnet device that are connected trough a IP controller. IE i see controller via whois but not the devices attached to it. Any ideas? below is the function I have so far.

//var msg = {};
const bacnet1 = global.get('bacnet');

// Initialize BACStack
const client = bacnet1({
apduTimeout: 6000,
});

// Discover Devices
client.on('iAm', (device) => {
Message.payload('address: ', device.address, ' - deviceId: ', device.deviceId, ' - maxAdpu: ', device.maxAdpu, ' - segmentation: ', device.segmentation, ' - vendorId: ', device.vendorId);
});

client.whoIs(3003934);

// Read Device Object
const requestArray = [
{objectId: {type: "", instance: 3003934}, properties: [{id: 85}]}
];
client.readPropertyMultiple('192.168.1.41', requestArray, (err, value) => {
msg.payload= ('value: ', value);
node.send(msg);
});
return msg;

@mtoko Object type was left out because that is what i am trying to find the value of. it is a Mutli-state-Value i don't know the number value of that type.

on my Pi Node-red had two folders i added bacstack to both folders then i was able to write but it killed the Bacnet pallete. Below are the locations i added backstack to.

home/pi/.node-red/node_modules
and
/usr/lib/node_modules/node-red/node_modules

In order for me to ge tthe bacstak folder to the /home/... path I had to do
Sudo -s then
rysnc -av /usr/lib/node_modules/node-red/node_moules/bacstack / home/pi/.node-red/node_modules

I hope this helps.

A post was split to a new topic: Using Node-RED with Angular