I’ve searched for this information in the forum, but I couldn’t find it. So, here’s my question: is there a field in the edge agent’s toml file which allows me to set the MQTT parameter clean session to false?
Unfortunately, CleanSession 0 is not supported. You can locate this documentation here.
I see the limitation. However, I wasn’t sure if this limitation is related to the Losant broker only, or by all Losant instances that communicate MQTT. Because most of the work in a scenario where clean session 0 is done by the broker, I still got this doubt. In my case, I am not connecting directly to the Losant broker. Instead, I use a local broker to centralize some MQTT clients, including the edge agent. And the clean session 0 gives me a very important feature, which is storing messages whenever the connection to the internet is unreachable. Regarding the MQTT doc:
After the disconnection of a Session that had CleanSession set to 0, the Server MUST store further QoS 1 and QoS 2 messages that match any subscriptions that the client had at the time of disconnection as part of the Session state
So, the clean session 0 is not supported by either Losant’s broker and agent? If so, is there any chance of this feature being integrated to the edge agent?
Thanks for this detailed response. I’m checking with the engineering team on this now, but here are a couple of things I do know:
Right now, devices can not connect to the Losant MQTT Broker with cleanSession 0. Also, today, the Losant Edge Agent can not be configured to connect to any broker with cleanSession 0.
I’m creating a feature ticket for you now to possibly be able to configure the Losant Edge Agent to connect to another broker ( your local one for example ) with cleanSession 0. But, even in this case, this setting would only be valid for local brokers that support cleanSession 0.
As I look into this more, I’ll see if we can come up with some alternatives, and I’ll follow up on this.
Thank you for the answer and the effort on this issue. My local broker supports clean session 0 from MQTT clients connections, so it won’t be a problem for the clients.
Furthermore, as you mention about the Losant MQTT broker not supporting this configuration, I was able to connect to it with clean session 0, and received the messages in the debug screen. Is that suppose to happen?
Thanks for your patience on this. I just had an in-depth chat with the engineering team on this, and I have some information for you.
I did want to touch on this fist:
This is something I’m going to make clearer in the docs, but the Losant Edge Agent will already store messages offline upon disconnection from the internet ( or in this case, disconnection from the Losant Broker). This feature is enabled with the QUEUE_OFFLINE_MESSAGES flag. This flag does nothing to the MQTT connection, the agent itself will store the messages. But, this may already solve the problem you’re trying to solve.
Moving on to your feature request: Right now, the MQTT client on the Edge Agent is tightly coupled to Losant’s broker. So, exposing the ability to set
cleanSession for the Edge Agent’s MQTT client is something that will have to be a feature. We have some upcoming MQTT / Edge Agent features in the pipeline that should help with some of the complex edge interactions you’re trying to define.
For your use case, one thing to keep in mind is the difference between connects/disconnects to the local broker vs connects/disconnects to the internet. Since it is assumed that the Edge Agent is connected to the Losant Broker, the edge agent thinks it’s connected to the internet due to a successful broker connection. There is a case where your device could be disconnected to the internet, but the edge agent still connected to the local broker. In that case, the edge agent would think it’s connected to the internet, which could lead to unexpected behavior. Just something to keep in mind as you are configuring the local broker.
It would help us a ton to understand more about your use case here. Any more information you could provide would help a ton!
Hi @anaptfox ,
Thanks for bringing this information. I know that the Edge Agent will store the messages, but my point is exactly as you stated here,
Its gonna happen a scenario where the local broker disconnects to the Losant broker (no internet), but the Edge Agent is connected to the local broker. That’s the base idea of this post: if the Edge Agent would connect with cleanSession 0 to my local broker, I would be able to persist its session, together with its message, until the connection with Losant Broker is established again, so my local broker would send all the stored messages from the Edge Agent. This problem would by solved by the MQTT protocol level.
So far, since we don’t have this feature, I had to implement a routine to check the connection between local broker and Losant Broker. Whenever the connection is dropped, I have to kill the local broker so that I drop every client connected, including the Edge Agent. This solves for now, but is not ideal, I’d rather prefer to solve it using the protocol feature.
Again, I am insisting in this feature just because it seems to me a normal feature in MQTT clients (I’ve been using cleanSession 0 in lots of clients), but I don’t know how hard is to your engineering team implement this, as there must be many other aspects to be considered. In any case, I hope in the future we get this feature in the Edge Agent. I’ll be checking for further releases.