# Custom Node code

**URL:** <https://discourse.nodered.org/t/custom-node-code/248>\
**Category:** General\
**Created:** [19 May 2018 09:15 UTC](https://discourse.nodered.org/t/custom-node-code/248 "2018-05-19T09:15:29Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [25 September 2019 15:38 UTC](https://discourse.nodered.org/t/custom-node-code/248/21 "2019-09-25T15:38:59Z")

</div>

@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. 😉

---

<div class="post-metadata">

**Author:** ![Navybrandon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/navybrandon/32/13021_2.png) [@Navybrandon](https://discourse.nodered.org/u/Navybrandon)\
**Post date:** [25 September 2019 16:01 UTC](https://discourse.nodered.org/t/custom-node-code/248/22 "2019-09-25T16:01:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mtoko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mtoko/32/138_2.png) [@mtoko](https://discourse.nodered.org/u/mtoko)\
**Post date:** [26 September 2019 07:02 UTC](https://discourse.nodered.org/t/custom-node-code/248/23 "2019-09-26T07:02:48Z")

</div>

@Navybrandon

You install bacstack using npm see this link

> **[bacstack](https://www.npmjs.com/package/bacstack)**
>
> A BACnet protocol stack written in pure JavaScript.

---

<div class="post-metadata">

**Author:** ![Navybrandon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/navybrandon/32/13021_2.png) [@Navybrandon](https://discourse.nodered.org/u/Navybrandon)\
**Post date:** [27 September 2019 14:16 UTC](https://discourse.nodered.org/t/custom-node-code/248/24 "2019-09-27T14:16:39Z")

</div>

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"]]}]

---

<div class="post-metadata">

**Author:** ![mtoko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mtoko/32/138_2.png) [@mtoko](https://discourse.nodered.org/u/mtoko)\
**Post date:** [27 September 2019 14:32 UTC](https://discourse.nodered.org/t/custom-node-code/248/25 "2019-09-27T14:32:35Z")

</div>

Can you share your flow?

---

<div class="post-metadata">

**Author:** ![Navybrandon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/navybrandon/32/13021_2.png) [@Navybrandon](https://discourse.nodered.org/u/Navybrandon)\
**Post date:** [27 September 2019 15:35 UTC](https://discourse.nodered.org/t/custom-node-code/248/26 "2019-09-27T15:35:18Z")

</div>

@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;

---

<div class="post-metadata">

**Author:** ![Navybrandon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/navybrandon/32/13021_2.png) [@Navybrandon](https://discourse.nodered.org/u/Navybrandon)\
**Post date:** [27 September 2019 15:36 UTC](https://discourse.nodered.org/t/custom-node-code/248/27 "2019-09-27T15:36:27Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![Navybrandon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/navybrandon/32/13021_2.png) [@Navybrandon](https://discourse.nodered.org/u/Navybrandon)\
**Post date:** [27 September 2019 16:34 UTC](https://discourse.nodered.org/t/custom-node-code/248/28 "2019-09-27T16:34:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [6 May 2020 11:07 UTC](https://discourse.nodered.org/t/custom-node-code/248/29 "2020-05-06T11:07:58Z")

</div>

A post was split to a new topic: [Using Node-RED with Angular](https://discourse.nodered.org/t/using-node-red-with-angular/26166)

[Previous page](https://discourse.nodered.org/t/custom-node-code/248.md?page=1)
