IMD SolutionComputing LibraryShop main store

Explainer

Why MQTT setpoint gating belongs in CODESYS, not the client

Edge computing and IIoT Published 9 min read By IMD Solution engineering team

Short answer

Gate MQTT setpoints in the controller, not the client: no client read-write mode can read your Local/Remote switch. Keep the Ignition Edge subscription connected, land remote values in their own scratch-pad word, let groov View write a separate local word, and let one CODESYS function block select between them from the switch input, so Local blocks control while status keeps publishing.

On this page
  1. Can a client setting gate MQTT setpoints on a physical switch?
  2. What does a publish-only or subscribe-only mode actually control?
  3. Why must the MQTT subscription stay connected during Local?
  4. Where should the local and remote setpoints live?
  5. How should CODESYS select between the two setpoints?
  6. Which remote command wins when the switch turns to Remote?
  7. How do you commission and prove the selection logic?
  8. Questions asked

There is no client setting that will gate MQTT setpoints on your Local/Remote switch, and the connection is the wrong layer to try: your status telemetry and your remote control share one session. Keep the Ignition Edge subscription connected at all times, land each remote setpoint in its own scratch-pad word, give the groov View setpoint a second word, and let one small CODESYS function block choose between them from the switch's digital input. Local then blocks control, not communication, and local changes keep publishing upstream to the main Ignition server. What follows are the word assignments, the selector logic, the worked numbers behind the switch-over rule and the commissioning sequence.

Can a client setting gate MQTT setpoints on a physical switch? #

No — there is no client setting that reads your Local/Remote switch, because a read-only, write-only or read-and-write mode governs message direction on the wire and nothing else; the gate you want is one arbitration function block in CODESYS, driven by the switch wired to a digital input.

The idea is worth closing off quickly. MQTT is the OASIS-standard publish/subscribe protocol (version 5.0 dates from 2019), and the standard describes transport: connect, publish, subscribe, acknowledge, disconnect. It has no concept of an operating mode, no field that carries a permissive and no place to evaluate an input every control cycle. The connection screens in Ignition Edge configure broker address, port, authentication, keep-alive and topic mappings — all of it transport.

On a groov EPIC the switch terminates at a digital input of the controller, and the only software on that device with cycle-by-cycle access to the process image is CODESYS, which runs the IEC 61131-3 languages alongside Ignition Edge on the same processor. The MQTT module has no scan engine, so even a hypothetical block-reception toggle could not judge a permissive, time a transition or decide what a queued command means. The gate belongs at the layer that owns the input and the interlocks.

What does a publish-only or subscribe-only mode actually control? #

It controls which direction the client may move MQTT messages — publish outbound, subscribe inbound, or both — and it never evaluates a switch input, applies a pump permissive, or defines what happens to a command that arrived while reception would have been blocked.

A direction switch on a client does exactly that and no more: publish-only sends outbound, subscribe-only accepts inbound, both does either. Broker-side access rules, where a broker offers them, judge nothing but topic names and client identity. None of these options knows that an operator flipped a switch, none can hold a setpoint back until the pump is in a state to accept it, and none defines what a command received during Local should do — apply on switch-over, hold for a fresh command, or discard. Those are control decisions, and they need the rung logic that also owns the permissives.

Per-topic write rejection, where a client configuration exposes it, is the same idea in blunter form: it blocks by topic continuously, not by mode, and it cannot read your switch to restore reception when the operator turns back to Remote. So leave the Edge client in full publish-and-subscribe and spend the effort on the selector.

Why must the MQTT subscription stay connected during Local? #

Because your status publication and your future remote control both depend on that one session: drop it in Local and the upstream system stops seeing local changes, while a retained setpoint waits on the broker and redelivers the moment you reconnect.

Three things break if the session itself is your gate. First, the requirement: local changes must always reach the main Ignition site, and a disconnected Edge client publishes nothing. Second, retained messages: if the setpoint topic is retained, the broker stores the last value and hands it to your client on every connect, so a subscription you disable in Local and re-enable in Remote is precisely the mechanism that delivers the stalest command at the least guarded moment. Third, queuing: for a persistent session, QoS 1 and QoS 2 messages accumulate on the broker while the client is away and arrive together on reconnect, and a burst of old setpoints is the last thing you want meeting a just-turned Remote switch.

Keep the session up permanently and treat delivery and acceptance as separate events: the client receives, the selector decides. Keep the inbound control topic and the outbound status topics distinct in the data model — the same discipline as keeping publish and control separate in Node-RED.

