Hi,
We are trying to write a c++ application which is run on a remote host (running linux) and uses gRPC (https://github.com/grpc/grpc) (remote) to exchange data with an AXC F 3152. We have tested and verified with grpcurl (following the guide) that everything works and are able to read data perfectly fine with that utility in insecure mode. We then tried the following code on our remote machine (same local network, very similar to the grpc c++ plcnext example except from a remote host (https://github.com/PLCnext/plcnext-grpc-example-cpp) ) :
std::shared_ptr<Channel> channel = grpc::CreateChannel("192.168.0.1:50051", grpc::InsecureChannelCredentials());
auto dataAccessService = IDataAccessService();
auto dataAccessStub = dataAccessService.NewStub(channel);
auto ctx = grpc::ClientContext();
auto request = IDataAccessServiceReadRequest();
auto portName = "MyComponent/Item1.Config";
request.add_portnames(portName);
auto response = IDataAccessServiceReadResponse();
auto status = dataAccessStub->Read(&ctx, request, &response);
if (status.ok())
{
Logging::info("Portname: {0}
Output: {1}", portName, response.SerializeAsString());
}
else
{
Logging::error("gRPC failed: {0}", status.error_message());
}
When we run this however, it fails to connect , with the following error : „gRPC failed: failed to connect to all addresses; last error: UNAVAILABLE: ipv4:192.168.0.1:50051: Socket closed“ So we tried using the CA certificate from the controller (similar process to here https://www.plcnext-community.net/makersblog/secure-remote-grpc-using-grpcurl/, user authentication disabled however on the PLC) , and got a different authentication error. We did this since even with „InsecureChannelCredentials“ above, it still appeared to be using a TLS socket. Hence :
auto CA = fileToString("src/machines/plt/server/bin/CA.crt");
auto credentials = grpc::SslCredentials(grpc::SslCredentialsOptions());
std::shared_ptr<Channel> channel = grpc::CreateChannel("192.168.0.1:50051", credentials);
Hence : " gRPC failed: failed to connect to all addresses; last error: UNKNOWN: ipv4:192.168.0.1:50051: Ssl handshake failed: SSL_ERROR_SSL: error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED"
Questions :
* Has anyone tried to use gRPC (specifically using the c++ api) to communicate with a PLCNext controller from a remote device ? If so, do they have any advice ?
* Are there any other tips/settings that might be applicable on the PLC relative to gRPC that might be useful for us to explore ?
Cheers,
Lindsay