Flexy BASIC IDE Doesn't set MQTT will/last testament message

Flexy 205, firmware 14.6s0

Will topic is not working, although connection and publish is working. Am I doing something wrong, or should I get a different device from a different company?

Function WANAction($WANStatus%)
  IF $WANStatus% = 1 Then
  PRINT "WAN up"

Function Start()
  PRINT "starting MQTT"
  PRINT "Initialized."
  ONMQTTStatus "@MosquittoMQTTStatusChange(mqtt('status'))"

Function MosquittoInit()
  MQTT "open", mqtt_client$, mqtt_host$
  MQTT "setparam", "CAFile", "/usr/certs/cert.crt"
  MQTT "setparam", "ProtocolVersion", "3.1.1"
  MQTT "setparam", "port", mqtt_port$
  MQTT "setparam", "username", username$
  MQTT "setparam", "password", password$
  MQTT "setparam", "WillPayLoad", "OFFLINE"
  MQTT "setparam", "WillTopic", mqtt_base_topic$ + "STATE"
  MQTT "setparam", "WillQoS", "1"
  MQTT "setparam", "WillRetain", "1"
  MQTT "connect"
  //MQTT "subscribe", mqtt_base_topic$ + "DCMD", 0

Function readMsg($msgID%)
  IF $msgID% > 0 Then
    msgTopic$ = MQTT "msgtopic"
    msgData$ = MQTT "msgdata"
    PRINT "received: "; msgTopic$; " -> "; msgData$

Function MosquittoMQTTStatusChange($status%)
  IF $status% = 5 Then
    PRINT "MQTT connected"
    //MQTT "setparam", "WillPayLoad", "OFFLINE"
    //MQTT "setparam", "WillTopic", mqtt_base_topic$ + "STATE"
    //MQTT "setparam", "WillRetain", "1"
    TSET 1, 5
    ONTIMER 1, "@MosquittoMQTTPublish()"
    PRINT "MQTT disconnected"

Function MosquittoMQTTPublish()
  msg$ = "test(" + STR$(n%) + ")"
  PRINT "publishing!!!!!!!!!"
  MQTT "publish", mqtt_base_topic$ + "DATA", msg$, 0, 0
  n% = n% + 1

Hi @Dio2pRqh,

We have tested this with our test broker (Ewon MQTT Broker) and it works:

Can you try the same?

I modified the MosquittoMQTTPublish() function to publish a CLOSING payload on the /DATA topic just before it closes the connection:

Function MosquittoMQTTPublish()
  msg$ = "test(" + STR$(n%) + ")"
  PRINT "publishing!!!!!!!!!"
  MQTT "publish", mqtt_base_topic$ + "DATA", msg$, 0, 0
  n% = n% + 1
  IF n% > 3 Then
    TSET 1, 0
    MQTT "publish", mqtt_base_topic$ + "DATA", "CLOSING", 0, 0
    MQTT "close"

I just tried the demo broker and it doesn’t work as seen in the screenshot, no death topic is ever sent.

I tried copying and running the program in a different flexy that we have and it produces the same issue as well.


It seems that the MQTT client on the flexy sends the MQTT DISCONNECT packet, even when it ideally shouldn’t, for example, when I manually stop the BASIC IDE execution. This means that the flexy cannot be 100% reliably known to be online when implementing a program that is designed to be persistently connected (eg. someone stops the ide while the program running, the client subscribed to the flexy publish topics will not receive a death certificate, and will not know that the flexy has in fact stopped reporting real time metrics). This behavior adds a level of uncertainty to any application implementing real time, report-by-exception data reporting.

Thank you for your input. I will check with the developers to find out if this is deliberate or not. Stopping the IDE isn’t a typical network disconnection because it is the user consciously stopping the program. I think that it’s probably dealt with this way because of that. It’s more of a “graceful” shutdown of the system as compared to a network failure, failure to communicate the keep alive, etc.

I confirmed with the developers that this is intentional and not a bug. If you want to simulate a disconnection, you should kill the network connection (disconnect the cable, for example).

Overall the MQTT support seems lackluster. Is there any plans to add open IIOT standards like sparkplug to the flexy capabilities/features? All the great features that the flexy currently has plus a widely supported protocol like Sparkplug B on MQTT would certainly make it an amazing device.

I like the easy configuration and user interface of the flexy and ecatcher, and we have been using flexy in our equipment for many years now. However, without a proper MQTT standard, going forward we will have no choice but to move to a different IIOT gateway.

I’m not sure I understand what you mean by lackluster MQTT support. We have a number of connectors that are built on MQTT, like the Azure Connector, AWS Connector, Thingworx, Mindsphere, Ignition, I believe at least most of them are using MQTT.

I’m sorry, but I’m not personally familiar with Sparkplug B.

This is a tech support forum though. I’m not in sales and I’m not an Ewon developer. You may want to check with your local distributor or regional sales manager or check out our Developer Forum if you have concerns with MQTT lacking certain features.

We also have a number of solution partners that work with the Flexy (and many are using MQTT) if you need more capabilities. There are also other options, like the M2Web and DMWeb APIs, which you can find more info about here: IOT Solutions | Ewon Developers