Troubleshooting
When MQTT does not compile on an OpenPLC Windows runtime
Short answer
The MQTT demo cannot run on the OpenPLC Windows runtime: MQTT is implemented only for microcontroller targets, so the Structured Text build stops while generating C files and the green running status belongs to the previously compiled program. Put the MQTT client outside the runtime as a Modbus/TCP-to-MQTT bridge in Node-RED or Python, or write it into the project with a Python Function Block on OpenPLC v4.

On this page
- Why does the MQTT demo fail to compile on the OpenPLC Windows runtime?
- What do the 16 compile errors in the ST build log mean?
- Why does the runtime show a green status while the program never compiled?
- How do you get MQTT data into an OpenPLC Windows runtime?
- Should the bridge be a Python script or a Node-RED flow?
- Can the MQTT client run inside the PLC project on OpenPLC v4?
- What happens to the GPIO pins on a Raspberry Pi 4 under runtime v4?
- How should the bridge map MQTT topics into PLC registers?
- How do you verify the compile, the download and the bridge separately?
- Questions asked
The MQTT demo cannot run on an OpenPLC Windows runtime. MQTT support exists only for the microcontroller targets, so the demo's Structured Text build stops while generating C files with 16 errors, and the green running status you see afterwards belongs to the previously compiled program. The frozen blink_led and mqtt_connected watches confirm it: the new program never loaded. The working path keeps the MQTT client outside the runtime — a Modbus/TCP-to-MQTT bridge in Node-RED or Python — or, on OpenPLC v4, writes it into the project with a Python Function Block. On a Raspberry Pi 4 that also drives its GPIO pins, runtime v3 remains the right choice.
Why does the MQTT demo fail to compile on the OpenPLC Windows runtime? #
The demo fails because MQTT exists only in the microcontroller implementation of the runtime: the Windows and Linux builds carry no MQTT code behind those function blocks, so the Structured Text compiler stops while generating C files and never produces an executable you could download.
The asymmetry has a mundane cause. The microcontroller implementation is built on the Arduino framework, which supplies an MQTT library that runs on Arduino-compatible boards; the Windows and Linux runtimes would need their own cross-platform library, and none has shipped yet. That is why the same demo compiles on a networked Arduino-compatible board and fails on a PC. It also means no broker-side setting can help: the build stops before the broker address, the credentials or any firewall rule is ever read. Stop re-downloading the demo and plan the bridge instead.
What do the 16 compile errors in the ST build log mean? #
The 16 errors are one real fault plus its cascade: two invalid variable declarations on lines 8 and 9 of the generated 691186.st, then 7 statement errors on line 18 and 7 on line 20, and 2 + 7 + 7 = 16 matches the summary line.
Read the first two errors and treat the rest as noise. Lines 8 and 9 fail with invalid specification in variable declaration: the compiler met declarations it cannot resolve on this target — the MQTT function-block types the demo assumes. Everything after is cascade: once those declarations are unknown, lines 18 and 20 produce invalid variable before ':=' in ST assignment statement, ';' missing at the end of statement in ST statement and invalid statement in ST statement, because the compiler no longer knows what those names are.
That settles what not to do. Adding semicolons or retyping the assignments cannot repair a missing implementation, and the summary lines — 16 error(s) found. Bailing out!, then Error generating C files and Compilation finished with errors! — record a build that stopped before any executable existed.
Why does the runtime show a green status while the program never compiled? #
The green running status means only that some program is executing; after a failed compile that program is the previously compiled one, which is why blink_led and mqtt_connected never change — the demo you downloaded never reached the runtime.
Keep three checks separate: build acceptance, application identity and variable behavior. The status lamp proves the runtime's loop is alive, not which application it is looping. The watch list proves the rest: both demo variables frozen at their initial values is the signature of the old program still executing, because the program that would change them never loaded. If the previous application happens to drive the LED, the LED tells you nothing about the new download either — application identity needs its own evidence, a behavior only the downloaded program produces.
How do you get MQTT data into an OpenPLC Windows runtime? #
Put the MQTT client outside the runtime: a small bridge process talks MQTT to your broker on one side and Modbus/TCP to the runtime's registers on the other, so the PLC project reads and writes plain registers and never needs the unsupported MQTT blocks.
The options differ in where the client lives:
- Python script bridge — one process that is an MQTT client toward the broker and a Modbus/TCP client toward the runtime; you own every line, which suits audited deployments.
- Node-RED flow — the same two clients wired visually, with the MQTT and Modbus connections configured once and editable without a code editor; the pattern is the one described in MQTT to Modbus TCP with Node-RED on an edge gateway.
- Python Function Block on OpenPLC v4 — the client code sits inside the PLC project itself; needs a v4 deployment, covered below.
- Microcontroller target — the only place the built-in MQTT blocks work; an Arduino-compatible board with WiFi or Ethernet.
For a Windows or Linux runtime that needs MQTT today, the external bridge is the only option that compiles as-is.
Should the bridge be a Python script or a Node-RED flow? #
Choose Node-RED when you want to edit the map without a code editor and see the flow; choose Python when you want one auditable script; both designs were reported working against this exact runtime, and both keep MQTT entirely off the compile.
The choice is about maintenance, not capability. Node-RED wins when the person on shift edits flows in a browser and wants connection status visible at a glance; Python wins when you want one file in version control with logs you can grep. Either way the bridge needs a small host that runs around the clock — a fanless mini PC mounted in the cabinet next to the runtime host does that without occupying an engineer's workstation. Broker placement is a separate decision, and the trade-offs of running an MQTT broker in the PLC or on a separate device apply unchanged: the bridge and the broker do not have to share a machine.
Decision: browser-edited flow for shift maintenance, single script for version-controlled deployments — both on their own always-on host.
Can the MQTT client run inside the PLC project on OpenPLC v4? #
Yes on OpenPLC v4: a Python Function Block lets you write the MQTT client code directly in the PLC project, with no separate editor or tool — but this needs a v4 runtime deployment, and it does not repair the demo on the older Windows runtime.
OpenPLC Runtime v4 is a headless runtime that executes IEC 61131-3 programs on standard computing hardware and pairs with OpenPLC Editor v4; the Python Function Block is the v4 feature that makes the in-project client possible. Driver and protocol extensions are handled by v4's plugin system, which is also why capabilities differ between runtime versions. Treat this as an architecture migration, not a repair: moving a working installation to v4 mid-fault trades one problem for two.
Decision: use the Python Function Block when the deployment is moving to v4 anyway; keep the external bridge on existing installs.
What happens to the GPIO pins on a Raspberry Pi 4 under runtime v4? #
Runtime v4 has no drivers for the Pi's GPIO pins, so the %QX output mappings that worked under v3 stop driving physical outputs; use runtime v3 on the Pi when the project needs GPIO, and the v4 editor works with both runtimes.
The case behind that restriction is concrete: a Pi 4 project moved to v4 and its %QX outputs stopped driving pins, and the interim workaround was Node-RED writing Modbus coils that a separate process mapped to the physical pins. That workaround adds a moving part exactly where outputs live, which is the wrong trade for machine control. MQTT needs do not force the move — the bridge pattern works against runtime v3 the same way it works on Windows.
Decision: on a Pi that switches real outputs, stay on runtime v3 and take MQTT from a bridge; move to v4 only once the outputs no longer depend on %QX GPIO.
How should the bridge map MQTT topics into PLC registers? #
Define the map before you configure either tool: one table that fixes each topic, its direction, its register, its data type and its scale, so a subscribed payload becomes a typed register write and a register read becomes a published value.
Worked example, with illustrative values: the bridge subscribes to line1/heating/setpoint and receives the payload string 215; it converts that to the unsigned integer 215 and writes it to the holding register your project mapped for the setpoint. The Structured Text logic applies the project's fixed scale of 0.1 °C per count, so the applied setpoint is 215 × 0.1 °C = 21.5 °C. In the reverse direction the program writes the measured value 198 to its status register, and the bridge publishes 198 × 0.1 °C = 19.8 °C to line1/heating/actual. Keep the ×0.1 scale in exactly one place — the bridge or the project, never both.
Watch the register-address convention if the first write lands one register away from where you expected: the offset question behind Modbus error 8189 — why 400001 has to be added to the register address — is the same trap, and page explaining why Modbus error 8189 needs 400001 added to the register address walks through it. One safety rule belongs here: keep the interlocks in the PLC program, treat every subscribed write as a setpoint the Structured Text logic still limits, and never let a topic write an output that drives a pump or valve directly.
How do you verify the compile, the download and the bridge separately? #
Verify in this order and do not merge the steps: a compile with zero errors, proof the intended program is the one loaded, a Modbus read-back of each mapped register, and a publish-and-subscribe test through the broker before any real value moves.
- Rebuild and require a clean log — no errors, no bailing-out summary, a completed download. A log repeating the same first declaration errors means the same unsupported program is being built again.
- Prove application identity with one behavior only the downloaded program produces;
blink_ledcounts as evidence only if the loaded program is the one updating it. - Read every mapped register back with a second Modbus/TCP client before the bridge is allowed to write to it.
- Publish a test message to each command topic from a separate client and watch the bridge receive it and change the register.
- Track three health states independently — broker connection, Modbus transaction success, fresh data — because one healthy connection proves none of the other two.
Decision for each case: a Windows or Linux OpenPLC runtime that needs MQTT today takes an external Modbus/TCP-to-MQTT bridge — Node-RED for visual maintenance, Python for a single auditable script. An OpenPLC v4 deployment without GPIO needs takes the Python Function Block. A Raspberry Pi 4 driving real outputs stays on runtime v3 plus the bridge. A networked Arduino-compatible board runs the built-in demo, the only place it compiles.
Questions asked
Does the same limitation apply to the OpenPLC runtime on a Raspberry Pi?
Yes. The Raspberry Pi runs the desktop-class runtime, not a microcontroller build, so it has the same gap: no MQTT inside the runtime regardless of how capable the board is. Run the bridge on the Pi itself, which is often the most convenient host anyway, and let the PLC project talk plain registers.
Can an Arduino Mega 2560 run the MQTT demo?
No. MQTT on the microcontroller targets needs a board with WiFi or Ethernet, and the Mega 2560 has neither, so the demo's build fails inside its MQTT module before any connection is attempted. On a networked Arduino-compatible board the same demo compiles and runs, which remains the only place the built-in MQTT blocks work today.
Why does the build log report a missing ethercat file?
A message that a file called ethercat could not be found appears in the same build output, but it is a separate file-access diagnostic: not one of the 16 counted Structured Text errors and not the reason the compile stopped. Concentrate on the declaration errors; the ethercat message only matters if EtherCAT hardware is actually in use.
What should mqtt_connected show once you move to a bridge?
Nothing useful. mqtt_connected belongs to the demo program that never compiled, so it cannot report the state of an external Node-RED flow or Python process. Build your own health signal instead: have the bridge publish a periodic heartbeat the project watches, and treat a stale heartbeat as the bridge being down rather than the broker.


