To familiarize myself with the OPC-UA protocol (and server in the PLC) I tried to connect to the PLC using (almost) its default settings. The exact security string took me some time to get right; maybe this is useful for someone else.
* Use with python3 and be sure python-opcua is installed ("pip3 install opcua")
* The included certificates are provided as example or for testing purposes only, generate your own for real-world use!
* Configure the visibilty of variables of the OPC UA server to either 'Marked'
* This application reads the variable named 'INPUT' of 'NewProgram1':
You can pull it from https://github.com/dschoorisse/PLCnext-OPC-UA-connect-minimal (only images are allowed to upload to the forum).
Thank you for this post! I am sure that there are many people who will be interested in this. Will you consider creating a Makers Blog post on this topic?
Perhaps some text that answers questions like:
* Why is python useful?
* What problem were you trying to solve? (e.g. data exchange between the real-time PLC program and the python program; or maybe "how to access PLC I/O from a python program").
* What was the general idea for a solution? (use the existing OPC UA server in the PLC)
* How was this implemented? (by including an OPC UA Client in the python program)
* Challenges (e.g. security string)
* Result (perhaps a short video showing something happening?)
* More information (e.g. link to GitHub)
* Ideas for how to extend this example - e.g. run the python program on the PLC?
… but even a short blog post would be good, so that this achievement is available for future Makers to learn from.