Assemble OPC UA for BAS, Mako and Xedge ======================================= To add OPC UA to a Barracuda App Server (BAS) build, compile the native module and package the Lua resources from the **same release and profile**. The native module exposes the compiled standard address space (namespace 0) to Lua. The Lua files implement the client, server and services. Choose :doc:`minimal or full `, then follow the row for your host. 1. Choose the host build ------------------------ .. list-table:: :header-rows: 1 :widths: 24 31 45 * - Host - Native build - Resources to deploy * - Mako Server - Mako executable, full by default when OPC UA is included - Matching ``mako.zip`` alongside the executable * - Standalone Xedge - Xedge executable or firmware, minimal by default when OPC UA is included - Standalone ``Xedge.zip``, or its ``XedgeZip.c`` representation linked into an embedded-resource build * - Xedge hosted by Mako - Mako supplies the native module - Mako supplies the OPC UA resources. Select the profile when building Mako. * - Custom BAS host - Build BAS with the chosen selector and register the module in the host's Lua state - Put the matching Lua modules in the resource filesystem used by the host's Lua loader The BAS SDK Mako and standalone Xedge makefiles propagate ``BA_ENABLE_LUA_OPCUA`` to both builds. The generic BAS header defaults to ``0`` when no host build selects a value. .. list-table:: :header-rows: 1 :widths: 16 43 41 * - Selector - C build - Resource build * - ``1`` (full) - Packed reader and full namespace 0 - All OPC UA Lua files * - ``3`` (minimal) - Packed reader and minimal namespace 0 - Minimal Lua file set listed below * - ``0`` (off) - Disable OPC UA registration - Omit OPC UA Lua files * - ``2`` (external) - Host registers an application-supplied native module - Application supplies the Lua files For example, with ``BAROOT`` pointing to a configured BAS SDK, these POSIX builds select the profile for both the executable and its resources: .. code-block:: sh # Build a minimal Mako executable and mako.zip. make -C "$BAROOT/examples/MakoServer/make" plat=posix BA_ENABLE_LUA_OPCUA=3 exe # Build standalone Xedge with full OPC UA and embedded resources. make -C "$BAROOT/examples/xedge/make" plat=posix io=ezip BA_ENABLE_LUA_OPCUA=1 exe Keep the normal compiler, platform and linker settings for your SDK. If the SDK already contains the OPC UA release, the makefiles handle the file selection. Continue at :ref:`verify_opcua_assembly` after building. 2. Assemble the native module ----------------------------- When importing a release, the native files come from the OPC-UA repository root. In a BAS SDK source tree they live under ``BAS/xrc/lua/opcua/``. Keep both model sources in the SDK so the build can select either profile. .. list-table:: :header-rows: 1 :widths: 36 64 * - File - Role * - ``opcua_packed.c`` - Compile for both profiles. Implements the reader and the Lua module ``opcua_ns0``. * - ``opcua_packed.h``, ``opcua_ns0.h`` - Shared headers for the reader, registration entry point and compiled model data. * - ``opcua_ns0_min.c`` **or** ``opcua_ns0_full.c`` - Compile exactly one. Both define ``opcua_ns0_blob`` and ``opcua_ns0_blob_size``. BAS amalgamated builds select and include the implementation when compiling BAS with value 1 or 3. In a project that compiles the individual OPC UA sources itself, add the reader and selected model once and make the shared headers and the host's Lua headers available to the compiler. Mako and standalone Xedge call ``luaopen_opcua_ns0_static(L)`` during Lua startup for every enabled mode. In a custom host call this entry point on the initialized ``lua_State *L`` before loading the OPC UA application. With value 2, the application must link the implementation that supplies that symbol. 3. Assemble the Lua resource archive ------------------------------------ The source is ``lua/opcua/`` in the stack checkout and ``BAS-Resources/src/opcua/`` in the BAS resource tree. Preserve paths relative to ``lua/`` under ``.lua/`` in the archive. For example, ``lua/opcua/api.lua`` becomes ``.lua/opcua/api.lua`` so the application can load ``opcua.api``. **Full** includes ``lua/opcua/**/*.lua`` recursively, including Lua files directly in ``lua/opcua/``. **Minimal** selects only the following four rows. Each ``*`` matches within one directory. .. list-table:: :header-rows: 1 :widths: 40 60 * - Include mask - Filenames to exclude in that directory * - ``lua/opcua/*.lua`` - ``compat_lua.lua``, ``init_project.lua``, ``main.lua``, ``openssl.lua``, ``services_ext.lua``, ``table_array.lua`` * - ``lua/opcua/binary/*.lua`` - ``*_http.lua`` * - ``lua/opcua/binary/crypto/*.lua`` - None * - ``lua/opcua/model/*.lua`` - ``export_*.lua``, ``*xml.lua`` The BAS-Resources builders apply these rules from ``build/opcua-min.txt``. For a custom build, create the archive from a fresh staging directory so a switch to minimal also removes full-only modules. When packaging separately, give the compiler and resource builder the same numeric selector. From ``BAS-Resources/build`` on Linux, for example: .. code-block:: sh # Package full Lua resources for a standalone Xedge compiled with value 1. BA_ENABLE_LUA_OPCUA=1 bash Xedge.sh On Windows, set the environment variable before running ``Xedge.cmd`` or ``mako.cmd``. Deploy the resource archive with the matching executable. For embedded Xedge resources, rebuild and deploy the image containing the generated ``XedgeZip.c``. .. _verify_opcua_assembly: 4. Verify the installed pair ---------------------------- Download :example:`check_profile.lua `. With the new Mako executable and its matching ZIP installed together, run: .. code-block:: sh mako check_profile.lua On standalone Xedge, use a small test application: 1. Save the same :example:`check_profile.lua ` as ``.preload`` at the top level of the application ZIP, alongside its ``.config``. 2. Deploy the ZIP in the Xedge IDE and start the application. If its ``.config`` sets ``autostart`` to true, deployment starts it automatically. 3. Read the Xedge trace. Expect ``OPC UA profile: minimal`` for selector ``3`` and ``OPC UA profile: full`` for selector ``1``. On either host, the script checks for the Root node and compares a full-only standard type with the installed subscription service. A missing ``opcua_ns0`` points to native linkage or registration. A missing ``opcua.api`` points to the resource path or archive. A mismatch means the selected native model and Lua services disagree. Finally use :doc:`quickstart` to check the listener and a client session on Mako. For a device endpoint, :doc:`integrations/thirdparty_clients` shows how to browse and read from a separate machine. Using a separate OPC UA source checkout --------------------------------------- The OPC-UA Makefile and a Mako development build using ``OPCUA_ROOT`` use the string selector ``OPCUA_PROFILE``. Its accepted values are ``min`` and ``full``, with ``full`` as the default. From the OPC-UA checkout: .. code-block:: sh # Build the minimal native module and stage the selected sources. make OPCUA_PROFILE=min # Build a sibling Mako source checkout with that same profile. make -C ../mako OPCUA_ROOT="$PWD" OPCUA_PROFILE=min mako In this workflow the Mako shell resource builder leaves OPC UA packaging to the development build identified by ``OPCUA_ROOT``. The ESP32 development target in the OPC-UA checkout also accepts ``OPCUA_PROFILE`` when OPC UA is enabled. For a prebuilt Xedge32 image, check the profile supplied by that firmware.