Troubleshooting
Why Unrecognised command 224 stops MQTT publishing for good
Short answer
Unrecognised command 224 appears when the MQTT session has already died and the script keeps publishing through the old client. Clear the connected state on the first publish exception, close the client once and rebuild it from a scheduled reconnect path. Do not reboot after three failures: a 4G module normally produces three or four connect failures at startup.

On this page
After Log (08): Error: Unrecognised command 224, the MQTT session is dead and every later publish through the same client object fails silently or repeats the symptom. The fix is session recovery, not a device restart: clear the connected state on the first publish exception, close the old client once, and build a new one from a scheduled reconnect path. And do not reboot after three failures, because on a Flexy with a 4G LTE board three or four connect failures right after startup are normal modem boot behavior, not a fault.
What the two logged errors actually mean #
The two errors in your log belong to two different subsystems, and treating them as one fault sends you down the wrong path.
Log (08): Error: Unrecognised command 224— the MQTT session has failed and the client object is no longer usable. Once it appears, no further publish succeeds through that client. The exact source of the rejected command is not identified, so recover the session rather than analyzing the number.smbs-Connect socket failed— your Modbus IO server could not connect to a configured Modbus device, so it could not refresh the tags bound to it. This is not an MQTT error. The main loop and the MQTT client can both keep running while the Modbus acquisition is down.
A Modbus socket failure does not mean every IO port is dead; it means that one IO server could not obtain its configured tag values. Check tag quality or freshness before putting those values into an MQTT payload, or the script will happily publish stale process data with a successful result code.
Why publishing fails forever after the error #
The failure pattern in the reported case: a Flexy 202 with a 4G LTE extension board publishing once a minute runs fine for days, then logs the unrecognised-command error, and from then on nothing is sent again while the Modbus socket message repeats every minute. That pattern comes from the publish loop ignoring the state of the session. A publish call is asynchronous: it returns without confirming delivery, and when the underlying session is gone it throws. If the script catches the exception without invalidating the client, it keeps calling publish on a dead object and the gateway never recovers on its own.
Closing and reopening the connection around every publish makes this worse, not better. Each cycle adds cellular signaling, TCP setup and MQTT setup, multiplies the failure points, and gives the session more chances to die. Keep one connection open across the once-a-minute publishes; the same open-once discipline that applies to instrument and server sessions applies here — the reasoning behind keeping a session open for the program's lifetime rather than per call is the same one described in the guide to opening a VISA session once and closing it at program end.
The recovery sequence #
Build the publish path so a dead session is replaced exactly once, on schedule:
- Gate every publish on a connected flag or, on firmware 14.0 or later, on the MQTT connection status facility that firmware adds for exactly this purpose. Publish only when it reads connected.
- Check the modem, IP address, route and broker reachability before attempting a connect. Inhibit the MQTT branch until the LTE interface has registered and holds an address and a usable route.
- Set the client options before connecting: port
1883, log1, plus the username and password your broker requires. - When a publish throws, clear the connected flag immediately, close the failed client object once, and return from the publish path.
- Create the replacement client only from the scheduled reconnect path, reapply its options, call connect, and restore subscriptions such as
my/topicbefore publishing again. - Never call the connection constructor recursively from its own exception handler. That grows the call stack and produces an uncontrolled retry loop. Schedule the next attempt after returning.
If the gateway itself needs a restart for a separately diagnosed device-level fault, the documented call is com.ewon.ewonitf.RuntimeControl.reboot(); — but reserve it for that case. Related reading for the reconnect side: the article on why a Flexy MQTT client drops after one publish on firmware 14.0s01 covers the same session-replacement pattern, and checking MQTT connection status in a Flexy BASIC script shows the status read that gates publishing on newer firmware.
Sizing the reconnect threshold for a once-a-minute publisher on a Flexy 202 with 4G LTE #
The question that started this: can the device reboot when the MQTT socket fails three times in a row? Work the number instead of guessing it.
Inputs and where they come from:
- Publish interval: 60 seconds, once a minute, as configured in the reported application.
- Expected startup failures: three or four MQTT connect failures while the 4G module boots, observed on this hardware after every restart.
The rule in words: the failure threshold that declares a dead session must exceed the largest number of failures normal startup produces, otherwise the rule fires on every boot. Give the modem a full startup window, then judge only failures inside that window.
Arithmetic: the modem needs its whole boot period, so take a window of 10 consecutive failed attempts. At 60 seconds per attempt, that window is 10 x 60 s = 600 s = 10 minutes. Normal startup produces at most 4 failures, which is 4 / 10 = 40 percent of the window, so a threshold of 10 leaves a margin of 6 failures — three times the worst startup behavior — before the session is declared dead.
Result: declare the session dead and rebuild the client at 10 consecutive connect or publish failures, which at this publish rate means 10 minutes of continuous failure.
Decision: rebuild the MQTT session at 10 consecutive failures; never reboot at 3, because 3 sits inside the normal 3-to-4-failure startup window and would restart a healthy gateway after every power-up. Reboot only on a separately diagnosed device fault.
How to verify the recovery works #
Force a controlled broker outage and watch the state sequence rather than the message count:
| Verification point | Pass condition |
|---|---|
| Normal operation | One publish per minute, with no connect or close cycle around each message. |
| Broker interruption | The first failed publish clears the connected flag and closes the old client exactly once. |
| LTE unavailable | No connect attempt runs until the modem, IP and route checks pass. |
| Broker restored | A new client connects, subscriptions are restored, publishing resumes. |
| Modbus failure | The socket message is handled as an IO server fault, never classified as an MQTT failure. |
If a Flexy is no longer worth repairing as your edge host, the same recovery logic runs on any industrial mini PC acting as the gateway, with the MQTT client library of your runtime doing the reconnect. When the Modbus socket error recurs, resolve it on the Modbus path — device address, network route and device availability — independent of anything MQTT does.
The one-line answer: treat Unrecognised command 224 as proof the session died, replace the client from a scheduled path, gate publishes on real connection status, and keep the reboot call out of the failure counter entirely.
Questions asked
How do I recover publishing after Unrecognised command 224?
Stop publishing through the affected client immediately, close that client object once, and create a fresh client from a scheduled reconnect path rather than from inside the exception handler. Reapply the port, log, username and password options, call connect, restore any subscriptions, and only then resume publishing. Keep the connected flag false until the new connect succeeds.
Why should I not reboot the gateway after three MQTT failures?
A 4G module needs time to boot and register after a restart, and during that window three or four MQTT connect failures are normal. A rule that reboots after three failures fires on every normal startup and masks the real fault. Use a failure window that exceeds the startup count, such as ten consecutive failures, and rebuild the MQTT session instead of restarting the device.
Is smbs-Connect socket failed an MQTT error?
No. It comes from the Modbus IO server, which could not reach a configured Modbus device to refresh its tags. Test the Modbus path, target address and device separately, and check tag quality before letting those values into a published payload.
How do I know the MQTT client is connected before publishing?
On firmware 14.0 and later, read the MQTT connection status facility and publish only when it reports an active session. On earlier firmware, keep your own flag: set it after connect succeeds, and clear it the moment a publish throws or a connect fails. Never publish on the assumption that a previous successful connect still holds.


