mikakaraila / node-red-contrib-opcua

A Node-RED node to communicate OPC UA. Uses node-opcua library.
Other
209 stars 194 forks source link

Error at RaspberryPi but on Windows it's working #61

Closed vallik800i closed 6 years ago

vallik800i commented 6 years ago

Hello there, I am a student from Germany and at this moment I am working at a company.

My task is to read something out of a PLC with OPC UA.

My programm has about 8 Flows with 13 OPCUA client nodes, which are reading. If I deploy only 1-2 Flows there are no problems on my RaspberryPi 3. But if I deploy more, I get the warning:

warning : ClientSessionKeepAliveManager#ping_server   ServiceResult is BadSessionIdInvalid (0x80250000)
 warning : ClientSessionKeepAliveManager#ping_server   ServiceResult is BadSessionIdInvalid (0x80250000)
 message was 
undefined
 message was 2: { /*OpenSecureChannelRequest*/
 requestHeader                 /* RequestHeader                    */: {
   authenticationToken         /* NodeId                           */: ns=0;i=0
   timeStamp                   /* UtcTime                          */: 2017-08-18T19:50:29.933Z
   requestHandle               /* IntegerId                        */: 1               0x1
   returnDiagnostics           /* UInt32                           */: 0               0x0
   auditEntryId                /* UAString                         */: null
   timeoutHint                 /* UInt32                           */: 0               0x0
   additionalHeader            /* ExtensionObject                  */: null
 }
 clientProtocolVersion         /* UInt32                           */: 0               0x0
 requestType                   /* SecurityTokenRequestType         */: ISSUE ( 0)
 securityMode                  /* MessageSecurityMode              */: NONE ( 1)
 clientNonce                   /* ByteString                       */: null
 requestedLifetime             /* UInt32                           */: 600000               0x927c0
};

For about one minute, the programm will run now. But after one minute I get this Error:

Timeout .... waiting for response for  OpenSecureChannelRequest { /*RequestHeader*/
 authenticationToken           /* NodeId                           */: ns=0;i=0
 timeStamp                     /* UtcTime                          */: 2017-08-18T19:50:29.933Z
 requestHandle                 /* IntegerId                        */: 1               0x1
 returnDiagnostics             /* UInt32                           */: 0               0x0
 auditEntryId                  /* UAString                         */: null
 timeoutHint                   /* UInt32                           */: 0               0x0
 additionalHeader              /* ExtensionObject                  */: null
};
18 Aug 19:51:29 - [error] [OpcUa-Client:7ad5e19b.271e7]  OPC UA connection error: Transaction has timed out
warning : disconnection : closing pending sessions

But I get this Errors only at the RaspPi. On Windows I get sometimes the warning but not the Error.. What is my fault? I am searching for a week now and i don't know what's wrong... EDIT: Sometimes I get the Error also at Windows but not very often and then the Clients are still active

Can you help me? Thanks in advance and sorry for my bad english..

Valentin

I think it's the same problem like this: https://github.com/mikakaraila/node-red-contrib-opcua/issues/22 But there i found no solution..

nospam2000 commented 6 years ago

can you please check the number of open tcp connections to your OPC UA server by using the following command on the client machine (replace "4840" by the port number of your OPC UA server): netstat -a -p tcp | grep 4840

You can also use the diagnostics of your OPC UA server, e.g. the Siemens S7-15xx PLCs provide connections diagnostics via a web interface, but this must be enabled explicitly in the TIA-Portal.

When there are more connections than OPC UA nodes in your flows, you might have run into issue #58. PS: is it a secret for which company you are working?

vallik800i commented 6 years ago

I have changed the programm a little bit. now I have 13 OpcUa Items which are connected to one OpcUa Client. Also there are 8 Flows. In the first Flow there are the OpcUa things. I am writing them in a databank. In the other Flows I read datas out of the databank and put them in other db's and process them and show them on dashboard.

If I only activate the Flow 1 (OpcUa reading) i have no errors and I have only one connection to my OPCUA server (netstat -a -p tcp | grep 4840) But if I activate one or two more Flows, I will get the error and I have between 5 and 14 connections to the OpcUa Server. But why? In the other Flows there is nothing with OpcUa... I have no idea...

I don't know if I am allowed to tell my company name.. But we are a medium-sized company with less than 1000 employees.

Thanks for the fast reply.

mikakaraila commented 6 years ago

One cause could be that the other flow nodes will block or cause delay so OPC UA will try to use keepalive session(s) to reconnect... this is just idea that you should check.

vallik800i commented 6 years ago

I think this is the problem. The other Flows cause a delay that the OpcUa isn't fast enough and more Clients will be opened.. So the RaspPi-processor is too slow? Is there a possibility to avoid this?

mikakaraila commented 6 years ago

One question is how you are using flows. Are there a flow that will save data to database? Is database local or remote... etc.

vallik800i commented 6 years ago

All Flows are saving data to databases. I am using SQLite so the databases are local

mikakaraila commented 6 years ago

Ok are those implemented async? So storing data does not block other actions/flows/events? Is the db-node some public existing one or have you implemented it by yourself?

vallik800i commented 6 years ago

The db-node is public existing from node-red-node-sqlite. I split some Flows and read something out of other db's and join them after that together. Picture from OpcUa Flow: https://picload.org/view/rwcporpi/2.png.html

Picture from one other Flow(all other Flows are near to that): https://picload.org/view/rwcporiw/1.png.html

mikakaraila commented 6 years ago

How fast are you getting&storing data? Every 1s or faster? SQlite reconnect timeout is 20s. I think it is related to CPU load and how fast Raspberry can store data. Which model you are using? Model2 or model3? SDcard speed can also effect. Check cpu load to narrow the bottleneck...

vallik800i commented 6 years ago

I am getting and storing every 1s. I tried it with 3 and 5s but same error.. I am using the RaspPi 3. CPU-Usage is between 5 and 30%. The node-red-Task needs 1-3% CPU usage

mikakaraila commented 6 years ago

Have you created db and tables before you start storing? Model3 should be capable to run this. This must have some principle error... SDcard could be one bottleneck. Is it fast one?

vallik800i commented 6 years ago

Yes, I created the table before. The datas writing correctly in the db's.

mikakaraila commented 6 years ago

Do you have index on table? Can you add/check timestamp behaviour? Can buffer data and write it once a minute? Create one test flow and study with it if same happens. How many items you have in subscription? Are you using multiple subscriptions? Single read action is always slow.

vallik800i commented 6 years ago

The db is every time writing when the OpcUa is running. If the error pops out, The db ( named "daten", as you can see in the first picture from the comment with the pictures) stop writing because it gets no datas. The other db's which are reading from the main db ("daten") only read the last entry.

Look at the picture: https://picload.org/view/rwcporpi/2.png.html

There you can seehow many Items I am reading. On the left you can see 12 Items and they are going into one OpcUa Client

vallik800i commented 6 years ago

I've got the Solution!! If I start the interval for reading after deploying, there is no error! I am just not allowed to start it instantly. But why? :D

mikakaraila commented 6 years ago

Ack, there is fix / solution coming, see #58 I will merge it soon.

vallik800i commented 6 years ago

Okay top

mikakaraila commented 6 years ago

Merge done, please test.

vallik800i commented 6 years ago

you've merged #62 with #58 but not #61, or am I wrong?

mikakaraila commented 6 years ago

I suppose pull request contained more fixes... did you test this? I will have more time after work. Fix should cover this one also... we can reopen this if needed. I do not have any Raspberry PI at the moment.