How to run an OPC UA server on ESP32?

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:

2 – Get the opcua-esp32 under esp-idf examples:

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) 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.

  • (python) flash

6 – Monitor to check if the board got IP and started the OPC UA Server. On the below screenshot ESP32-EVB board got ip “”.

  • (python) monitor

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;


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:

6 thoughts on “How to run an OPC UA server on ESP32?

    1. Hello Tran,

      Thank you very much for your feedback.

      Yes, i have tried to connect over an OPC Client working on S7-1500 and it worked. But, it depends on your network configuration. For instance if there is a DHCP server with specified MAC Addresses
      ESP32 will not be able to get an IP Address, so OPC UA server will not start.

      If you try and could not connect please let me know by openning an issue in github.


  1. Hello
    while trying to work on OPC UA, encountered the following error on build command,
    ‘’ is not recognized as an internal or external command,
    operable program or batch file

    Can you help me out what am i doing wrong ?


  2. Hello !
    Thanks for this great tutorial. One question : Do you think its possible to use this on a Lilygo T-Call 1.3 ESP ?
    It´s an ESP32 with GSM on board. I am trying to send an analog value from the ESP32 to WinCC via OPC UA.


    1. Hello Jens,

      Thank you for the positive feedback.

      I expect it to be compiled and flashed successfully on Lilygo T-Call board and connect over Wi-Fi. But ofcourse you need to configure the analog or digital peripherals according to your setup with Lilygo. And if you want to use OPC UA over GSM, it won’t work, to be honest i do not know if its even possible. 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s