Troubleshooting
Flexy MQTT TLS fails when the certificate lacks the broker DNS name
Short answer
A Flexy that will not complete TLS on port 8883 almost always has a certificate identity problem, not an MQTT problem. The cafile parameter must hold the root certificate that signed the broker certificate, and that broker certificate must carry the exact DNS name you connect with in its Subject Alternative Name.

On this page
- Why does my Flexy fail TLS on port 8883 with my own broker?
- What exactly goes in the cafile parameter?
- Where must the broker hostname appear in the certificate?
- Why did my openssl command not create a Subject Alternative Name?
- What settings do I change on the Flexy, in order?
- How do I verify the fix end to end?
- Questions asked
A Flexy that refuses TLS on port 8883 against your own Mosquitto broker usually has a certificate identity fault, not an MQTT fault. Two things must match: the cafile parameter holds the root certificate that signed the broker certificate, and that broker certificate carries the exact DNS name you connect with in its Subject Alternative Name.
Why does my Flexy fail TLS on port 8883 with my own broker? #
Other clients on the same broker work while the Flexy does not, and that points at certificate identity rather than at the broker configuration. The documented requirement is that the CA file you load must be the root certificate used to sign the broker certificate, and the broker certificate must contain the DNS name used to connect the broker.
This differs from connection failures after a broker restart or a dropped session; if your symptom is a connect that never completes after a restart, check [an article:mqtt-subscriber-stops-receiving-after-broker-restart] first. If TLS begins but you never receive a CONNACK, walk the path hop by hop with [an article:mqtt-tls-no-connack-find-the-failing-hop].
What exactly goes in the cafile parameter? #
The cafile value must be the root certificate that signed the broker certificate, stored on the Flexy and named in the script. A leaf certificate, a client certificate, or an intermediate alone will not establish the trust chain. In the reported working configuration the root file is copied into the /usr directory and loaded with two calls before the connection starts:
MQTT "setparam", "port","8883"
MQTT "setparam", "cafile","/usr/ca.crt"
Confirm that ca.crt is the signing root, not merely another certificate from the chain. The evidence for this failure mode does not establish any need for a client certificate, so leave mutual TLS out until identity checking passes.
Where must the broker hostname appear in the certificate? #
The DNS name you configure as the broker address on the Flexy must appear in the broker certificate's Subject Alternative Name. A hostname placed only in another field, such as the common name or the FQDN field some tooling shows, was not shown to work in the documented case. This matches general TLS server-identity checking: the client compares the name it connected to against the certificate's SAN entries.
The decision is simple: generate the broker certificate with a Subject Alternative Name entry whose value is character-for-character the DNS hostname on the Flexy, for example DNS:mqtt.plant.local, and connect using that hostname. If you must connect by IP address instead, the Mosquitto project's guidance is to add that IPv4 address as a subjectAltName address entry alongside any hostname entries.
Why did my openssl command not create a Subject Alternative Name? #
Because the plain req command shown in the reported case does not ask for SAN extensions. The command as run was:
openssl req -new -x509 -days 1826 -key ca.key -out flexy.crt
That interactive run prompts for an FQDN field, and a URL typed into FQDN, or a DNS Name value pasted elsewhere, still produced a certificate the Flexy rejected. The value must be written as an extension. Add it on the command line, for example:
openssl req -new -x509 -days 1826 -key ca.key -out flexy.crt -addext "subjectAltName=DNS:mqtt.plant.local"
Or in an OpenSSL config file under the relevant section:
subjectAltName = DNS:mqtt.plant.local
Replace mqtt.plant.local with the exact hostname the Flexy uses. Before connecting by that name, confirm DNS actually resolves it on the plant network; name-resolution problems on gateways are a separate fault covered in [an article:why-an-ewon-flexy-205-publishes-mqtt-by-ip-but-not-hostname].
What settings do I change on the Flexy, in order? #
Work through this checklist once, in order, and stop at the first step that fails:
- Confirm the broker certificate was issued with the exact connection hostname in its Subject Alternative Name, as a DNS entry (or an IP entry if you connect by address).
- Confirm the CA root that signed that broker certificate is the file on the Flexy, at the path named in cafile.
- Set the port to 8883 and the cafile path with the two MQTT setparam calls shown above.
- Connect using the DNS hostname, not an address absent from the certificate.
- Confirm a completed TLS session before testing any tag publication or subscription behavior.
The documented evidence does not establish that the setparam calls must appear in a specific order, and does not establish that parameter order causes this failure.
How do I verify the fix end to end? #
Verify identity before application logic. Inspect the issued broker certificate and read back its Subject Alternative Name; it must show the connection hostname. Then connect the Flexy with that hostname on port 8883 and confirm the TLS session completes. Only after that, publish a known tag value and confirm it arrives at the broker.
If the handshake completes but data still does not flow, the certificate problem is solved and the fault lies elsewhere, for example in the publish path described in [an article:fix-a-plc-mqtt-client-that-never-reaches-your-broker]. The decision for each case: certificate missing the SAN hostname, regenerate the broker certificate with the SAN entry; wrong file in cafile, replace it with the signing root certificate; both correct and TLS still failing, move on to broker-side and network diagnosis.
Questions asked
Does the order of the MQTT setparam lines matter for a TLS connection?
No confirmed ordering requirement exists for the MQTT setparam calls. Set the port to 8883 and the cafile to the root certificate path, verify the broker certificate's Subject Alternative Name carries the DNS name you connect with, and confirm a completed TLS session before testing publish or subscribe behavior.
Can the Flexy connect by IP address instead of a DNS name over TLS?
Only if the broker certificate lists that IP address in its Subject Alternative Name as an address entry alongside any DNS entries. If the certificate holds only a DNS name, connect using that exact DNS name; an IP-based connection against a DNS-only certificate fails the identity check.
Do I need a client certificate for the Flexy as well?
The documented cases in this failure mode used only a trusted root CA on the client side and no client certificate. Do not add a client-certificate requirement until you have confirmed the root CA file and the broker certificate's DNS identity, because either one alone is enough to break the handshake.


