Search code examples
node.jsopc-ua

Creating a Table in Node OPCUA


How to extend the address space into your SQL database with bidirectional mirroring, which immediately reflects any value change in the variable or database end in the opposite end. So if I have a table in Database, whose values can be changed from outside(for-example data could be added, deleted or updated), how would my node-opcua server would be notified?


Solution

  • In OPC UA, any server which is created will follow SoA architecture. Meaning server will process request only when some service request.

    In your case, you can achieve that with the help of Subscribing for Data Change and Monitoring the node which exposes the table in your data base to client. Subscribing for data change will be possible only when that node is exposed to client.

    Once node is subscribed for data change, there are 2 values which is needed by server from client.

    • Sampling interval: how frequently server should refresh data from source
    • Publishing interval: how frequently client is going to ask for notification from server.

    Lets say for example Sampling interval is 100 milliseconds and Publishing interval is 1 minute. Meaning Server has to collect the samples from the source (in your case it could be data base) at every 100 milliseconds, But Client will request for all those collected samples every 1 minute.

    In you will be able to achieve updating the server with the changed values for table in database.

    If SDK supports multi threading, then there is another way to achieve what is mentioned in question.

    • In server application, let the data source (i.e. data base) object be running in one thread.
    • Create a callback to server application layer and intialise data source object with this callback.
    • When data changes in data base, trigger a call to data source thread from data base. and if it is the required data and need to be informed to server, call the callback function which is initialized earlier.

    I hope this answered your question.