How to connect to mqtt broker on long period publishing device

Hi guys,

I need some help here. I have some questions about mqtt.

I’m working on a project that needs to publish some values every 15 minutes, 30 minutes, or even 1 hour from a field-deployed remote device equipped with SIMCOM’s Sim7070G, which includes support for the mqtt protocol.

My questions :

What is your suggestion or recommended procedure to connect with the broker in case of posting every 10 minutes or more?

  • Do I have to open and close the broker connection on each post? Or should I keep the connection opened? How? Please note that the device is a low power type so I would like to keep the transmissions as quiet as possible.

  • What is the role of the keepalive timeout in the case of publishing interval greater than 90 seconds if the losant server closes the connection?

  • Does the connection request to the broker have limitations? If yes, what is the limit per device?

Thanks!!!

Hey @Walter_Peresson,

Welcome to the Losant Forums, we’re happy to have you!

Addressing your questions individually:

What is your suggestion or recommended procedure to connect with the broker in case of posting every 10 minutes or more?

Opening/closing the connection on a schedule depends on how the device is powered. If power consumption is a concern in your use case, then I would recommend that you open & close the connection and then sleep the device and/or modem as the majority of the power will be consumed by keeping the radio powered on. If power consumption is not a concern, then opening an MQTT connection and leaving that connection open is just fine.

Do I have to open and close the broker connection on each post? Or should I keep the connection opened? How?

With MQTT you do not have to open and close the connection on each post. First, the connection to the broker is established, and then on a frequency that you define, data is published to a topic. Leaving the connection open depends on how your device is powered, as mentioned. In a battery-powered use case, where power consumption is a major concern, closing the MQTT connection and sleeping the modem (either wifi or cellular) will preserve the battery.

What is the role of the keepalive timeout in the case of publishing interval greater than 90 seconds if the losant server closes the connection?

The Keepalive timeout is simply a ping and response to ensure that the connection from the MQTT client to the broker is still working. This does not depend on how often a client is publishing data, but rather that the client is still maintaining a connection to the broker.

Does the connection request to the broker have limitations?

Could you give some examples of limitations you’re are referencing here? As we outline in our documentation, the connection request to the Losant Broker must include a Client ID, Username, and Password. Are there any other limitations that you are referencing that you’d like for me to address?

Please let me know if I can explain anything further or better.

Thank you,
Heath

Hi Heath, thanks for your quick response to my questions, you have been very helpful.

Our devices are battery powered so we are going to open the connection, publish and then it will be closed, just like you mentioned.

I can see from my organization’s “usage” page on Losant that connections and disconnections are counted as payloads (see image below). So what I want to know is if there is any restriction from Losant on the number of connections to the broker per device per unit of time (per day or month). As an example, if I publish a value from a single device every 15 Min, I will connect-publish-disconnect from broker almost 100 times per day. Is it ok from the broker side?

@Walter_Peresson,

Happy to help!

…if I publish a value from a single device every 15 Min, I will connect-publish-disconnect from broker almost 100 times per day. Is it ok from the broker side?

There should be no issue in doing this :slight_smile:

Another thing I would like to point out is that you have the ability to batch report device state. This means that if you don’t need that data in the 15-minute intervals, you can collect data throughout the day, and then report all that data at once in one publish once a day.

Let me know if you have any other questions.

Thank you,
Heath