Troubleshooting
Why an Ewon MQTT status stays at 3 after enabling TLS
Short answer
Once MQTT CONNECT has launched, the Ewon retries on its own, so a status stuck at 3 means the same hop fails every cycle — usually the TLS handshake, the CA chain, the SAN entry or the clock. LSTERR only reports whether the command launched. Read the status with MQTT STATUS, log with SetParam log 1, and walk the hops: TCP 8883, handshake, CA chain, SAN, clock, credentials.
On this page
- What a stuck status 3 does and does not tell you
- The six hops between the Ewon and a publish
- Why the connect fails only after the CA lines are set
- Where the TLS failure actually shows up
- Counting the redundant CONNECT commands in the 300 s timer
- The reconnect pattern that replaces the timer connect
- The decision for each case
- Questions asked
A status that stays at 3 after you set CAFile is not a connect command that gave up. It is the Ewon's automatic retry loop reporting the same TLS failure on every cycle. Once MQTT "CONNECT" has launched, the gateway retries on its own, so the timer that re-issues CONNECT cannot change the outcome — and GETSYS PRG,"LSTERR" cannot help, because it reports whether the command launched, not what happened in the TCP, TLS and CONNACK stages that follow. The fix is diagnostic, not structural: read MQTT "STATUS", keep Mqtt "SetParam","log","1" switched on, and walk the path in order — TCP to 8883, handshake, CA chain, SAN, clock, credentials — until the broker's own log shows which hop fails.
What a stuck status 3 does and does not tell you #
MQTT "CONNECT" starts a background process. LSTERR read immediately after the call returns the launch result: whether the command started, never whether the TCP, TLS and CONNACK stages succeeded. That is why the error message carries no TLS detail — expected behavior, not a dead end.
The vendor's support answer to this exact question states the behavior that matters: once MQTT "CONNECT" is launched, the Ewon keeps retrying automatically if the connection is lost, so no retry configuration is needed. A status parked at 3 is what a persistent cause looks like. Every retry cycle fails at the same hop, and the number never advances until that hop is fixed.
Read the status instead of inferring it. The program polls MQTT "STATUS" each timer tick, which works; the support suggestion in the same discussion is to call ONMQTTSTATUS so transitions are reported as they happen. Log the raw integer at every sample. And leave the connecting to the client: a timer that re-issues CONNECT while the status is 3 or 4 duplicates the built-in retry, cannot succeed while the cause persists, and is unnecessary once the cause is cleared.
The six hops between the Ewon and a publish #
Each hop has its own failure signature, and the later hops cannot be debugged until the earlier ones pass; the same hop-by-hop method traces MQTT TLS connects but no CONNACK: find the failing hop on any client.
- Route. The Ewon and the broker, 10.0.0.52 in the original program, share a route and no firewall drops the session. Signature: the broker log shows no connection attempt and the status never leaves its pre-connect value.
- TCP to the listener. The broker listens on 8883 and the program sets Mqtt "SetParam","port","8883". Signature: the broker log is still empty and the Ewon log shows a failed connect.
- TLS handshake. The 8883 listener is a TLS listener and the CA file is readable on the Ewon at the path given to CAFile. Signature: the broker logs a handshake error or a client that closed early. When the TCP connection succeeds and the MQTT connect still fails, this hop or the next holds the fault — the diagnosis continues in MQTT connect fails when TCP works: diagnose the handshake.
- Certificate verification. The CA in CAFile signed, or is, the broker certificate; the certificate's subjectAltName carries the address used in Mqtt "open"; and the Ewon clock sits inside the certificate's validity window. Identity checking compares the address the client opened against the SAN, and an IP matches only an IP-type entry, never a DNS name. Signature: the handshake aborts with an unknown-CA or bad-certificate alert. A correct certificate still fails when the clock is outside the validity dates — the mechanism behind PLC ping works but AWS IoT Core MQTT fails when the clock is wrong.
- MQTT CONNECT and CONNACK. Username, password and client ID are accepted. Signature: the broker logs an authentication refusal and the status never reaches 5.
- Publish. The status reads 5 and the publish branch runs. The program treats 5 as the only state in which it publishes, so all five earlier hops must pass first.
Why the connect fails only after the CA lines are set #
Setting CAFile switches the client from plain MQTT to TLS on the same socket, so a connect that worked before and fails after the two CA lines sits in the handshake or certificate hop, not in the script. The vendor's stated minimum for TLS is the CA certificate through CAFile alone, so make the first test with only Mqtt "SetParam","CAFile","/usr/certs/cert_san.pem" and leave CAPath out — one variable fewer.
| Symptom after adding the CA lines | Cause to test | Check |
|---|---|---|
| Connect fails immediately | The client now speaks TLS but the listener is plain MQTT, or the path is wrong | Confirm the listener configuration on the broker; confirm the file exists at /usr/certs/cert_san.pem after the upload |
| Handshake aborts on the Ewon side | The file in CAFile is not the certificate that signed the broker certificate | For a self-signed test, the file must be the root that issued the broker certificate, or the broker certificate itself if it is self-signed |
| Name or address rejected | The SAN lacks the address used in Mqtt "open" | The broker certificate must carry the broker IP 10.0.0.52 as an IP-type SAN entry, not only a DNS name |
| Chain valid, still rejected | The Ewon clock is outside the certificate's validity window | Compare the Ewon's system time, NTP or manual, with the certificate's not-before and not-after dates |
| File garbled or truncated | The upload altered the file | Compare the file size and the BEGIN CERTIFICATE and END CERTIFICATE lines after the upload |
| TLS passes, status still short of 5 | Credentials or client ID refused | The broker's authentication log |
Prove the script before certificates. The vendor hosts an unencrypted test broker at tools.ewonsupport.biz: publish at status 5 there, with no CA parameters, and the program logic is proven — any failure that appears after the CA lines is certificate or listener configuration. Run that unencrypted test only against the isolated support broker, never across the plant network, because CONNECT then carries the username and password in cleartext.
Where the TLS failure actually shows up #
Keep the logging parameter in the init block and read three places during one connect attempt:
- The Ewon event log and realtime log. The program's LOGEVENT entries land next to the client's own messages, with timestamps that line up.
- The broker's own log. No entry for the attempt means hop 1 or 2; a handshake or certificate alert means hop 3 or 4; an authentication refusal means hop 5.
- A packet capture on the broker host when the first two stay vague. Look for the SYN to the listener port first, then for the TLS alert and which side sent it.
The broker side of this — TLS listeners, CA files and access rules — is built step by step in Run a secure Mosquitto MQTT lab broker with Node-RED. The vendor also publishes ready-to-use MQTT scripts in its BASIC repository on the same support site, worth comparing against the init order before rewriting anything.
Counting the redundant CONNECT commands in the 300 s timer #
The inputs, each with its source: timer 1 fires every 300 s, from the program's own Tset 1,300; the observation window is 1 h, or 3600 s, one shift hour on the plant floor, the example window; the launches needed after the first is 0, because the vendor documents that the Ewon retries on its own once CONNECT is launched; and the status reads 3 throughout, the value the program logs each cycle.
The rule in words: a timer that re-issues CONNECT adds one command per period, so the redundant commands in a window equal the window divided by the period, minus the launches actually needed.
The arithmetic: 3600 s / 300 s per command = 12 commands; 12 minus the 0 needed leaves 12 redundant CONNECT commands in the hour.
The result: 12 commands that cannot change the outcome. Each cycle fails at the same hop, and the status is still 3 at the end of the hour.
The decision, with its threshold: any CONNECT issued while MQTT "STATUS" reads 3 or 4 is redundant, at 300 s or at any period. Remove the call from the timer, keep timer 1 as a log-only status sampler or drop it, and let the built-in retry own the connecting. The status moves past 3 on its own once the failing hop in the TLS path is fixed.
The reconnect pattern that replaces the timer connect #
Move every parameter line and the single CONNECT into the init section, wrapped in RESUMENEXT so the launch result is logged. Timer 2 keeps its 1 s period and only publishes; if status history is useful, add a slower log-only sampler, never a CONNECT:
// username and password below are the lab values from the original program
FUNCTION Log($Msg$)
LOGEVENT $Msg$,100
PRINT $Msg$
ENDFN
Mqtt "open","adm","10.0.0.52"
Mqtt "SetParam","port","8883"
Mqtt "SetParam","username","adm"
Mqtt "SetParam","password","adm"
Mqtt "SetParam","cleansession","1"
Mqtt "SetParam","log","1"
Mqtt "SetParam","CAFile","/usr/certs/cert_san.pem"
SETSYS PRG,"RESUMENEXT",1
MQTT "CONNECT"
ErrorReturned% = GETSYS PRG,"LSTERR"
@Log("CONNECT launched, LSTERR=" + STR$ ErrorReturned%)
SETSYS PRG,"RESUMENEXT",0
Tset 2,1
Ontimer 2,"goto MqttPublish"
MqttPublish:
$ConnStatus% = MQTT "STATUS"
IF ($ConnStatus% = 5) THEN
var$ = STR$ GETIO "festo"
MQTT "publish","/location/area/festo",var$,0,1
ELSE
@Log("client not ready, status " + STR$ $ConnStatus%)
ENDIF
End
One launch, one retry owner, and a status number in the log at every sample. The client retries, the logs locate the hop, and the script never competes with the retry.
The decision for each case #
- The broker log has no entry for the attempt. Hop 1 or 2: fix the route or firewall, or the listener, before touching any certificate.
- The broker logs a handshake or unknown-CA alert. Hop 3 or 4: verify that CAFile holds the root that signed the broker certificate, that the SAN carries the broker IP as an IP-type entry, and that the Ewon clock is inside the certificate's validity dates.
- The broker logs an authentication refusal. Hop 5: TLS is already proven; fix the username, password or client ID.
- Publishing works on the unencrypted support broker but not on the plant broker. The script is proven; the fault is certificate or listener configuration on the plant side.
- The status reads 3 no matter what. Take CONNECT out of the timer and leave one launch in the init section — the built-in retry does the rest — then fix the hop the broker log names.
Questions asked
Is there a timeout parameter for the MQTT CONNECT command?
No timeout parameter appears in the MQTT parameter set this program uses, and the vendor's answer to this question names none. The design removes the need for one: once CONNECT launches, the background process retries by itself, so aborting and relaunching is never part of the fix. Let the process run, read MQTT STATUS to see where it stands, and repair the hop the logs point to. The system communication parameters for the Ewon Cosy and Flexy are described separately in the vendor's comcfg.txt document, the reference to check when you suspect a connection-side setting.
What do MQTT status values 2, 3, 4 and 5 mean?
The BASIC reference for the firmware in question documents 3, 4 and 5; it does not describe a status 2, so treat any other number as unknown and log the raw integer at every sample. Status 5 is the connected state the publish branch waits for; values below it mean the client has not reached that state yet. To watch the transitions as they happen, the support suggestion in the same TLS discussion is to call ONMQTTSTATUS rather than judging success from the command result.
Does the certificate need the broker's IP address in the SAN?
Yes, when the client connects by address. TLS identity checking compares the exact string used in Mqtt open against the certificate's subjectAltName, and an IP address matches only an IP-type SAN entry, never a DNS name. A certificate whose SAN lists only a hostname will fail verification when the open call targets the broker IP 10.0.0.52, as this program does. Either add the address as an IP entry when you generate the certificate, or connect by a name the SAN lists and resolve that name on the Ewon.
What does the cleansession parameter do in this program?
Mqtt SetParam cleansession 1 maps to the clean-session flag defined in the OASIS MQTT 3.1.1 specification: the broker discards any session left over from a previous connection and starts fresh, with no queued messages from before. It plays no part in the stuck status 3, because the flag travels in the MQTT CONNECT packet, which only runs after the TLS handshake has already passed. For a publisher that sends current values only, as this program does, clean session 1 is the usual choice.