# Node-opcua server

**URL:** <https://community.factoryio.com/t/node-opcua-server/332>\
**Category:** Uncategorized\
**Created:** [July 4, 2020, 2:34pm UTC](https://community.factoryio.com/t/node-opcua-server/332 "2020-07-04T14:34:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdevoo](https://dub1.discourse-cdn.com/flex017/user_avatar/community.factoryio.com/jdevoo/32/84_2.png) [@jdevoo](https://community.factoryio.com/u/jdevoo)\
**Post date:** [July 4, 2020, 2:34pm UTC](https://community.factoryio.com/t/node-opcua-server/332/1 "2020-07-04T14:34:25Z")

</div>

I am trying to use node-opcua with a simple scene and comparing with the codesys example. No luck so far.  
Has anyone tried this? I can get FactoryIO to connect with my server but not receive any data (at entry, at exit in my case).

---

<div class="post-metadata">

**Author:** ![jdevoo](https://dub1.discourse-cdn.com/flex017/user_avatar/community.factoryio.com/jdevoo/32/84_2.png) [@jdevoo](https://community.factoryio.com/u/jdevoo)\
**Post date:** [July 4, 2020, 9:51pm UTC](https://community.factoryio.com/t/node-opcua-server/332/2 "2020-07-04T21:51:33Z")

</div>

had omitted the setter… working fragment below

```
    let atEntry = false;
namespace.addVariable({
  componentOf: device,
  nodeId: "s=atEntry",
  browseName: "atEntry",
  dataType: "Boolean",
  value: {
    get: function() {return new opcua.Variant({dataType: opcua.DataType.Boolean, value: atEntry});},
    set: function(variant) {atEntry = variant.value; return opcua.StatusCodes.Good;}
  }
});
```

---

<div class="post-metadata">

**Author:** ![janbumer1](https://dub1.discourse-cdn.com/flex017/user_avatar/community.factoryio.com/janbumer1/32/60_2.png) [@janbumer1](https://community.factoryio.com/u/janbumer1)\
**Post date:** [July 5, 2020, 7:47am UTC](https://community.factoryio.com/t/node-opcua-server/332/3 "2020-07-05T07:47:04Z")

</div>

Nice one. So, this means you can now control the scene via Node.js?

---

<div class="post-metadata">

**Author:** ![jdevoo](https://dub1.discourse-cdn.com/flex017/user_avatar/community.factoryio.com/jdevoo/32/84_2.png) [@jdevoo](https://community.factoryio.com/u/jdevoo)\
**Post date:** [July 5, 2020, 9:41am UTC](https://community.factoryio.com/t/node-opcua-server/332/4 "2020-07-05T09:41:44Z")

</div>

I am still just trying to read but in theory yes. At the moment I see session issues though. Below is a screenshot of the server and below the commander console (separate repo under node-opcua)  
At the first occurrence of session transfer, FactoryIO dialog popped up. I had to manually refresh on FactoryIO. At the second occurrence, FactoryIO did not throw a dialog and continued although the data is not being transmitted.

 ![Screenshot from 2020-07-05 11-26-35](https://europe1.discourse-cdn.com/flex017/uploads/factoryio/original/1X/279f21ac1c2835599ef46ed8e124d545db688ab9.png)

---

<div class="post-metadata">

**Author:** ![jdevoo](https://dub1.discourse-cdn.com/flex017/user_avatar/community.factoryio.com/jdevoo/32/84_2.png) [@jdevoo](https://community.factoryio.com/u/jdevoo)\
**Post date:** [July 5, 2020, 9:44am UTC](https://community.factoryio.com/t/node-opcua-server/332/5 "2020-07-05T09:44:10Z")

</div>

after I put the cursor in the OPC Server config and simply hit enter, data transmission resumes

---

<div class="post-metadata">

**Author:** ![janbumer1](https://dub1.discourse-cdn.com/flex017/user_avatar/community.factoryio.com/janbumer1/32/60_2.png) [@janbumer1](https://community.factoryio.com/u/janbumer1)\
**Post date:** [July 6, 2020, 5:08am UTC](https://community.factoryio.com/t/node-opcua-server/332/6 "2020-07-06T05:08:48Z")

</div>

Okay, so does this work stable?

---

<div class="post-metadata">

**Author:** ![jdevoo](https://dub1.discourse-cdn.com/flex017/user_avatar/community.factoryio.com/jdevoo/32/84_2.png) [@jdevoo](https://community.factoryio.com/u/jdevoo)\
**Post date:** [July 6, 2020, 1:05pm UTC](https://community.factoryio.com/t/node-opcua-server/332/7 "2020-07-06T13:05:20Z")

</div>

I just started with this but so far, comparing with Modbus, no. I will post separately my solution with a Node Modbus library which handles better network issues. That is not to say node-opcua cannot - more that I need to put more time into it. FactoryIO may also have a better support for Modbus?

---

<div class="post-metadata">

**Author:** ![brunovgr](https://dub1.discourse-cdn.com/flex017/user_avatar/community.factoryio.com/brunovgr/32/12_2.png) [@brunovgr](https://community.factoryio.com/u/brunovgr)\
**Post date:** [July 6, 2020, 4:20pm UTC](https://community.factoryio.com/t/node-opcua-server/332/8 "2020-07-06T16:20:43Z")

</div>

@jdevoo node-opcua was one of the tools we have used to test the OPC UA driver during development. The results were quite good and we were impressed with how easy it is to develop a custom OPC UA server using javascript.

In my opinion, OPC is way to complex - maybe more than it should be. Modbus is simpler but also very limited. Whenever possible, I choose Modbus over OPC.

I’m attaching to this post a modified version of the [official sample server](https://github.com/node-opcua/node-opcua/blob/v2.1.3/documentation/sample_server.js) which includes two boolean variables (input/output). Maybe it can serve as a starting point for anyone waiting to explore node-opcua.

![GIF 06-07-2020 16-35-49](https://europe1.discourse-cdn.com/flex017/uploads/factoryio/original/1X/7eef223613146c4b80694a12f78f123d0cd108ec.gif)

Instructions:

1. Extract the zip archive and run: `npm install`
2. run: `node sample_server.js`
3. Open the included scene (node.js-opcua.factoryio) in FIO and set the correct server url in the OPC Configuration panel (find it in 2).

[node-opc-ua-sample-server.zip](https://community.factoryio.com/uploads/short-url/7A7HsfCcsYxgtthjT9PLkBkyCEa.zip) (62.9 KB)

---

<div class="post-metadata">

**Author:** ![janbumer1](https://dub1.discourse-cdn.com/flex017/user_avatar/community.factoryio.com/janbumer1/32/60_2.png) [@janbumer1](https://community.factoryio.com/u/janbumer1)\
**Post date:** [July 7, 2020, 5:36am UTC](https://community.factoryio.com/t/node-opcua-server/332/9 "2020-07-07T05:36:31Z")

</div>

Thank you very much @brunovgr, great help as always!

And thanks to @jdevoo for taking a dive into this. I will test this myself to see if I get it running.
