This is an example of using MQTTPubService. Messages issued by NX using MQTTPubService are collected and visualized using a monitoring tool based on Mosquitto + Telegraf + InfluxDB built on Docker.For details, please check this article (Japanese). The controller uses LineProtocolLib to generate Line protocol format data. For monitoring tools, using MQTTPubService is not mandatory. It can also be used for other purposes if the message is in Line protocol format. After building the project, you will be able to view the following dashboards.
By changing the data sent from the controller, cells on the dashboard, and their queries, you can perform monitoring as intended.
The following environment is required to use this project
Controller | NX1 or NX5 |
Sysmac Studio | I always recommend the latest version. |
Network | Avoid networks with large delays between the localer and controller. A ping value of about 30 ms is recommended. |
Docker | There is no problem if it is Docker Compose compatible. |
This project was built in the following environment.
Controller | NX102-9000 Ver 1.64 |
Sysmac Studio | Ver.1.60 |
Network | There was an average delay of 10 ms in Ping values between the broker and the controller. |
Docker | Docker Desktop 4.37.1 (178610) |
Build it by following these steps. If you run into problems, check the logs. A common occurrence is port conflicts.
First, launch the monitoring tool with Docker Compose. Open the monitor-tools directory in a terminal where you can run docker commands and run the following command.
docker compose --profile collect up -d
Once the monitoring tool is up and running, create an InfluxDB dashboard. This task only needs to be done once unless you destroy the InfluxDB Volume. Apply the dashboard template file as follows. The template file is "monitor-tools/nx102-9000_run_monitor.json", InfluxDB's "user/password" is "helltaker/chocolatepancakes".
Once the monitoring tool is ready, bring up the controller. The steps are provided for reference.
-
Check the project file hash
Nothing can be done if the project file is corrupted. -
Match the project's controller format to the controller you use
Older NX1 cannot use MQTT communications Library. Please check the MQTT communications Library manual for available versions. -
Change settings for "POU/Program/NotifyStatsWithLineProtocol"
Match the broker address, port number, and client ID to your environment. The broker is Mosquitto, which stands as a monitoring tool.iMqttSettings.BrokerAdr := 'YOUR_BROKER_ADR'; // '192.168.250.2'; iMqttSettings.BrokerPort := 1883; iMqttSettings.ClientID := 'YOUR_CLIEN_ID';
-
Change configuration/settings/controller settings/built-in EtherNet/IP port settings
Change the settings so that you can reach the broker. -
Adjust controller clock
If the clock of the connected terminal running Sysmac Studio is appropriate, it will be reflected. If you use NTP, make sure it is synchronized. -
Download project to controller
Run the program in run mode and check the event log for errors.
You can change settings by editing the .env file and secrets. Edit the .env file if there is a conflict with your host environment or if you want to change the topics you are subscribed to. Edit secrets if you want to change the secret information.
The default .env file is as follows.
# Mosquitto settings
MOSQUITTO_MQTT_PORT=1883
MOSQUITTO_WEBSOCKET_PORT=9001
# InfluxDB settings
INFLUX_PORT=8086
INFLUX_ORGANIZATION=monitor
INFLUX_BUCKET=machine
# Telegraf settings
TELEGRAF_HOSTNAME=localhost
TELEGRAF_MQTT_SUB_TOPICS=machine/#
Secrets stores each value as a separate file under the secrets directory. The default is below.
setting item | file | default |
---|---|---|
Influx admin user | secrets/.influxdb2-admin-username | helltaker |
Influx admin password | secrets/.influxdb2-admin-password | chocolatepancakes |
Influx admin token | secrets/.influxdb2-admin-token | THVjaWZlciwgQ0VPIG9mIEhlbGw= |
I recommend checking the hash value of the acquired Sysmac Studio project.
file | sha256 |
---|---|
MQTTPubServiceExample_MonitorTask.scm2 | a112194d6c1369a4af8b202d2594fe6e7eacb3e92387571787b62733c15bb913 |