Makers Blog
1,593 views 0 comments

WARNING: The procedure described in this blog uses features of the PLCnext Runtime that are currently not supported. Use these features at your own risk, and definitely do not use these features in production applications.

From the gRPCurl github project:

grpcurl is a command-line tool that lets you interact with gRPC servers. It's basically curl for gRPC servers.

In recent firmware versions, it has been possible to access the gRPC server on PLCnext Control devices, but only using gRPC clients running on the local device. Previous Makers Blog posts have given examples of gRPC clients written in C# and Python.

In future firmware versions, it will also be possible to access the gRPC server on PLCnext Control devices from remote devices. In fact this feature is already included in firmware version 2022.6, but this is still under development and is not currently supported. This article describes how to activate this feature for testing and development purposes, using an open-source gRPC client called gRPCurl.

Please note that the gRPC server should NOT currently be accessed remotely in production applications.

Procedure

On the PLCnext Control device (with firmware 2022.6)

  • Edit the file /etc/plcnext/Packages.acf.settings and change the value of the environment variable ARP_PACKAGE:Arp.Services.GrpcRemote to "true"

In the future, this setting will be made through the Web Based Management "System Services" page.

  • Restart the PLCnext Runtime.

  • Check the contents of the file /opt/plcnext/logs/Output.log. You should see the message INFO - gRPC Server listening on 0.0.0.0:50051". This means that the gRPC server is listening on port 50051 for messages from gRPC clients.

On the remote device

grpcurl -insecure -import-path Documents/plcnext-grpc/protobuf -proto Device/Interface/IDeviceStatusService.proto -d '{"identifier":"Status.Board.Temperature.Centigrade"}' 192.168.1.10:50051 Arp.Device.Interface.Services.Grpc.IDeviceStatusService/GetItem

... where -import-path is the path to the protobuf directory, and the IP address is the address of the PLCnext Control device.

NOTE: If using Windows PowerShell, it may be necessary to escape each of the double-quotes in the above command using a backslash.

The reply should be a JSON object containing the board temperature in degrees Celsius:

{
  "ReturnValue": {
    "TypeCode": "CT_Int8",
    "Int8Value": 43
  }
}

FAQ

Can the command-line tool grpcurl be run directly on an AXC F 1152 or 2152?

This might be possible, but grpcurl would need to be built from source for the target platform, and given the number of dependencies that probably won't be simple.

For more help ...

Use grpcurl -help to get more information on available options.

For questions about the gRPC Server in the PLCnext Runtime, please use the PLCnext Community Forum.

Note:

The Makers Blog shows applications and user stories of community members that are not tested or reviewed by Phoenix Contact. Use them at your own risk.

Discussion

Please login/register to comment

Login/Register

Leave a Reply

Newsletter
Never miss a new article
Sign up for the newsletter
Never miss news about PLCnext Technology
Get interesting content via newsletter four times a year
Receive exclusive information before all other users