In an earlier post, i have briefly mentioned about OPC UA and what it is 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.
If you want to download and use immediately then please move on this post. But if you are ok with building things from source then proceed 🙂 .
On 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, or if you are interested in a ready to use one then please contact me over 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 embedded servers as small as 100 kB.
Here are the 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 – Plug the ESP32 development board you are using. I have used ESP32-EVB so if are also using it you will be able to control the on board relays without making any changes in the code.
4 – Configure the ESP32 with “menuconfig” command.
(python) idf.py menuconfig
Navigate to “Connection Configuration” to set the type of connection (Wi-Fi or Ethernet), Wi-Fi SSID, password and static IP configuration. Currently static IP can only be set for ethernet.
You can see the config options you can set for your OPC UA server under “Connection Configuration” as;
5 – Flash the build to the board.
6 – Run monitor to check if the board got IP and started the OPC UA Server. This is required if you have not set an IP address to ESP32 board via DHCP or not connecting over ethernet with a static IP address.
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).
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.
So, now you got the cheapest opc ua server in your hand. It can even work on battery, which i haven’t tried yet. Enjoy controlling devices around, over an industrial grade communication…
If you are interested in a ready to use one, please contact me over here.
Useful Links and references: