st-one-io / node-red-contrib-s7

A Node-RED node to interact with Siemens S7 PLCs
GNU General Public License v3.0
111 stars 58 forks source link

Read on trigger also possible? #32

Closed paskalare closed 5 years ago

paskalare commented 5 years ago

I don't know how is it possible to read PLC variables with trigger input also? It would be great because in case of GPRS connection where the cycle time may have 5 minutes or more (for reduction of data traffic) and you make some writing, you want to see directly the changes from PLC side and not waiting the next cycle update

Regards paskalare

gfcittolin commented 5 years ago

Unfortunately, this is currently not possible. There's a major rewrite of the underlying library that will allow this and other features in an easier way. But as far as I checked, writes to the PLC are not bond to the reading cycle time. That is, even if you have a reading cycle time of 5 minutes, write commands should be executed immediately (as long as there's not any other write in progress)

paskalare commented 5 years ago

i don't want to bind read and write cycles. The reading cycle still reads every 5 minutes but it would be perfect if accept input to trigger the reading direct (not wait for the cycle). I think its worth because it is very flexible (you can refresh your status data when page load, filter some values etc)

gfcittolin commented 5 years ago

Sorry, I have understood you would be writing to the PLC. The current way to do this would be to have a short cycle time for reading, and then save the states into a variable by using the "Change" node. When needed, you can then use another "Change" node to recover the last state and use it for whatever needed. In the future we'll hopefully have something like this.

paskalare commented 5 years ago

The point is to avoid extra data traffic. You leave the reading cycle to be at 5 minutes and when you need fresh data you trigger the node. This cannot done using "change" node

paskalare commented 5 years ago

Dear gfcittolin, is it possible to change config.cycletime programmatically? It makes sense if we can add an offset on this parameter during runtime

node._td = setInterval(doCycle, config.cycletime);

gfcittolin commented 5 years ago

This is currently not possible, but we could have a new "s7 control" node, so we'd have room for this implementation and future ones (like get/set PLC time, read variables individually, etc.).

Just one question: with setInterval(), the first call of the desired function will only be executed after the configured time is elapsed. That is, if we'd set it to 10s, we'd have to stop the previous timer and set a new one that would be fired for the first time only after these 10s. Would this be ok for you?

gfcittolin commented 5 years ago

The point is to avoid extra data traffic. You leave the reading cycle to be at 5 minutes and when you need fresh data you trigger the node. This cannot done using "change" node

Are you accessing your PLC directly over a public network? Ideally you'd have a device with Node-RED running locally to the PLC and performing the read requests, and allow the access from this device only to the desired information. Just have in mind the security implications of it :)

paskalare commented 5 years ago

That is, if we'd set it to 10s, we'd have to stop the previous timer and set a new one that would be fired for the first time only after these 10s. Would this be ok for you?

No this is not useful Maybe you can make this?

The PLC is behind a router with firewall and openvpn. So all the traffic is secured. The idea is to have many PLC (RTU) with GPRS and read their STATUS Datablock every lets say 15 minutes. From node-red dashboard you give some command and you want to send it directly without delay to PLC. That time you change the reading update cycle to 1 second because you want the feedback (valve changed from CLOSED to OPEN) on next seconds in order to update the "HMI" of dashboard. After you receive the new STATUS you change again the update cycle to 5-15 minutes. *If you see the "node-red-contrib-s7comm" it has input on reading node where you can trigger reading cycle. I don't know if this can be also possible to your node

paskalare commented 5 years ago

Dear gfcittolin, did you find any way to implement the trigger read function? It would be very useful for all applications based on 3G-4G traffic. I honesty hope some time to see this function on your node

gfcittolin commented 5 years ago

Whoopsie, sorry, missed this one. I'll put in our pipeline for this week's development.

gfcittolin commented 5 years ago

Hi @paskalare , I've implemented a new "s7 control" node that enables you to control the cycle time by messages. It expects the cycle time in ms, and by sending 0 you can disable the cyclic read process.

For now, it's in a separate branch. Would you mind trying it out by installing it manually via npm install netsmarttech/node-red-contrib-s7#control-node and giving a feedback about it? If it's everything ok, then I'll merge this and publish on npm.

gfcittolin commented 5 years ago

Just added a "Trigger read" function to control node that may be useful to you. This way you can leave the cycle time around 15 min like you said, and trigger a read manually when needed.

paskalare commented 5 years ago

Hi @gfcittolin, please give me some time to test it more

paskalare commented 5 years ago

the s7 control node did not produce payload with data values but only reproduce the trigger TRUE signal. If i put also a s7 node (old type) with the same settings then every time i trigger the new node i take the payload with values from the old type exit.

https://ibb.co/nbDCbL3 image

gfcittolin commented 5 years ago

That's how I thought it should work. The control node just triggers the reading process, not performs the reading process itself. So the usage scenario from your screenshot would be exactly what I had in mind: you can trigger the reading process using the control node, and get the data as required using the in nodes. I think I'll improve the node's documentation to reflect this behavior.

Regarding functionality, does it match what you need?

paskalare commented 5 years ago

:-) its fine!

Thanks on more time

gfcittolin commented 5 years ago

Great! I'll improve the documentation overall, and then publish it to npm for general availability. Sorry for the delay on implementing it and thanks for the discussion! Let me know if you have any issue

gfcittolin commented 5 years ago

Published v1.6.0 on npm with the new functionality