cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

How to use MQTTSubscribe function block in MQTT Client SL library to subscribe to a mqtt topic

How to use MQTTSubscribe function block in MQTT Client SL library to subscribe to a mqtt topic

ahmadKhairi
Established Member

Hi,

I am just trying out the MQTT Client SL library after installing the CODESYS IIoT Libraries into ctrlX PLC.

I am using Cedalo MQTT broker installed in my ctrlX CORE at port 8883.

From ctrlX PLC, I have successfully connected to the MQTT Broker using the MQTTClient function block.

So my next attempt is to subscribe to a mqtt topic by using the MQTTSubscribe function block.

The topic in this case is a "Temperature" topic that was already published to the mqtt broker from a sensor.

My attempt is to retrieve the message from the topic in ctrlX PLC.

According to the FB description, the input wsTopicFilter is a WSTRING(1024) data type.

However after adding the MQTT Subscribe FB and downloaded to PLC, I got the error at the output of the MQTTSubscribe FB:

VAR_OUTPUT MQTTSubscribe.eMQTTError : MQTT_Error --> TOPIC_FILTER_EMPTY

Can anyone help?

2 REPLIES 2

HmiGuide
Community Moderator
Community Moderator

The topic in MQTT is the name of the variable you want to retrieve.
This name can contain wildcards, therefore I the FB parmater is called TopicFilter.
In your screenshoot you just provide an empty string "" which makes no sense.

Therefore you get the error message, which exactly points you to the problem.

Hi, thank you for your feedback. Yes you are right.

I managed to find the solution when I referred to the example MQTT Client SL FB with the visualization.

Everything works now. Since the MQTTClient and MQTTSubscribe variables are available in the Data Layer, I brought it up to webiq and created a similar hmi which now can be accessed using a tablet pc/iPad.

Thanks!

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist