GENESIS V11 - MQTT connection to iQ-F PLC (FX5-ENET)

GENESIS V11 - MQTT connection to iQ-F PLC (FX5-ENET)

Info
This article explains how to read data from an iQ-F series FX5-ENET module to GENESIS V11 using a dedicated decoder. A sample GX Works3 project used in this example is added as an attachment.

Precautions

The MQTT communication function is officially supported by iQ-F series module FX5-ENET if you have the required versions of CPU firmware, module firmware and GX Works3:


If you don't have the FX5-ENET module or your module is too old for a firmware update, the only option is to use Function Blocks that connect to the broker using a standard TCP connection on the built-in Ethernet port as described here.

MQTT Broker configuration

A Broker is always necessary to manage MQTT connections. In this example a free MQTT Broker Mosquitto was used. An example of how to configure Mosquitto can be found in this article and many other sources.

PLC Configuration

1 MQTT connection settings

The MQTT communication needs to be enabled in FX5-ENET module parameters in GX Works3:



After that, click on Detailed Setting below and set your broker address. You can also configure login, password and certificate settings here if needed depending on your broker settings. The Client ID is how the PLC identifies itself when connecting to the broker - you can set any ID you want, but it should be unique if more devices connect to the same broker.


2 JSON program

MQTT messages are usually sent in JSON format. A dedicated Function Block libary for iQ-F fb-strprocessing_f_v100 contains a function block that prepares a message in a format expected by the FX5-ENET decoder in GENESIS.

To generate the JSON message, data needs to be written to a configuration array as described in the library manual (you can find it in the library .zip file attached to this article). Each element of the array requires 4 values:



In this example an ST program was created to prepare the message by writing values to the array and calling the function block:


Set the bUpdateJSON variable each time you want to refresh the message. The message generated by this program is formatted like below:

Quote
{
  "Floor1/Room101/LightsOn": 1,
  "Floor1/Room101/Temperature": 21.37,
  "Floor1/Room102/LightsOn": 0,
  "Floor1/Room102/Temperature": 22.5,
  "Floor2/Room201/LightsOn": 1,
  "Floor2/Room201/Temperature": 23.4
}

3 Communication program

To communicate with the broker, standard function blocks for FX5-ENET are used. M_FX5ENET_MQTT_Connect_00A block needs to be used to establish connection. First set the bEN input, then bConnect and check the outputs to confirm a successful connection:


After a successful connection, data can be published to the configured MQTT topic using the M_FX5ENET_MQTT_PublishSend_00A block. To do this set the bEN input, then set bPublish each time you want to send a new message:


The sample program also has function blocks to subscribe to a topic and receive data, but they are not necessary if you only want to send data to GENESIS.

GENESIS configuration

Make sure the ICONICS Internet of Things Subscriber Point Manager service is running:


Under Data Connectivity -> Internet of Things in Workbench, add a connection to your broker:


Then add a Subscriber Connection to the topic your PLC is publishing data to. Make sure to select the Mitsubishi FX5-ENET JSON decoder and check Create Virtual Hierarchy:


Alert
When upgrading from previous GENESIS 11 versions to version 11.02, the Mitsubishi FX5-ENET JSON decoder is not immediately visible. To display the decoder:
Delete C:/ProgramData/ICONICS/11/FwxIotSubscriber.Plugins.config.xml, and then restart Workbench and Internet of Things Subscriber.

After any data is published by the PLC, it should be available in Data Browser (BuildingA is the name of the topic set in PLC program):


If Create Virtual Hierarchy was not enabled, data from the same message format would look like this: