Troubleshooting
MQTT connect fails after power loss when the CA certificate is missing
Short answer
After a power failure, a gateway whose MQTT connect fails while VPN, PLC traffic and open ports all still work may be missing its runtime files: in one reported case the CA.crt certificate and the BASIC script were gone from the usr folder, and restoring them fixed publishing when a firmware upgrade did not. Check the files and the certificate's expiry date before touching the network or firmware.
On this page
When an MQTT client stops connecting right after a power failure while the VPN still comes up, PLC values keep arriving and IT confirms the ports are open, the network is rarely the fault — check what the gateway kept on disk. In one reported case, a factory power outage left an edge gateway without its CA.crt certificate and without the BASIC script it needed; every rerun of the script ended in operation failed: "MQTT connect", and putting the files back into the usr folder restored publishing on the next run. A firmware upgrade changed nothing. Work the isolation in that order: separate what still works from what broke, read the logs at the failing step, verify the runtime files and the certificate's expiry date, and only then touch firmware or the broker configuration.
What still working proves, and what it does not #
Each surviving function eliminates one layer. A VPN session into the gateway proves the WAN path and the remote-access stack are alive; continuing PLC value updates prove the controller link and the acquisition side run. Neither says anything about the publish path. An open TCP port is a statement about the broker host, not about your client: the port accepts connections before any TLS or MQTT exchange starts, so a port check cannot prove a session. The distance between an open port and a working session is exactly the case in MQTT connect fails when TCP works: diagnose the handshake.
| Observation | What it establishes | What it does not establish |
|---|---|---|
| VPN to the gateway connects | WAN path and remote access are alive | Nothing about MQTT files or broker-side registration |
| PLC values keep updating | Controller link and data acquisition run | Nothing about the publish path to the broker |
| Ports 1883 and 8883 reported open | The broker host accepts TCP connections | TLS verification and the MQTT CONNECT still have to succeed |
operation failed: "MQTT connect" on script rerun |
The failure sits client-side, at connection setup | Which stage failed: TCP, TLS or CONNECT |
Read the log at the failing step #
With logging enabled, the gateway's real-time logs print the MQTT connection sequence step by step while you rerun the script, so watch which step completes last. The event log in the reported case showed a stdios-device TCP connect failed socket error — which reads like a network fault but sat alongside a working VPN and live PLC traffic, a contradiction that points away from routing. TLS breakage has a recognizable signature: client-side logs report certificate verification failure, handshake failure or key mismatch when credentials or certificates are invalid. A failure at the TCP stage points at DNS, routing or firewall rules; a failure at the certificate stage points at the files on the device. What a complete client-side TLS arrangement looks like, certificate by certificate, is laid out in configuring MQTT TLS certificates in Node-RED on an edge PC.
Check the runtime files before anything else #
- Open the gateway's file system and look in the usr folder, where the runtime keeps its certificates and scripts.
- Confirm CA.crt is present, together with every other certificate the MQTT script references.
- Read the expiry date out of the certificate file; a file being present proves nothing about its validity.
- Confirm the .bas script file itself survived. In the reported case, both the certificates and the script were gone from the usr folder.
- Read the file-management lines in your script and rule out anything that writes to, moves or clears that folder during a run.
- Restore known-good copies of the missing files, rerun the script, and confirm a publish lands on the broker.
Power loss alone is not a documented mechanism for deleting runtime files, and the reported case never explained the removal, so treat any script logic that touches its own runtime folder as the first suspect on a recurrence. Before restoring or editing anything on a gateway that feeds plant data, capture a full backup with support files included so a bad restore cannot take down the only path to the historian.
Worked example: 121 days of validity left on a CA certificate expiring 2026-03-31 #
Inputs: the certificate's not-after date, 2026-03-31, read from the certificate file with an x.509 viewer or from the broker platform's console (example date); the review date, 2025-11-30, the day you run the audit (example date); the audit threshold, which defaults to 30 days on the large IoT platforms' automated device-certificate audits and is configurable from 30 up to 3652 days (documented default and range).
Rule in words: remaining validity in days equals the expiry date minus the review date, and the renewal trigger is the larger of the configured audit window and your own renewal lead time.
Arithmetic: from 2025-11-30 to 2025-12-31 is 31 days; 2025-12-31 to 2026-01-31 is 31 days; 2026-01-31 to 2026-02-28 is 28 days, because 2026 is not a leap year; 2026-02-28 to 2026-03-31 is 31 days. Total: 31 + 31 + 28 + 31 = 121 days.
Result: the certificate holds 121 days of validity on the review date.
Decision: 121 days sits above the 30-day default audit window, so an audit at default settings reports nothing today. Set the audit window to at least your renewal lead time, and treat any remaining-validity reading below that window as the trigger to renew. If the file is missing altogether, expiry arithmetic is moot: restore the file first, then read its expiry from the restored copy.
Broker side, firmware and recurrence #
Confirm the device is still provisioned on the broker or IoT platform. A working VPN says nothing about broker-side registration, and a removed or expired device record produces the same connect failure as a missing file. Once the files are back, re-check the publishing configuration too — topics, payload structure and broker settings — against the platform's expectations; configuring tag publishing to a broker covers that side.
Firmware is the last lever, not the first. In the reported case the gateway ran an older release, an upgrade to a newer one was applied, and the failure persisted; publishing returned only when the files came back. Upgrade for documented fixes in the release notes, and do not expect a version change to restore deleted files.
If the files vanish a second time, capture the diagnostics before restoring anything: a full configuration backup with support files included, the real-time log output of one script rerun, and the certificate's expiry date as read from the file. Rule out every script line that can write to or clear the usr folder, then take that package to the vendor's official support channel. If no cause is ever found and the box keeps losing runtime files, replacing it is the fallback: a fanless mini PC built for edge duty takes over the gateway and publishing role.
If every file is present, unexpired and correct, and the session still will not come back after a restart, the fault lies elsewhere; why an edge gateway stops sending after a reboot works that case.
Questions asked
Can a power failure delete the certificate and script files by itself?
No documented mechanism removes files from a gateway's usr folder during a power event, and the reported case never explained the removal. Treat a first occurrence as a one-off: restore the known-good CA.crt and .bas files and move on. If it happens again, capture a full backup with support files before restoring anything, review every file-management line in the script, and escalate through the vendor's official support channel.
Why do open ports 1883 and 8883 not prove that MQTT works?
An open port means the broker host completed a TCP-level acceptance on that port number. MQTT over TLS still requires the client to load its certificate files, verify the CA chain and finish the handshake before any publish, and a port scan does none of that. Treat an open-port report as a trigger to test the session, never as proof of one.
Will a firmware upgrade fix an MQTT connect failure after a power loss?
In the reported case, moving the gateway to a newer firmware release changed nothing; publishing returned only when the missing CA.crt and script files were restored. Firmware has no mechanism to recreate files that are gone from the usr folder. Upgrade when the release notes document a fix you need, but verify the runtime files first, because files, not firmware, were the cause here.
How early should certificate expiry be flagged on an edge gateway?
Automated device-certificate audits on the large IoT platforms default to flagging a certificate 30 days before expiry, and that window is configurable from 30 up to 3652 days. Set the window to at least your renewal lead time: if issuing and installing a replacement takes your team two weeks, the default leaves only that much margin, so widen it rather than racing the clock.
What belongs in a support package when the files vanish a second time?
Capture a full configuration backup with support files included, using the gateway vendor's own backup utility, before you restore anything. Add the real-time log output from one script rerun and the certificate's expiry date as read from the file. That package lets support separate a device fault from script logic or a broker-side change.