Troubleshooting
Why MQTTSubscribe returns the TOPIC_FILTER_EMPTY error
Short answer
MQTTSubscribe reports TOPIC_FILTER_EMPTY when its wsTopicFilter input still holds an empty string at the moment the block executes; the MQTTClient connection to the broker on port 8883 is not the fault, because a connected client never populates the filter. Assign the publisher's exact topic text, verify it online, and confirm the PLC receives a payload before trusting the HMI.

On this page
- What the error names and what it does not
- Why a connected client cannot fill the filter
- Assign the topic text in the application
- Worked example: checking the Temperature filter against the 1024-character limit
- Verify online, then prove the payload arrives
- When the error clears but no message arrives
- The decision for each case
- Questions asked
TOPIC_FILTER_EMPTY at the eMQTTError output of MQTTSubscribe has one meaning: the block executed while its wsTopicFilter input still held an empty string. Your MQTTClient connection to the broker on port 8883 succeeded, and that success is exactly why the fault sits at the subscription input — a connected client never fills the filter in for you. Assign the publisher's exact topic text, in this case Temperature, to wsTopicFilter, confirm the value online, and then confirm the payload reaches the PLC before you trust anything an HMI displays. What follows is the fix, a worked check of the filter against the documented topic limit, and the order of diagnosis for everything that can remain after the error clears.
What the error names and what it does not #
The data path has two directions. The sensor publishes its measurement to the broker under the topic Temperature; the PLC, over its client connection, sends a subscription request naming the topic it wants, and the broker forwards matching messages back. TOPIC_FILTER_EMPTY is raised at the entry of that second hop: MQTTSubscribe, from the MQTT Client SL library for CODESYS controllers, looked at wsTopicFilter, found no topic text, and reported it at eMQTTError, whose type is MQTT_Error.
The declaration WSTRING(1024) describes the input's type and capacity — the controller's wide-string type — but a declaration never populates a value. After download, an untouched wide string initializes as an empty string, so the error appears the first time the block executes.
Each element of the chain, and its state in this case:
- MQTTClient — holds the connection to the broker. Already established; not the fault.
- MQTTSubscribe — sends the subscription request and reports the outcome at eMQTTError.
- wsTopicFilter — the filter text the broker matches against published topics. Empty here.
- TOPIC_FILTER_EMPTY — the enumeration value meaning the filter contained no topic text when the block ran.
Why a connected client cannot fill the filter #
A connection and a subscription are separate MQTT operations. The connection is only the transport; each subscription is its own request, and the MQTT specification requires its topic filter to be at least one character long. There is no default topic: the broker cannot guess which topic a client wants, and the library does not invent one. A working connection on one block and an empty filter on another is therefore a consistent state — the first block did its job, the second has nothing to send. The error text is precise; fill the input and the block has a request it can send.
Assign the topic text in the application #
- Open the application and locate the MQTTSubscribe instance that shows the error in the online view.
- Declare a filter variable of the input's type and initialize it with the publisher's topic text. The name is yours; for example:
VAR
wsFilter : WSTRING(1024) := "Temperature"; // illustrative variable, any name
END_VAR
- Connect that variable to wsTopicFilter. Do not leave an empty literal
""wired to the input. - Match the publisher's spelling exactly. MQTT topic names are case-sensitive, so
Temperatureandtemperatureare two different topics. - Leave the working MQTTClient configuration untouched; the broker address, port and credentials were never part of this fault.
- Download the application and run the subscription the way the library's own example project does — the MQTT Client SL example with its visualization is the reference for wiring and call order.
- Watch eMQTTError on the next execution: TOPIC_FILTER_EMPTY must be gone.
Worked example: checking the Temperature filter against the 1024-character limit #
Inputs, each with its source:
- Filter text to apply:
Temperature, the topic the sensor already publishes — from the publisher's configuration. - Value found at wsTopicFilter when the error appeared: an empty string, 0 characters — from the online view after download.
- Maximum topic size: 1024 characters — from the MQTT Client product data sheet, which declares topics as WSTRING.
- Broker endpoint: port 8883, client connection already up — from the MQTTClient status in the project.
The rule in words: a subscription filter must be at least 1 character long and at most the documented maximum topic size. An empty filter fails before any subscription exists, and that local failure is what TOPIC_FILTER_EMPTY reports.
The arithmetic:
- Characters in
Temperature: T-e-m-p-e-r-a-t-u-r-e = 11 characters. - Length check on the intended filter: 1 ≤ 11 ≤ 1024, so it passes.
- Length of the value actually applied: 0 characters, and 0 < 1, so it fails.
Result: Temperature is a valid filter for this library, and the empty string was the entire fault — the working client connection played no part.
Decision: assign Temperature to wsTopicFilter and re-read eMQTTError on the next execution. Every filter inside the valid range passes the length rule; above 1024 characters, shorten the topic at the publisher rather than the filter, because the data-sheet limit governs the topic itself.
Verify online, then prove the payload arrives #
- Online value: while the block executes, wsTopicFilter must read
Temperature. A blank here means the variable you filled is not the one wired to this instance. - Same instance: if the value is visibly set yet the error persists, the block you are monitoring is not the block that is executing; find the second instance and fix that wiring.
- Receipt in the PLC: with the sensor publishing — or with one manual publish to
Temperatureas a test — confirm the payload delivered by the block updates in the controller with fresh content. - Display last: only after the PLC variable updates, check the HMI.
When the error clears but no message arrives #
A cleared TOPIC_FILTER_EMPTY proves exactly one thing: the filter is no longer blank. If nothing arrives after that, work in this order:
- Compare the filter with the topic the publisher actually uses, character by character, capitalization included.
- Confirm the publisher is still sending, and to the broker and topic you assume.
- Confirm the client connection stayed up; if the client reconnected with a fresh session, the subscription request must run again.
If the client stays connected and the subscription still delivers nothing, continue with Why an MQTT subscribe function block connects but receives nothing. If the client never connected at all, that is a different fault, with its own sequence in Fix a PLC MQTT client that never reaches your broker.
The decision for each case #
- Blank filter, error present: assign the publisher's exact topic text to wsTopicFilter; the error clears on the next execution, and no broker change is needed.
- Set filter, error present: the monitored instance and the executing instance differ; fix the wiring of the block that actually runs.
- Error cleared, no payload: correct the topic text or the publisher first; with both verified, follow the connect-but-receives-nothing diagnosis.
- Payload in the PLC, HMI blank: the subscription works; the fault is in the display mapping, downstream of the MQTT path.
Questions asked
Can wsTopicFilter contain MQTT wildcards?
Yes. The input is a topic filter, and MQTT subscription filters accept a single-level wildcard and a multi-level wildcard. For a first test, use the exact topic so that one publisher matches and the result is unambiguous. Add wildcards only when you deliberately want several topics delivered through one subscription, and expect every matching payload to arrive on the same block output.
Why is wsTopicFilter a WSTRING, and what if my topic text is in a STRING?
The library declares all topics as WSTRING, so the input expects the controller's wide-string type, written as a literal in double quotes. If your topic text lives in a plain STRING variable, convert it to the wide type before the block executes; the two string types are not interchangeable at that input, so an assignment between them is refused.
Does TOPIC_FILTER_EMPTY mean the broker rejected the subscription?
No. The enumeration is raised at the function block itself: a filter with no topic text is caught before it can become a working subscription, and the block reports the empty input rather than a broker response. Since the client connection already succeeded in this case, there is no broker-side fault to chase. Correct the input and let whatever the block reports next select the following step.
What sets the maximum length of the topic filter?
The product data sheet for the MQTT Client library fixes a maximum topic size, and the declared length of wsTopicFilter matches it. A longer topic is not a valid topic for this library, so shorten it at the publisher rather than truncating the filter; a truncated filter would match nothing or the wrong topics.
The PLC receives the payload but the HMI stays blank. Where is the fault?
In the display path, not the subscription. The client and subscription variables can be exposed to an HMI through the controller's data layer, and that layer only shows what the PLC holds. Re-map or refresh the displayed symbol, then confirm the value updates in the PLC first and on the panel second. A blank panel over an updating PLC variable is a mapping problem.


