Call for submissions - gRPC Client example in Python
Calling all Python programmers ...
We have recently been getting requests for an example that shows a simple gRPC Client, written in Python, running on an AXC F 1152 or 2152 controller.
There is already a Makers Blog post showing a simple gRPC Client written in C#, here:
It would be great to have a similar Makers Blog post but using Python instead of C#. We know that there are talented Python programmers out there, some of whom have contributed interesting Python application examples to the PLCnext Community in the past. If anyone would like to take on the challenge of writing a simple gRPC Client in Python for a PLCnext Control device, and sharing the procedure in the Makers Blog, please let us know.
Comments
... and also a question for the Java programmers. Ist there a small example for a gRPC client in Java/Maven? Also a list of dependencies of a working program would be helpful. We tried the example in
https://www.plcnext.help/te/Service_Components/gRPC_Introduction.htm
but ended up with a type error in ".eventLoopGroup(new EpollEventLoopGroup())" and a not found class for "GrpcServicesGrpc" using protobuf 3.14.0 and grpc-all 1.36.2 (1.36.4 as mentioned in
https://www.plcnext.help/te/Service_Components/gRPC_Introduction.htm
does not seem to exist). Any help appreciated :)
I'm glad to learn that community member Nils Hettig has now published a Makers Blog article showing how to use the gRPC server from a python program running on an AXC F 3152:
Thanks to Nils for this very useful tutorial.
Regarding the Java code snippet I have to test some things. The snipped is quite old and it looks like there are some changes necessary. I just figured it out from the official grpc java benchmark.
Additionally the socket path is missing a "/" in the code snippet.
There are also some more things to consider for Java and using unix domain sockets. You will need the maven packages
netty-transport-native-epoll
andos-maven-plugin
Many thanks. This helps me to get one step ahead. Well, netty-transport-native-epoll only seems to be available for Linux, so for a Windows development setup we need some Maven profile hacking to get it compiled (Eclipse still complaining because it does not understand the profiles, but something we can live with for now).
After that, the code for the channel compiles (slash included, thanks; usePlaintext() instead of usePlainText(true)), but the creation of the client still ends up with an unknown GrpcServicesGrpc class. Do I miss any further dependency (currently besides epoll com.google.protobuf:protobuf-java:3.14.0 and io.grpc:grpc-all:1.36.2).
Did you follow the Basics tutorial | Java | gRPC ? This often helped me to get at least something running on the controller.
Thanks for taking care :)
My Maven/GRPC compilation step was not up to date, which prevented the creation of GRPC stubs. All about version numbers :/ The stubs are now called differently than in the Java example, e.g., IDeviceStatusServiceGrpc. Here, the C example on
https://www.plcnext-community.net/makersblog/how-to-create-a-client-for-the-plcnext-control-grpc-server-in-c
was also helpful for the next steps. Now I just need to identify some status identifiers and cross my fingers that it runs on our AXC ;)
I will post a message when it works. As part of a research project, the code will be open source - might be helpful for others.
Short update... it's working, also from inside a Docker container (requires a mapped volume on /run/plcnext and respective file permissions). Hopefully, we can also figure out how to safely get rid of the netty channel at the end, but for now - it's working. Link to code will follow.
... as promised,
the code is integrated into an optional system monitor plugin, but code/dependencies may give some inspiration/insight.