Custom Node code

@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