Skip to content

Commit

Permalink
Merge pull request #2324 from arduino/sync/taddy/opta-opc-ua-fw
Browse files Browse the repository at this point in the history
[PXCT-233] Opta: OPC UA Firmware Content
  • Loading branch information
mcmchris authored Jan 21, 2025
2 parents 682de92 + d283c63 commit 5674889
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,185 @@ You should be able now to connect to your Opta™ using a central device. The Bl

![Bluetooth® Low Energy service and characteristic information from an Opta™ device](assets/user-manual-14.png)

## OPC Unified Architecture (OPC UA)

This section explains the use of the [**OPC UA library**](https://github.com/arduino-libraries/Arduino_OPC_UA) designed for Opta.


![OPC UA GUI client with Opta](assets/opta-opc-ua-gui.gif)

The library is based on the [**Fraunhofer open62541**](https://github.com/open62541/open62541) implementation of [**OPC UA**](https://en.wikipedia.org/wiki/OPC_Unified_Architecture), created specifically for the Opta family.

The [**OPC Unified Architecture (OPC UA)**](https://en.wikipedia.org/wiki/OPC_Unified_Architecture) is an industrial communication protocol widely used in automation and Industrial Internet of Things (IIoT) systems.

It provides a platform independent and secure method for exchanging information between devices and systems. **OPC UA** supports features like custom data modeling, authentication, encryption, and scalable architecture, making it a preferred choice for modern industrial applications.

The [**open62541** library](https://github.com/open62541/open62541) is an open-source implementation of the **OPC UA** standard. It is lightweight, efficient and written in C, making it ideal for embedded systems like the Opta. The library provides a flexible framework to create **OPC UA** servers and clients, ensuring compatibility with the standard while maintaining high performance.

The [**OPC UA library**](https://github.com/arduino-libraries/Arduino_OPC_UA) supports secure communication and interoperability for industrial automation applications, with the capability to automatically detect, configure, and expose up to two Arduino Opta Expansion Boards via **OPC UA**. Supported expansion boards include:

- Digital Expansion with mechanical relays (D1608E)
- Digital Expansion with solid-state relays (D1608S)
- Analog Expansion (A0602)

### Setting up the OPC UA Server

To set up the **OPC UA** server, upload the [**`opta_opcua_server`** example](https://github.com/arduino-libraries/Arduino_OPC_UA/blob/main/examples/opta_opcua_server/opta_opcua_server.ino) to your Opta. This can be done using either the Arduino IDE or the Arduino CLI.

![Successful Compilation with Arduino IDE](assets/arduino-ide-compilation.png)

Run the following command to compile and upload the example if used with the Arduino CLI:

```bash
arduino-cli compile --fqbn arduino:mbed_opta:opta -v examples/opta_opcua_server -u -p /dev/ttyACM0
```

![Successful Compilation with Arduino CLI](assets/arduino-cli-compilation-upload.png)

***If you are not familiar with the __Arduino CLI tool__, you can refer to the getting started documentation found [here](https://arduino.github.io/arduino-cli/1.1/getting-started/).***

Next, connect the Opta to a network via its Ethernet port. Please make sure the network has a DHCP-enabled router or switch to assign an IP address to the device.

Use a serial monitor to check the server status and retrieve the device's IP address. You can use the Arduino IDE Serial Monitor or other programs like [**Putty**](https://www.putty.org/) to establish a serial connection.

The output will display details such as the **discovery URL**. Below is an example of the server log output on the Arduino IDE Serial Monitor:

![Server information with discovery URL - Arduino IDE](assets/opta-opc-ua-arduino-ide.gif)

With [**Putty**](https://www.putty.org/), the following serial connection shows the server information:

![Server information with discovery URL - Putty](assets/opta-opc-ua-cmd.gif)

The output information is as follows and you should see similar information:

```bash
[2024-12-11 22:19:08.000 (UTC+0000)] info/eventloop Starting the EventLoop
[2024-12-11 22:19:08.000 (UTC+0000)] warn/server AccessControl: Unconfigured AccessControl. Users have all permissions.
[2024-12-11 22:19:08.000 (UTC+0000)] info/server AccessControl: Anonymous login is enabled
[2024-12-11 22:19:08.000 (UTC+0000)] warn/server x509 Certificate Authentication configured, but no encrypting SecurityPolicy. This can leak credentials on the network.
[2024-12-11 22:19:08.000 (UTC+0000)] info/server Arduino Opta IP: 192.168.100.191
[2024-12-11 22:19:08.000 (UTC+0000)] info/server Arduino Opta Variant: Arduino Opta WiFi
[2024-12-11 22:19:08.000 (UTC+0000)] info/server OptaController 0 expansion modules detected.
[2024-12-11 22:19:08.000 (UTC+0000)] info/server stack: size = 16384 | free = 15400 | used = 984 | max = 4248
[2024-12-11 22:19:08.000 (UTC+0000)] info/server o1heap: capacity: 327520 | allocated: 66784 | peak_allocated: 68896
[2024-12-11 22:19:08.000 (UTC+0000)] info/server Thread: 0x2405ADA4 ("application_unnamed_thread"), Stack size: 4248 / 16384
[2024-12-11 22:19:08.000 (UTC+0000)] info/server Thread: 0x2405C960 ("rtx_idle"), Stack size: 328 / 896
[2024-12-11 22:19:08.000 (UTC+0000)] info/server Thread: 0x2405D338 ("lwip_tcpip"), Stack size: 792 / 1200
[2024-12-11 22:19:08.000 (UTC+0000)] info/server Thread: 0x2405DB60 ("shared_event_queue"), Stack size: 392 / 2048
[2024-12-11 22:19:08.000 (UTC+0000)] info/server Thread: 0x2405D090 ("main"), Stack size: 2224 / 32768
[2024-12-11 22:19:08.000 (UTC+0000)] info/server Thread: 0x2405C91C ("rtx_timer"), Stack size: 104 / 768
[2024-12-11 22:19:08.000 (UTC+0000)] info/server Thread: 0x2406AE40 ("USBevt"), Stack size: 136 / 256
[2024-12-11 22:19:08.000 (UTC+0000)] info/server Thread: 0x2405D250 ("stm32_emac_thread"), Stack size: 192 / 1024
[2024-12-11 22:19:08.000 (UTC+0000)] info/server Heap size: 10393 / 90272 bytes
[2024-12-11 22:19:08.000 (UTC+0000)] warn/server Maximum SecureChannels count not enough for the maximum Sessions count
[2024-12-11 22:19:08.000 (UTC+0000)] info/network TCP | Listening on all interfaces
[2024-12-11 22:19:08.000 (UTC+0000)] info/network TCP 604424824 | Creating listen socket for "192.168.100.191" (with local hostname "192.168.100.191") on port 4840
[2024-12-11 22:19:08.000 (UTC+0000)] info/server New DiscoveryUrl added: opc.tcp://192.168.100.191:4840
[2024-12-11 22:19:14.000 (UTC+0000)] info/server Arduino Opta IP: 192.168.100.191
```

In this example, the output displays the **IP address**:

```bash
192.168.100.191
```

The **discovery URL** is as follows, which indicates the OPC UA server is running at:

```bash
opc.tcp://192.168.100.191:4840
```

You can now connect to the OPC UA server running on Opta.

### Connecting to the OPC UA Server

Once the server is running, you can use any OPC UA compatible client to connect to the server using the discovery URL. This allows interaction with the device and any connected expansion modules.

The [**opcua-client-gui**](https://github.com/FreeOpcUa/opcua-client-gui) client will be used to connect to the OPC UA server running on Opta in this section.

### Using OPC UA GUI Client for Testing

The [**opcua-client-gui**](https://github.com/FreeOpcUa/opcua-client-gui) client can be used if you are interested in testing or further interaction with the OPC UA server. To install the tool, please use the following commands:

```bash
cd /tmp
```

```bash
git clone https://github.com/FreeOpcUa/opcua-client-gui && cd opcua-client-gui
```

```bash
python -m venv .venv
```
```bash
source .venv/bin/activate
```

```bash
python3 -m pip install --upgrade pyopenssl
```

```bash
python3 -m pip install --upgrade .
```

If you are on a Windows OS platform, please follow the next steps:

1. Install [**WinPython**](https://winpython.github.io/) and install the version including **`pyqt5`**.

2. Use `pip` to install **opcua-client**:

```bash
pip install opcua-client
```

It is recommended that the command be run within the *`WinPython Command Prompt`* downloaded with [winpython](https://winpython.github.io/).

3. Run via the script `pip` created: `YOUR_INSTALL_PATH\Python\Python35\Scripts\opcua-client.exe`

It will launch the GUI and connect to the OPC UA server running on the Opta using the discovery URL. You will be able to see similar results as in the following clip:

![OPC UA GUI client](assets/opta-opc-ua-gui.gif)

With this, Opta is ready to handle the OPC UA protocol through simple [OPC UA GUI client](https://github.com/FreeOpcUa/opcua-client-gui). The interface allows browsing, subscribing to variables, writing values, and performing other interactions.

***For more information about the simple OPC UA GUI client and dedicatd installation instruction sets, please refer to [__opcua-client-gui__ repository](https://github.com/FreeOpcUa/opcua-client-gui).***

### Memory Debugging Insight

Additional configuration is possible for developers requiring detailed heap and stack memory usage information. The `mbed_app.json` configuration file should be modified to include memory and stack statistics macros to enable this feature.

The `mbed_app.json` file is found within [**`ArduinoCore-mbed`**](https://github.com/arduino/ArduinoCore-mbed/tree/main) at:

```bash
variants/OPTA/conf/mbed_app.json
```

Or the location can be referenced [here](https://github.com/arduino/ArduinoCore-mbed/blob/main/variants/OPTA/conf/mbed_app.json).

Add the following macros to enable memory and stack statistics:

```bash
"target.macros_add": [
  ...
+  "MBED_HEAP_STATS_ENABLED=1",
+  "MBED_STACK_STATS_ENABLED=1",
+  "MBED_MEM_TRACING_ENABLED=1"
]
```

After making these changes, recompile the core library using the following commands:

```bash
cd ArduinoCore-mbed
```

```bash
./mbed-os-to-arduino -a -g OPTA:OPTA
```

## Interrupts

**Opta's analog/digital programmable inputs and user-programmable button are interrupt-capable**. An interrupt is a signal that prompts Opta's microcontroller to stop its execution and start executing a special routine known as the Interrupt Service Routine (ISR). Once the ISR finishes, the microcontroller resumes executing its previous routine.
Expand Down

0 comments on commit 5674889

Please sign in to comment.