# Bacnet code inside function not working using bacstack library

**URL:** https://discourse.nodered.org/t/bacnet-code-inside-function-not-working-using-bacstack-library/14850
**Category:** General
**Created:** [28 August 2019 10:29 UTC](https://discourse.nodered.org/t/bacnet-code-inside-function-not-working-using-bacstack-library/14850 "2019-08-28T10:29:46Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![VIKRAMAS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vikramas/32/3955_2.png) [@VIKRAMAS](https://discourse.nodered.org/u/VIKRAMAS)
#### Post date: [28 August 2019 10:29 UTC](https://discourse.nodered.org/t/bacnet-code-inside-function-not-working-using-bacstack-library/14850/1 "2019-08-28T10:29:46Z")

</div>

AS bacnet node was not working for me so, I used bacstack library. I am trying to read the data from a bacnet simulator. But I am getting below error

```
err: Error: ERR_TIMEOUT
    at Timeout._onTimeout (C:\Users\EpsilonPrime\node_modules\bacstack\lib\client.js:75:16)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at listOnTimeout (timers.js:263:5)
    at Timer.processTimers (timers.js:223:10)

```

Below is the nodejs code written using bacstack library which I wanted to include in function node.

```
const bacnet = require('bacstack');

// Initialize BACStack
const client = new bacnet({apduTimeout: 3000});

console.log(client);

//console.log(client.EventEmitter)

// Discover Devices
client.on('iAm', (device) => {
  console.log('address----------> ', device.address);
  console.log('deviceId----------> ', device.deviceId);
  console.log('maxApdu----------> ', device.maxApdu);
  console.log('segmentation----------> ', device.segmentation);
  console.log('vendorId----------> ', device.vendorId);
  console.log('object type----------> ', device.vendorId);
  console.log('vendorId----------> ', device.vendorId);
});

client.whoIs();

// Read Device Object
client.readProperty('192.168.14.87', {type: 8, instance: 2195695}, 28, (err, value) => {
  console.log('value: ', value);
  console.log('err: ', err);
});

```

I am getting the below reponse:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/98a2e5579a291af57edf750e1b8f9a52d52d427f.png)

Below is the simulator snap, I am using Yabe simulator:  
[![enter image description here](https://i.stack.imgur.com/HKJHY.png)](https://i.stack.imgur.com/HKJHY.png)

[![enter image description here](https://i.stack.imgur.com/CqnnB.png)](https://i.stack.imgur.com/CqnnB.png)

It is discovering the device but not able to read the value, is there any IP related issue.

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [28 August 2019 12:17 UTC](https://discourse.nodered.org/t/bacnet-code-inside-function-not-working-using-bacstack-library/14850/2 "2019-08-28T12:17:09Z")

</div>

And does it work in nodejs directly (without node-red)?

---

<div class="post-metadata">

### Author: ![Iliyas](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iliyas/32/19045_2.png) [@Iliyas](https://discourse.nodered.org/u/Iliyas)
#### Post date: [28 August 2019 13:01 UTC](https://discourse.nodered.org/t/bacnet-code-inside-function-not-working-using-bacstack-library/14850/3 "2019-08-28T13:01:00Z")

</div>

Its is working, it is discovering the device but it is not reading the value of that device....just see above post you will get to know

---

<div class="post-metadata">

### Author: ![Iliyas](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iliyas/32/19045_2.png) [@Iliyas](https://discourse.nodered.org/u/Iliyas)
#### Post date: [29 August 2019 07:08 UTC](https://discourse.nodered.org/t/bacnet-code-inside-function-not-working-using-bacstack-library/14850/4 "2019-08-29T07:08:24Z")

</div>

anyone who can help us out through it?

---

<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: [29 August 2019 07:22 UTC](https://discourse.nodered.org/t/bacnet-code-inside-function-not-working-using-bacstack-library/14850/5 "2019-08-29T07:22:41Z")

</div>

Well, this isn't a support forum for the bacnet npm module you are trying to use, so you may not get very far.

@VIKRAMAS have you reported the issues you have with the bacnet node to its author?

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [29 August 2019 07:24 UTC](https://discourse.nodered.org/t/bacnet-code-inside-function-not-working-using-bacstack-library/14850/6 "2019-08-29T07:24:36Z")

</div>

In the screenshot, before the `err:`, it shows `value: undefined`  
Is there something missing ?

---

<div class="post-metadata">

### Author: ![Iliyas](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iliyas/32/19045_2.png) [@Iliyas](https://discourse.nodered.org/u/Iliyas)
#### Post date: [29 August 2019 07:25 UTC](https://discourse.nodered.org/t/bacnet-code-inside-function-not-working-using-bacstack-library/14850/7 "2019-08-29T07:25:26Z")

</div>

we have checked everything......we need some guidance we are almost there, because if this issue is solved then we dont have to write a nodejs function as the bacnet node is also giving same exception it can be resolved if this problem is resolved.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [31 August 2019 07:53 UTC](https://discourse.nodered.org/t/bacnet-code-inside-function-not-working-using-bacstack-library/14850/8 "2019-08-31T07:53:27Z")

</div>

As @bakman2 suggested, have you tried this in node js (i.e. outside of node red)?

Also, have you tried communicating to localhost or 127.0.0.1.

Have you tried using another bacnet tool to see if you can read values from that simulator? To verify it actually permits read operations for your virtual device.

Lastly, if you get the same error in pure node js, you might get more help if you post an issue on the bacstack repo

---

<div class="post-metadata">

### Author: ![Iliyas](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/iliyas/32/19045_2.png) [@Iliyas](https://discourse.nodered.org/u/Iliyas)
#### Post date: [6 September 2019 06:28 UTC](https://discourse.nodered.org/t/bacnet-code-inside-function-not-working-using-bacstack-library/14850/9 "2019-09-06T06:28:21Z")

</div>

I have tried in nodejs itself, I am able to discover the device but not able read its objects, and i had also posted an issue in bacstack repo

---

<div class="post-metadata">

### Author: ![UdoUSA](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/udousa/32/12293_2.png) [@UdoUSA](https://discourse.nodered.org/u/UdoUSA)
#### Post date: [19 September 2019 06:51 UTC](https://discourse.nodered.org/t/bacnet-code-inside-function-not-working-using-bacstack-library/14850/10 "2019-09-19T06:51:28Z")

</div>

I am totally new to node-red but seasoned in BACnet. I apologize but the debug information is not easy to understand but I would suggest to use a monitoring tool like WireShark to actual see what get send and what comes back. This tool can decode BACnet messages into clear text and might help in understanding what is going on. This should help to isolate the problem.

---

<div class="post-metadata">

### Author: ![obnd](https://avatars.discourse-cdn.com/v4/letter/o/a698b9/32.png) [@obnd](https://discourse.nodered.org/u/obnd)
#### Post date: [3 May 2021 18:16 UTC](https://discourse.nodered.org/t/bacnet-code-inside-function-not-working-using-bacstack-library/14850/11 "2021-05-03T18:16:38Z")

</div>

Good afternoon.

I am working with bacnet nodes, and it is presenting me with this error message:

Error: BacnetError Class: SERVICES (5) Code: REJECT\_UNRECOGNIZED\_SERVICE (67)