Where should the local and remote setpoints live? #

In two different scratch-pad words: the MQTT setpoint gets its own word, the groov View setpoint a second, and a third carries the published selected command, so CODESYS can always tell which path wrote what.

On a groov EPIC the shared landing zone is the OptoMMP scratch pad, a memory area that applications and peer devices can write and that the processor itself reads. groov View reads and writes it, the Edge MQTT configuration maps the setpoint topic to a scratch-pad address, and CODESYS reaches it through the OptoMMP function blocks — the published hello-world example writes a string to the scratch pad and shows it on the Generic MMP page in groov Manage, which is also where you watch your words change during commissioning. Assign three words and keep them apart: for example word 3 for the groov View local request, word 4 for the MQTT remote request and word 5 for the published selected command. The indices are yours to choose; the separation is not. Two writers on one command word erase the only information the selector needs, which path supplied the value.

Keep the published status word observational: if the upstream copy of the selected command can loop back into a command word, an echo looks like a new remote instruction — the one-way discipline behind how robot PROFINET data reaches the PLC in one direction only.

How should CODESYS select between the two setpoints? #

With one function block that takes the local request, the remote request, the switch state from the process image and the write events, and outputs the single selected command the pump sequence uses: Local accepts only the local request, Remote accepts the most recent write of either.

Switch position Local request word Remote request word Selected command
Local eligible updated, held, not eligible local request only
Remote eligible eligible most recent write of either, by write event

Implement the selector as a function block; the IEC 61131-3 languages CODESYS runs on the EPIC are built for exactly this shape of decision. Illustrative names and types, not a vendor API: xRemote of type BOOL, TRUE when the switch is in Remote, read from the process image every scan; rLocalReq and rRemoteReq of type REAL, the two request words scaled to engineering units; xLocalNew and xRemoteNew of type BOOL, one-scan pulses raised where each write lands; rSelCmd of type REAL, the output the pump sequence consumes.

(* Illustrative selector; names and types are examples, not a vendor API *)
IF NOT xRemote THEN
    IF xLocalNew THEN
        rSelCmd := rLocalReq;      // Local: the local request only
    END_IF;
ELSIF xRemoteNew THEN              // Remote: most recent write wins
    rSelCmd := rRemoteReq;
ELSIF xLocalNew THEN               // Remote: a fresh local write still counts
    rSelCmd := rLocalReq;
END_IF;

Raise the pulses where the writes land, not from the values: a sequence word the publisher increments alongside the remote setpoint, a commit word the display writes alongside the local setpoint, or the write event the integration itself exposes. A sender that re-issues the same setpoint is issuing a new command, and a value that never changes proves nothing about order. If a local and a remote write land in the same scan, the remote branch above wins the tie — decide ties deliberately and document them. Range checks and pump permissives come after this block, in both modes.

Which remote command wins when the switch turns to Remote? #

The newest permitted write wins, identified by its write event rather than its value, and because your requirement is the latest command, a remote write that arrived during Local becomes active the moment the switch turns to Remote — 30 seconds old in the worked example below.

Run the numbers on a pump speed setpoint scaled 0 to 100 percent, with every write stamped in order. The Edge client stays connected throughout; nothing is disabled in Local.

Time Switch Write Stamp Selector output
14:00:00 Remote MQTT, 72 % 41 72 %
14:00:25 Remote MQTT, 70 % 42 70 %, stamp 42 newer than 41
14:01:10 Local groov View, 65 % 43 65 %, only the local word eligible
14:03:30 Local MQTT, 68 % 44 stays 65 %; remote word updates and waits
14:04:00 Remote switch turns, no new write — 68 % applies, 30 seconds old
14:04:12 Remote MQTT, 66 % 45 66 %
14:05:40 Remote groov View, 67 % 46 67 %, newest stamp wins in Remote

The arithmetic worth checking is ordering and elapsed time. Stamp 42 supersedes stamp 41 because 42 is newer, not because 70 differs from 72; the stored command written at 14:03:30 is 30 seconds old when the switch turns (14:04:00 minus 14:03:30); and if you instead require a fresh write after switch-over, the operator waits 12 seconds for the next remote command (14:04:12 minus 14:04:00). Commit to the rule your requirement names — newest permitted write, accumulated during Local, applied on switch-over. Pick the fresh-write variant only at stations where a stored command must never actuate unattended, and publish whichever rule you choose on the display. One safety note: this gate arbitrates availability, not protection — hardwired permissives and the pump interlocks stay in the controller in both modes.

