← Articles
HMI/11 min read/— views

Stop a Stale HMI Command From Replaying After a PLC Restart

A pump nobody started runs after a power blip. The six places a command survives a restart — retentive bits, MQTT RETAIN, driver write cache — and the sequence number that ends it.

HMISCADATagsTroubleshootingChecklists

The power blipped once at 2 a.m. The PLC came back, and the feedwater pump started before the operator got back to the screen. Nobody pressed anything. The Start pressed four hours earlier was still sitting true in retentive memory, and the PLC read it as a new command on the scan after first scan.

The HMI writes a request bit with sequence 1482 and the PLC answers accepted; then the PLC restarts. The reconnected HMI writes the same 1482 again and the PLC compares it against its last-processed value and rejects it HMIPLC restart Start — seq 1482 accepted — last = 1482 Start — seq 1482 (replay) rejected — stale seq seq compare

This is about where that bit hides before it comes back, and why one sequence number ends the whole class of problem. Normal operation is fine: the operator presses, the HMI writes a bit, the PLC sees it, the bit drops. It only breaks when the PLC, the driver or the HMI client dies in that gap — and that moment almost never arrives during commissioning.

Six places a command survives

Commands do not default to disappearing. Nearly every industrial stack is built to preserve values, so the forgetting is the part you have to ask for explicitly.

Where it livesWhy it survivesHow to check
PLC retentive memoryThe value is already restored before Logix's S:FS (first scan) runsSet the bit true, then power cycle
MQTT retained messageMQTT v3.1.1 §3.3.1.3 — a publish with RETAIN set is stored by the broker and delivered immediately to every new subscriber on that topicmosquitto_sub -t <cmd topic> on a fresh subscription
SCADA driver write cacheStore-and-forward queues writes during a comms break and flushes on reconnectDriver log, right after reconnect
Redundant server syncA pending write replicates to standby and is reissued after failoverRun the failover right after a command
HMI tag default valueClient restart applies the tag's initial valueRestart only the HMI client
Script variablesGlobal scope that outlives a screen changeLeave the popup open and change screens

MQTT is the one you can pin down with a clause, so check it first. A retained command topic stays there until something clears it — and the only way to clear it is to publish a zero-length payload with RETAIN set to the same topic (v3.1.1 §3.3.1.3). On MQTT v5.0 you can shorten its life with the Message Expiry Interval property (identifier 0x02), but the right value for a command topic is not an expiry time. It is not using RETAIN at all.

One request bit is not enough

A single-bit command has no way to separate "requested" from "executed". The minimum is four signals.

SignalDirectionWidthWhat it does
Cmd_ReqHMI → PLCBOOLRequests the action
Cmd_SeqHMI → PLCDINTSeparates a new request from a replayed one
Cmd_AckPLC → HMIINT0 pending, 1 accepted, negative values are rejection reasons
Cmd_LastPLC → HMIDINTThe last sequence the PLC actually processed

Make Cmd_Seq an INT and it wraps at 32767, and at that moment the comparison decides the request is old. Use DINT or UDINT. Doing the wraparound comparison properly is its own problem.

Returning Cmd_Last to the HMI is the part people skip. Without it the HMI has to guess whether its request landed, and an HMI that guesses writes again on reconnect.

The PLC consumes the request, not the HMI

Letting the HMI drop the bit breaks in both directions. Drop it too fast and the PLC scan never sees it — a 200 ms HMI pulse against a 10 ms scan is fine, but add remote I/O and an OPC UA subscription and the publishing interval alone costs hundreds of milliseconds. Drop it too slowly and the PLC treats true as a new command every scan.

The PLC-side order is:

  1. Check Cmd_Req is true and Cmd_Seq <> Cmd_Last. If not, done.
  2. Check mode, permissives, interlocks and authorization.
  3. Write Cmd_Last := Cmd_Seq before starting the action. This line is what prevents re-execution.
  4. Start the action and write the result to Cmd_Ack.

Put step 3 after step 4 and a PLC that dies in between runs the command twice. The order is the whole mechanism.

IEC 61131-3 defines R_TRIG and F_TRIG as standard function blocks for edge detection. Convenient, but they do not survive a restart: after a restart the block's internal state is at its initial value, so a held true bit looks like a rising edge on the first call. The sequence comparison is not a replacement for R_TRIG — it covers the window R_TRIG cannot see.

How much the protocol gives you

What you get for free depends on what you are speaking.

  • Modbus gives you nothing. FC05 (Write Single Coil) carries value 0xFF00 for ON and 0x0000 for OFF (Modbus Application Protocol v1.1b3 §6.5), and the request has no sequence and no idempotency marker. Modbus TCP's 2-byte Transaction Identifier exists to match responses to requests, not to stop replays. You build all of it yourself — see coil and register write safety.
  • DNP3 has select-before-operate. IEEE 1815 puts a Select before the Operate, and the outstation rejects an Operate that arrives after its select validity window closes. A transaction cut short by a restart therefore expires on its own. Direct Operate skips the protection entirely. More in select-before-operate.
  • OPC UA differs by service. The Write service (OPC UA Part 4) changes a value, and values persist. A Method call is an invocation — it does not get reissued by a reconnect, and it returns a rejection reason as a StatusCode such as Bad_UserAccessDenied or Bad_OutOfRange. For commands, Method beats Write; calling a Method from an HMI button covers it.

The startup gate is not "online"

A PLC being up is not the same as a PLC being ready to accept commands. Just after first scan, remote I/O is still connecting, drive comms are absent, and interlock inputs read 0. A 0 interlock does not mean safe. It means unknown.

Conditions to pass before enabling commands:

  • First scan complete, and every I/O connection healthy.
  • Interlock and permissive data not stale — judge on update timestamp, not value.
  • Device feedback current.
  • Mode source (local / remote / auto) determined.
  • Time sync valid if the audit needs a timestamp. A few seconds of NTP error here is the difference between proving and not proving whether the operator pressed twice.

And when it is blocked, put the reason on the screen. ISA-101.01 holds that the HMI must tell the operator the state of the system; a greyed-out button with no reason does the opposite. In the field a reason-free grey button produces exactly two things — a phone call, then a bypass. Rejected — I/O initializing, 8 s produces neither.

Audit the transaction, not the click

IEC 62443-3-3 asks for recorded access-control and operator-action events in SR 2.8 (Auditable events), trustworthy times for those records in SR 2.11 (Timestamps), and attribution in SR 2.12 (Non-repudiation). One row per mouse click meets none of the three.

What belongs in the row:

  • Operator ID and workstation.
  • Command name, target equipment, requested value.
  • The Cmd_Seq value. Without it you cannot tell a double-click from a replay.
  • Three timestamps: request, accepted, result.
  • PLC result code or rejection reason.
  • Whether a controller restart or comms break occurred during the transaction.

That last field is the one most often missing and the first one wanted during an incident review. Manual override audit trails covers the record design.

Restart testing from idle proves nothing

Restart a PLC while nothing is happening and nothing happens. The failures live mid-transaction, so pick the awkward moment deliberately, in safe simulation or a controlled commissioning window.

  1. Press the command, restart the HMI client before the PLC writes Cmd_Last.
  2. Press the command, restart the PLC immediately after it writes Cmd_Last.
  3. Break the HMI–controller network right after a command and restore it 60 s later.
  4. Restart the SCADA server with a confirmation popup open.
  5. Restart a gateway that has a write buffer.
  6. Fail over a redundant server pair with a command pending.
  7. Power up the PLC with the command bit true in retentive memory.

For each case, record whether the action ran 0, 1, or 2+ times — as a number. The right answer varies: a batch addition must be 0, a safety-related stop can tolerate 2. Knowing the number is the point. Case 7 catches almost every site the first time it is run.

The failures you actually see

SymptomCausePrevention
Command fires right after reconnectDriver store-and-forward flushed its queueDisable write cache on command tags, check the sequence
Same command runs twiceA held true bit reads as a rising edge after restartWrite Cmd_Last before the action
Command disappearsHMI pulse shorter than scan + publishing intervalPLC clears it after consuming
Every machine moves when the broker restartsRETAIN on command topicsNever RETAIN; clear existing ones with an empty payload
Button enables too early"Online" mistaken for "ready"Gate on staleness and I/O status
Operator clicks repeatedlyPending state and rejection reason not on screenRender Cmd_Ack as a sentence

What to check at commissioning

Six lines per important command is enough.

  • The PLC, not the HMI, is the defined owner of clearing the request.
  • Each of PLC / HMI / server / gateway has been restarted, and no stale request executed.
  • The PLC rejects when startup data is invalid, and the HMI shows why.
  • Cmd_Seq is DINT or wider, and Cmd_Last comes back to the HMI.
  • One audit row carries the sequence and all three timestamps.
  • No retained messages exist on any command topic.

None of this says make every button complicated. Do it for pump start, valve open, fault reset and batch addition — the ones where a wrong execution physically moves something. A single bit is fine for the rest.

Next time equipment moves by itself after a restart, check retained messages and the driver write cache before you open the logic. That is where it usually ends. If the problem is feedback that never comes back, command feedback timeouts is the other article.