Python libs: pip install opcua paho-mqtt
Prosys OPC UA simulation server: https://downloads.prosysopc.com/opc-ua-simulation-server-downloads.php
mosquitto (the MQTT broker): https://github.com/eclipse/mosquitto
Run helloworld_milo.py to connect with milo OPC UA server
- Run Prosys OPC UA simulation server
- Run helloworld_prosys.py
- Run server_test.py
- Run client_test.py
This is to retrieve data by calling get_value()
periodically. The followings are to retrieve data using Sub/Pub mode.
- Run server_test.py
- Run client_subpub_opctcp.py
ChatGPT: The opcua
library primarily supports the client-server model over TCP, so for Pub/Sub over UDP, additional steps and potentially different libraries are needed. Using OPC UA Pub/Sub over UDP in Python requires either specific support in your chosen library or the use of a C library like Open62541 with appropriate bindings.
class SubHandler()
is from python lib opcua, for Sub/Pub over TCP.
- Run in shell:
mosquitto
- Run in shell:
mosquitto_sub -t "test/topic" -v
- Run in shell:
mosquitto_pub -t "test/topic" -m "hello world"
See: eclipse/mosquitto: Eclipse Mosquitto - An open source MQTT broker (github.com). It is better to use "
instead of '
, as it seems they can make differences.
- Run in shell:
mosquitto
- Run publisher.py
- Run in shell:
mosquitto_sub -t "sensor/data" -v
In this test, paho.mqtt.client.publish() as publisher, mosquitto_sub as subscriber.
- Run in shell:
mosquitto
- Run publisher.py
- Run subscriber.py In this test, paho.mqtt.client.publish() is used as publisher, subscribe() as subscriber.
- Run in shell:
mosquitto
- Run Prosys simulation server, and set up in the PubSub tab,
- Key settings include address, encoding.
- The queue name is the topic name.
- Test it with
mosquitto_sub -t "prosysopc/json/data/urn:BGO-1043.ad.norceresearch.no:OPCUA:SimulationServer/WriterGroup1/VariableDataSetWriter" -v
- Run subscriber.py
In this test, Prosys simulation server is used as publisher, subscribe() as subscriber.