Create and Deploy Standalone OPC UA Application
This topic shows how to create and deploy a standalone application that uses OPC UA functionality. Before R2025a, you can use the general workflow to create a standalone application. For more information, see Create Standalone Application from MATLAB (MATLAB Compiler) and Create Standalone Application Using Standalone Application Compiler App (MATLAB Compiler).
Create MATLAB Script File
Create a MATLAB® script or function that uses OPC UA functionality. All scripts or
functions that use OPC UA functionality must include %#function
getSecret
. For example, write a script to create an OPC UA client and
display the client properties. Save the script file as
opcUaClient.m
.
%#function getSecret uaClient = opcua("localhost",53530); connect(uaClient); disp(uaClient);
Note
Security Considerations: Industrial Communication Toolbox™ does not package the MATLAB OPC UA client application instance certificate and its private key. Instead, a new application instance client certificate is generated for the standalone application.
Create and Package Standalone Application Using mcc
Since R2025a
Package secrets with your standalone application.
In the command window, set the private key password with the secret name
OPCUAPrivateKeyPassword
using thesetSecret
function.setSecret("OPCUAPrivateKeyPassword")
The
setSecret
function opens a Secret Prompt dialog box. Enter your private key password in the password field and click OK.Create a secret manifest file named
secrets_manifest.json
that specifies which secrets in the MATLAB vault to embed in the deployable archive. All OPC UA related applications must embed the secret namedOPCUAPrivateKeyPassword
.{ "Embedded": { "description": "All secret names specified in this section will be put into the deployed app.", "secret": ["OPCUAPrivateKeyPassword"] } }
Use the
mcc -J
(MATLAB Compiler) option to specify the JSON secret manifest file.mcc -m opcUaClient.m -J secrets_manifest.json
mcc
generates a standalone application named
opcUaClient
in your working directory. The file extension
depends on the platform used to generate the application.
Note
The generated standalone executable does not include MATLAB Runtime or an installer. To create an installer that installs the
application and MATLAB Runtime, use the compiler.package.installer
(MATLAB Compiler) function.
Run OPC UA Application
Test that the application runs in MATLAB.
!opcUaClient
OPC UA Client: Server Information: Name: 'SimulationServer@localhost' Hostname: 'localhost' Port: 53530 EndpointUrl: 'opc.tcp://localhost:53530/OPCUA/SimulationServer' Connection Information: Timeout: 10 Status: 'Connected' ServerState: 'Running' Security Information: MessageSecurityMode: SignAndEncrypt ChannelSecurityPolicy: Aes256_Sha256_RsaPss Endpoints: [1×11 opc.ua.EndpointDescription] Server Limits: MinSampleRate: 0 sec MaxReadNodes: 0 MaxWriteNodes: 0 MaxHistoryReadNodes: 0 MaxHistoryValuesPerNode: 0
If you want to run the application on another machine, you must install MATLAB Runtime at the same update level or newer. For more information, see Download and Install MATLAB Runtime (MATLAB Compiler).
(Not recommended) Store Private Key Password in Environment Variable
As an alternative to packaging secrets within the archive, you can store secret
values in environment variables on the target platform. For instance, if your
deployed code runs on a Windows® machine, set the environment variable as
OPCUAPrivateKeyPassword
and its corresponding value as the
intended private key password. You can expose your system to security risks when you
set your password in the environment variable. Use this method only in a trusted
environment.
Package only the code into a standalone application using mcc
.
mcc -m opcUaClient.m
mcc
generates a standalone application named
opcUaClient
in your working directory. After you set the
value for the environment variable OPCUAPrivateKeyPassword
on the
target machine, you can run this application.
See Also
mcc
(MATLAB Compiler) | getSecret
| setSecret
| compiler.package.installer
(MATLAB Compiler)
Topics
- Handle Sensitive Information in Deployed Applications (MATLAB Compiler)
- Download and Install MATLAB Runtime (MATLAB Compiler)