In an earlier post, i have briefly mentioned about OPC UA and for what its being used for. Thanks to open source projects and developers, it is possible to build an industrial communication network without any cost except the hardware.
So in this post, i will explain how i have compiled an OPC UA Server and make it run on ESP32 embedded development board. You can find the source here. There are also other platforms that you can port the OPC UA server code but i chose ESP32, because of its dynamic development environment, called esp-idf and it has a built-in Wi-Fi.
OPC UA server function has been developed by using open62541 open source C stack, which lets you compile a server as small as 100kB.
Here are steps to compile OPC UA Server on ESP32;
1 – Get the latest esp-idf:
git clone --recursive https://github.com/espressif/esp-idf.git
On Windows: install.bat
On Linux: install.sh
Linux: source export.sh
2 – Get the opcua-esp32 under esp-idf examples:
git clone https://github.com/cmbahadir/opcua-esp32.git
(python) idf.py build
3 – Plugin the ESP32 development board you are using. I have used ESP32-EVB so if you got it you will be directly able to control the on board relays without changing the relay pin macros.
4 – To configure the ESP32 run the “menuconfig” command.
(python) idf.py menuconfig
Navigate to “Connection Configuration” and enter the Wi-Fi SSID (Name) and Password, of course you will need to set them if you are going to use the Wi-Fi.
5 – Flash the build to the board.
6 – Monitor to check if the board got IP and started the OPC UA Server. On the below screenshot ESP32-EVB board got ip “192.168.1.101”.
7 – Run an OPC UA Client to connect to the server. I have been using UAExpert from Unified Automation.
After connecting properly, you will be able to browse/subscribe/control GPIO 32 (Relay-1 on ESP32-EVB) and GPIO 33 (Relay-2 on ESP32-EVB).
If you want to use the on board ethernet of ESP32-EVB you need to change the line 19 in “components/include/ethernet_connect.h” as;
#define CONFIG_EXAMPLE_CONNECT_WIFI 1 to
#define CONFIG_EXAMPLE_CONNECT_ETHERNET 1
And you can set the GPIO’s from “components/open62541lib/model.h”;
#define BLINK_GPIO 2
#define DHT22_GPIO 4
#define RELAY_0_GPIO 32
#define RELAY_1_GPIO 33
DHT22 temperature sensor and led blink gpio’s are not functional but can be used after few modifications.
To conclude, now you got the cheapest opc ua server in your hand. It can even work with a proper battery, which i haven’t tried yet. Enjoy controlling devices around, over an industrial grade communication…
Useful Links and references: