IMD SolutionComputing LibraryShop main store

Troubleshooting

PLC ping works but AWS IoT Core MQTT fails when the clock is wrong

Edge computing and IIoT Published 9 min read

Short answer

Check the controller clock first. Ping and DNS prove IP reachability only; with the PLC clock set to 2007, TLS rejects every current AWS IoT Core certificate as not yet valid and the handshake dies before MQTT CONNECT, which is why the same project works in simulation on the PC's clock. Connect the clock battery, set the time, enable the NTP client against a plant time server, then retest DNS, port 8883, TLS, CONNACK and publish.

On this page
  1. Why does ping work but AWS MQTT fail from the PLC?
  2. Which connection stage actually failed?
  3. Does the failure point at the controller clock?
  4. How do you set and keep the controller clock right?
  5. Why does the same project publish fine in simulation but not on the PLC?
  6. What do you retest after correcting the clock?
  7. Does a wrong clock break anything besides MQTT?
  8. Questions asked

Check the controller clock before you touch certificates, brokers or firewalls. Ping and DNS success prove IP reachability only, and a TLS client cannot open an MQTT session while its own clock is implausible: a controller in exactly this situation ran with its calendar set to 2007, so every current AWS IoT Core certificate failed the not-yet-valid check and the handshake died below MQTT. The identical project published fine in simulation because the simulation ran on the PC's clock. Set the controller time once, connect its clock battery, enable the NTP client against a plant time server, and then retest stage by stage — endpoint DNS, the TLS listener on 8883, certificate validation, CONNACK, publish. This article gives you the reading that decides each branch and the fix for the branch this fault landed on.

Why does ping work but AWS MQTT fail from the PLC? #

A successful ping proves one thing only — ICMP echo crossed the routed path to the address you tested — while publishing to AWS IoT Core needs endpoint DNS, a TCP connection to the TLS listener on port 8883, certificate validation and an accepted MQTT CONNECT, four stages ping never touches.

Treat every layer as its own test. Echo traffic and MQTT traffic are different flows, and a firewall routinely permits ICMP while denying the MQTT-over-TLS port from a PLC subnet, so a green ping must never be promoted into an MQTT pass. DNS behaves the same way: resolving an unrelated website proves the DNS service answered, not that the exact broker endpoint name is correct.

Replies from a numeric address such as 8.8.8.8 and from a well-known hostname together clear link, routing and the DNS service. What they leave untested is everything from the endpoint's port upward — and that is exactly where this fault lived.

Which connection stage actually failed? #

Read a single connection attempt as six stage checks in order — physical link, IP routing, endpoint DNS, transport connect, TLS handshake, MQTT CONNACK — because the first stage that returns an error is the fault location, and in this case the error appeared at TLS before any MQTT status existed.

Work down the stages once and stop at the first failure:

  • Physical link — read link state and error counters on the controller's Ethernet interface. Pass means the local connection is stable; fail sends you to cabling, the switch port or interface configuration.
  • IP routing — ping the default gateway, then an outside numeric address. Pass proves ICMP can cross the routed path; fail sends you to address, mask, gateway or upstream routing.
  • Endpoint DNS — resolve the exact AWS IoT Core endpoint configured in the MQTT client, not an unrelated hostname. Pass proves the configured name resolves; fail sends you to the DHCP-supplied DNS servers or the endpoint spelling.
  • Transport — open a TCP connection to the broker's TLS listener port. Pass proves route and policy allow that flow from the controller's source address; fail sends you to firewall, NAT or access policy.
  • TLS — read handshake status together with the controller's date and time. Fail here with an implausible clock is the subject of the next section.
  • MQTT — read the CONNACK return code and the publish status. Fail here with TLS already passing sends you to client state, credentials or broker policy.

In this case the controller cleared link, routing and DNS and then stopped at the TLS branch on every attempt — the classic signature of a clock problem rather than a network one. The same staged diagnosis from the broker's side of the wire is covered in MQTT connect fails when TCP works: diagnose the handshake.

Does the failure point at the controller clock? #

Yes — TLS is a time-dependent check: RFC 5280 requires the client to confirm that its own clock falls inside each certificate's validity window, and a controller running with its calendar in 2007 rejects every current AWS IoT Core certificate as not yet valid before any MQTT CONNECT is sent.

The check runs inside the TLS library — the OpenSSL and mbedTLS class of code — and such libraries often report a generic handshake failure, which is why the cause reads as a certificate or endpoint problem. Read the date, time and time-zone handling from the controller itself and compare them against a trusted source; the decisive reading is calendar plausibility, not whether the clock is merely running.

Worked example with this fault's numbers: suppose the plant's true date is 2025-03-04 and the controller clock reads 2007-05-14. The clock is 18 years behind (2025 - 2007 = 18). Every certificate the endpoint serves today carries a validity window that begins long after the clock's date, so the notBefore check fails, the client discards the chain and no MQTT CONNECT is ever sent. At the configured publish rate of one attempt every 500 ms, that is 2 failed handshakes per second (1,000 / 500 = 2) and about 7,200 per hour (2 × 3,600 s = 7,200), each logged as a TLS failure rather than an MQTT error.

The clock branch reads like this: a date years in the past means set the clock and add synchronization; a clock that is correct but resets after power loss means the battery is missing, disconnected or exhausted; a clock that is correct and holds means time is not your fault and you move to the trust and firewall branches.

Clock correct but TLS still failing is the trust branch: client stacks that lack the Amazon Trust Services roots need the Starfield Root CA Certificate added explicitly, as the AWS IoT documentation directs for server authentication. The same pair of checks — clock first, then trust — is documented on other controllers too, as in an S7-1500 MQTT TLS error 8089 traced to CPU clock and certificate trust.

How do you set and keep the controller clock right? #

Connect the controller's clock battery, set the date and time once from the controller itself, then enable its NTP client against your plant time server and verify the displayed time after the next synchronization rather than trusting the configuration request.

Start with the battery, because a battery-backed clock that was never connected explains a controller that forgets its time at every power-off. Follow the controller manual's procedure for connecting or replacing that battery — the safe handling steps are specific to each hardware family.

Then make the correction permanent. The NTP client is configured either in the CPU or device configuration or from the runtime program, depending on the controller family; in every form it is an entry where you supply the NTP server's address. Enter the server by IP address — for example 192.168.1.10 — so time synchronization does not gain a DNS dependency of its own, point it at a server your OT firewall actually permits, and read the displayed time again after the next synchronization and after a reboot.

The decision: a manual time set alone is a temporary fix; battery connected plus a working NTP client is the fix that holds.

Why does the same project publish fine in simulation but not on the PLC? #

Because the simulation runs on the PC, not on the controller: the simulated runtime borrows the PC's clock, network interface, DNS and route, so a clean simulation proves the project, endpoint and certificate files are right while telling you nothing about the controller's clock, source address or firewall permission. On this controller family the runtime's PC-side simulation is ARSim, and its success is one-sided evidence.

Compare the two paths hop by hop when the split matters: record the controller's and the PC's source addresses, the resolved endpoint address, the configured port and the gateway on each side. A firewall or router that trusts the engineering PC while denying the PLC's subnet produces exactly this split — simulation passes, the controller fails.

Read simulation success as proof of the project configuration, and read the controller's TLS-stage failure as the pointer to its clock; that combination was the whole diagnosis here.

What do you retest after correcting the clock? #

Run one publish cycle and read every stage status in order: transport opens, the TLS handshake completes, CONNACK returns success and the 500 ms publish is accepted — with the clock corrected, the same project that died at TLS should reach an accepted publish on the first attempt.

Retest in this order:

  1. Power-cycle the controller once and read its date and time again — this proves the battery holds the clock across power loss, not just within a running session.
  2. Trigger a single publish from the running project and read the client's return status at each stage: transport open, TLS handshake, CONNACK, publish.
  3. Confirm one received message on the cloud side with the broker's test subscription or console test client, so the proof is a delivered message and not only a client return code.
  4. Read the controller's displayed time again after a day of operation to confirm the NTP client is synchronizing, not merely configured.

Then branch on what you see. If TLS now completes but no CONNACK ever arrives, the clock is fixed and a different fault stands in front of you: MQTT TLS connects but no CONNACK: find the failing hop covers that hop. If CONNACK is accepted but the destination still shows no data, the delivery path is the suspect, and a fix for MQTT publish success with no data arriving at the destination walks that case. If TLS still fails with a verified correct clock, return to the trust-store branch above and the firewall rule for the controller's own source address.

Does a wrong clock break anything besides MQTT? #

Yes: an implausible time is reported to break OPC UA client and server connections the same way, and every certificate-based service on the controller — HTTPS clients, secure OPC UA, additional cloud brokers — validates against that same clock, so one corrected clock repairs all TLS-dependent services at once.

The OPC UA rejection is a reported pattern rather than a specification clause, but it follows the same logic: a large gap between the controller's time and the certificate or session window is implausible, so the server can refuse the connection outright. If your project also authenticates the device itself with a client certificate instead of only validating the server's, that setup carries its own failure modes, covered in fixing X.509 certificate authentication to Azure IoT Hub over MQTT.

The decision for every case in this article: when ping works but AWS IoT Core MQTT fails, read the controller clock first; set it, connect the battery, leave the NTP client enabled permanently, and only then work down the trust-store and firewall branches. A controller that publishes to a certificate-validated broker without an automatic time source is one power cycle away from the same silence.

Questions asked

Which NTP server should a PLC synchronize against?

Use a time source on your own network first — the plant domain controller or a dedicated NTP appliance — entered by IP address in the controller's configuration. Internet NTP pools work only where the firewall permits outbound NTP on UDP port 123 from the controller's address. Whatever you pick, verify the displayed time after synchronization; the reachable server your firewall permits beats an ideal one the controller can never query.

Why does the clock reset every time the controller loses power?

On hardware with a battery-backed clock, the usual cause is a battery that is disconnected, missing or exhausted. New controllers commonly ship with that battery unplugged for storage, and an aging battery dies silently. Connect or replace the battery following the controller manual, set the time once, power-cycle to confirm it holds, and keep the NTP client enabled so operating drift is corrected continuously.

Can a wrong PLC clock also break connections to MQTT brokers inside the plant?

Yes, for any broker that runs TLS, because your controller validates the broker's certificate against its own clock exactly as it does with AWS IoT Core. A plain MQTT connection without TLS performs no certificate check at all, which is why an unencrypted test broker can look healthy while every TLS-protected one fails.

How often does a controller clock need resynchronizing?

There is no service interval to schedule: leave the NTP client enabled permanently and it corrects drift continuously, while the battery only carries time across power-off. Re-check the displayed time after the events that realistically disturb a plant controller's clock — firmware updates, battery replacement and extended shutdowns — and after any unexplained loss of TLS connectivity.

Keep reading

  • How-to

    Set up the MQTT Client SL library on a CODESYS controller

    MQTT Client SL is part of the CODESYS IIoT Libraries SL package. Verify the exact controller runtime and its license, pin the library version, batch JSON per asset, and set the controller clock before opening a TLS session.

    Edge computing and IIoT

  • Troubleshooting

    Trace an edge gateway MQTT connection failure to Azure Event Grid

    A desktop MQTT client that connects and publishes with thumbprint authentication clears only that endpoint, certificate and permission combination on that host. When the gateway fails against the same Event Grid namespace, test four stages in order on the gateway itself: network path and DNS to TCP 8883, the TLS handshake with both certificate directions and the clock, the CONNECT identity, and publish authorization on the exact topic. The first stage that fails names the fix.

    Edge computing and IIoT

  • How-to

    Bridge a cellular tracker's TCP stream into MQTT for AWS IoT Core

    Build a small ingest service on your edge PC: it terminates the tracker's raw TCP session, decodes each stored record, and republishes one MQTT message per fix over TLS on port 8883. Acknowledge a packet only after every publish is confirmed, or a coverage-gap batch is silently lost.

    Edge computing and IIoT