Troubleshooting
Why an Ewon Flexy 205 publishes MQTT by IP but not hostname
Short answer
The Flexy's 4G WAN delivers no DNS servers, so a hostname never resolves and only a bare IP works; enter resolvers as EthDNS1 and EthDNS2 and set EthDNSAuto to 0 under System > Setup > Storage > Edit COM Cfg. A separate fault on firmware 13.0s0 sends no credentials when the password option precedes the username, and the broker answers CONNACK code 5; set the username first.
On this page
- Why does the Flexy connect by IP address but fail on the hostname?
- Where do you set the DNS servers for the 4G connection?
- Why does the broker answer CONNACK code 5 with correct credentials?
- Does "message published" in the realtime log prove the broker received it?
- How do you verify the whole path once both fixes are in?
- Why does a publish every 5 seconds work once and then stop?
- Questions asked
Your Flexy 205 reaches the MQTT broker by IP address because the transport, port and credentials are healthy; the hostname fails because the 4G WAN never supplies DNS servers, so name resolution returns nothing to connect to. A second, independent fault sits in the Java client: on firmware 13.0s0, setting the password option before the username option sends no credentials at all, and the broker answers with CONNACK code 5. The fixes are exact: enter resolver addresses as EthDNS1 and EthDNS2 with EthDNSAuto set to 0, and call the username option before the password option. Each fault below is isolated with a test that takes minutes and closed with a broker-side proof, never the Flexy's own log alone.
Why does the Flexy connect by IP address but fail on the hostname? #
The transport, port and credentials all work; what fails is name resolution on the cellular WAN, so the client never learns the broker's IP address and has no destination for its TCP connection.
In the reported case the broker listened on TCP port 1883. A command-line publisher using mosquitto_pub drew a CONNACK and its payload arrived at a subscriber, and the Flexy script behaved identically as long as the endpoint was an IP address. Point the same script at the hostname and the connect fails, and a plain Java name conversion on the unit fails with it, over the 4G link only. The WAN page offers the APN and no DNS fields at all, which is the tell: the unit waits for resolver addresses that the cellular network never hands it.
Three symptoms, three different faults. Map yours before changing anything:
| What you observe | What it means | What to do next |
|---|---|---|
| Connects by IP, never by hostname | Broker, port, route and credentials work; resolution fails | Enter static resolvers, then retest by hostname |
| Broker accepts the TCP connection, then closes it with no username logged | Credentials never left the client | Set the username option before the password option |
| Realtime log prints published, subscriber receives nothing | The local call returned; delivery is unproven | Subscribe on the exact topic and read the broker log |
Where do you set the DNS servers for the 4G connection? #
Open System > Setup > Storage > Edit COM Cfg, put your resolver addresses into EthDNS1 and EthDNS2, and set EthDNSAuto to 0 so the unit stops waiting for DNS servers the cellular link never delivers.
- Choose two resolvers reachable from the public side of the cellular link; the plant's LAN resolvers usually are not, because the 4G route bypasses them. For example 8.8.8.8 as primary and 8.8.4.4 as secondary.
- Open System > Setup > Storage > Edit COM Cfg.
- Enter the primary resolver as EthDNS1 and the secondary as EthDNS2.
- Set EthDNSAuto to 0 and apply the configuration.
- Rerun the Java name conversion that failed before; it must return the broker's address, and the MQTT connect by hostname must then succeed.
The unit's vendor support acknowledged the behavior as a known issue at the time and promised a fix, but the available evidence names no corrected build. Keep both resolvers configured on every unit — the entries are harmless on a healthy link, while a silent resolution failure costs a shift of data.
Why does the broker answer CONNACK code 5 with correct credentials? #
On firmware 13.0s0 the Java MqttClient sends no username and password when the password option is set first, so the broker is right to reject an anonymous client with CONNACK code 5, not authorized in MQTT 3.1.1.
The reported script had the pair backwards. Its broker log showed the TCP connection accepted and then closed, with no username recorded, while the same broker accepted the same account from mosquitto_pub — that comparison proves the account is valid and the script is at fault. The failing order, with the reported test's stand-in values:
Mqtt_c.setOption("password", "toto");
Mqtt_c.setOption("username", "unused");
The working order:
Mqtt_c.setOption("username", "unused");
Mqtt_c.setOption("password", "toto");
Here Mqtt_c is the script's MqttClient instance, already constructed with the client ID and endpoint; the option keys are the client's documented options and the two values stand in for your broker's real account. Where the script also uses TLS, the certificate options cafile, certfile and keyfile form a separate group, and the reported test reproduced the ordering fault with and without TLS, so enabling client certificates does not hide it.
The proof is in the broker log: the accepted connection must carry your username and the client must see CONNACK 0. That same build also carries a documented GMT offset quirk, covered in Flexy GMT offset troubleshooting for the same firmware, so keep the username-first order on every build instead of trusting a newer one.
Does "message published" in the realtime log prove the broker received it? #
No — the log records that the script's publish call returned, not that the broker kept or forwarded the payload, so delivery is proven only by an independent subscriber or the broker's own records.
The reported script published at QoS 0, and MQTT 3.1.1 gives a QoS 0 message no acknowledgment at all, so the client genuinely cannot know what the broker did with it. To close delivery, start a subscriber with the same account on the exact topic — test/topic in the reported case — publish one distinguishable payload, and watch it arrive. The same local-success trap catches other clients; why mqtt.to runs without errors but publishes nothing fails the same way and closes with the same broker-side check.
How do you verify the whole path once both fixes are in? #
Four checks in a fixed order — resolve, connect, authenticate, deliver — and each pass or fail points at exactly one fault, so nothing gets changed on a guess.
- Resolve: run the Java name conversion for the broker hostname on the Flexy. A failure here is the DNS fault; apply the resolver settings above.
- Connect: attempt the MQTT connect by hostname. Resolution passing with no TCP connection is a path fault, not DNS; handle it as you would a PLC MQTT client that never reaches the broker.
- Authenticate: read the broker log; the accepted connection must carry your username. A not-authorized reject with a valid account is the option-order fault, nothing else.
- Deliver: the subscriber on the exact topic must show the payload. Only then is the publish path closed.
Fix in that order — DNS first, because every later test names the broker by hostname; credentials second; the delivery proof last. Leave keepalive, broker listeners and firewall rules untouched while an earlier step still fails.
Why does a publish every 5 seconds work once and then stop? #
The evidence leaves this third symptom open, but the keepalive arithmetic clears the usual suspect: with keepalive 30 seconds the broker waits 45 seconds before dropping an idle client, and a 5-second publish cycle never idles that long.
The reported script sets the option as this.setOption("keepalive", "30");, so the keepalive period K is 30 s. MQTT 3.1.1 obliges the server to disconnect a client that stays silent for 1.5 × K, here 1.5 × 30 s = 45 s. A publish every 5 s puts a control packet on the wire nine times inside that window (45 s ÷ 5 s = 9), so an idle timeout cannot explain a stall that begins after the first message. Decision: leave keepalive and reconnect logic alone, capture the broker's connection and publish records across several cycles — whether the session stays established and which publishes arrive — and treat the stall as its own fault. At QoS 0 a dropped message is simply gone, with no retry to mask it, so the broker-side capture is the only trustworthy record.
Questions asked
Is the username-before-password order a Java-only quirk?
It traces to the Java API sharing its function prototypes with the BASIC one, where the same option sequence reads naturally. When a Java call on the Flexy behaves oddly, compare it with the documented BASIC usage of the same client; the reported solution for this fault came from exactly that comparison.
Can you keep the broker's IP address in the script instead of fixing DNS?
As a stopgap, yes; the reported script ran that way. Commit to the hostname anyway: hosting providers move broker addresses, and a hard-coded IP fails silently the day it changes. Set the two resolvers, return the script to the hostname, and keep the address only as a documented fallback for testing.
Will a firmware upgrade let you remove the manual DNS entries?
The behavior was acknowledged as a known issue in June 2018 with a fix promised, but neither affected nor corrected build numbers are documented in the available evidence. Keep EthDNS1 and EthDNS2 filled in, test the hostname once after every firmware upgrade, and remove the manual resolvers only when your installed build resolves names with automatic DNS.