How do you commission and prove the selection logic? #

Prove it in six steps: map the switch input, separate the scratch-pad words, show delivery before logic, show Local ignoring live remote writes, show Remote following the newest write from either source, and confirm the permissives sit downstream of the selector.

  1. Operate the physical switch through both positions and record the digital-input states in CODESYS; measure the mapping, do not assume which state means Remote.
  2. Assign the three scratch-pad words and confirm on the Generic MMP page that a write to one never disturbs the others.
  3. Prove delivery before proving logic: from the upstream system, write the remote setpoint while the switch is in Remote and confirm the word changes. A connected indication alone proves nothing — it is the same failure class as an MQTT subscribe function block that connects but receives no messages.
  4. In Local, send live remote writes and confirm the remote word updates while the selected command does not move; then change the groov View setpoint and confirm the selected command follows it and the new value publishes upstream.
  5. In Remote, alternate distinguishable writes from groov View and MQTT and confirm the selector lands on the newest permitted write every time, including a re-issued identical value.
  6. Confirm the range checks, permissives and interlocks sit downstream of the selector, so neither source can bypass them.

The decision, stated once: leave every MQTT client in full publish-and-subscribe, gate authority in the CODESYS selector on the switch input, and let three separate scratch-pad words carry the local request, the remote request and the published status. A client mode cannot read your switch; your logic can.

Questions asked

Can the main Ignition server watch the remote request word directly?

Yes. The groov EPIC OPC UA server exposes I/O values and the OptoMMP scratch pad areas, so the upstream server can read the remote request word over OPC UA as a second observation path alongside MQTT. Use that view for diagnostics only: the control decision stays in the CODESYS selector, and a second write path into the command words would break the source separation the selector depends on.

What MQTT quality of service should the setpoint topic use?

MQTT offers delivery levels 0, 1 and 2. Use at least level 1 for a setpoint, where the broker acknowledges each message, so a write lost on the plant network is retried. Level 2 adds a handshake that removes duplicates at the cost of extra exchanges; on a switched plant LAN it is rarely worth the overhead for a command that is re-issued on change anyway.

How do you retire a retained setpoint that should not survive?

From a client you control, publish a zero-length payload to the same topic with the retain flag set; the broker treats that as a delete and stops redelivering the old value. Do not rely on disconnecting the Edge client: retention lives on the broker and survives every connect and disconnect. Afterwards, verify that a fresh client receives no stale setpoint on connect.

Should the switch input be latched at startup or read every scan?

Read it every scan through the process image and feed it straight into the selector. A value captured once at controller start freezes the mode as the plant found it at power-up, which is wrong the first time an operator moves the switch while the controller is running, and it hides a wiring fault during commissioning because the logic never re-examines the input.

Can two different devices write the same scratch-pad word?

Physically yes, and peer-to-peer transfer through the scratch pad is what the area is designed for: another device can deposit data that the processor then reads. For command words, keep one writer per word anyway, because two writers erase the source information the selector needs. Diagnostic or status values can share a word; authority-carrying values cannot.

Keep reading

  • How-to

    Push ClearSCADA values to MQTT through an edge gateway

    ClearSCADA and Geo SCADA do not publish straight to an MQTT broker: the value travels from the SCADA server through an edge gateway to the broker as two independent client connections. Prove the SCADA read on one known point and the MQTT publish on a fixed test payload separately, join them only after both pass, and chase a login failure in the server's own web logs, never in the broker settings.

    Edge computing and IIoT

  • How-to

    Bridge ScadaBR data to MQTT through Node-RED

    In this ScadaBR 1.2 design nothing on the ScadaBR side speaks MQTT, so Node-RED bridges both directions: the HTTP Sender passes point values as GET parameters to a /nodered HTTP input, a switch on msg.parts.key publishes them to topics BIN, INT and FLOAT, and a join feeds them back as GET query parameters to the HTTP Receiver at /ScadaBR/httpds. Match the BIN, INT and FLOAT names everywhere.

    Edge computing and IIoT

  • Comparison

    OPC UA vs MQTT Sparkplug from a controller to SCADA

    Pick OPC UA when the controller and the SCADA host share one plant LAN you control: the host subscribes inbound to the controller's browsable server. Pick MQTT Sparkplug B when the controller sits behind NAT, on cellular or at a remote site, or when several consumers need the same tags: outbound-only connections plus birth and death certificates give automatic tag discovery and stale detection.

    Edge computing and IIoT

How many trend pens fit in one historian client window