I was wondering if anyone can give me some pseudocode structure that outlines the general procedures that need to happen to connect over cellular to a remote server using MQTT? To be specific, I already know all about MQTT basics. I need to write a library for this and I would just really appreciate some technical guidance on how to structure the code. If it helps at all, I'm using a Lara R2-02 Ublox cellular module from mikroe for my modem. If you have any technical resources you could share with me too, I would be grateful.

  • 1
    Please update the question with what you've already thought of. Also some information about what you will be interfacing with the UBlox device and how as this will have a huge impact on how you would approach this.
    – hardillb
    Jan 11, 2021 at 13:12
  • 1
    how to connect over cellular to a remote server using MQTT ... it think that the thinking should be how to connect over cellular to the internet, because without an internet connection, you cannot connect to the MQTT broker
    – jsotola
    Jan 11, 2021 at 23:19
  • Why add the dislike? I'm not asking anyone to give me a library and do all my work for me, but basically just give an in english version of the steps I should expect to take. For example, I've noticed a lot of libraries attach to some GPRS service and open a socket. I'm attempting to write a library myself and thought some additional knowledge would help. Jan 19, 2021 at 0:52

1 Answer 1


The general steps are:

  • Figure out how to have your modem connect to the internet. See the manual for the modem. (This may involve some carrier specific settings too.)
  • Now, you have the ability to do tcp/ip to the internet. Make sure you can connect to something via TCP/IP.
  • Now, you're ready to connect to an MQTT broker. Find out its security needs.
  • Use an MQTT library for connecting. Configure its security and use the connect method.
  • If you are wanting to implement said library, see the spec on MQTT https://docs.oasis-open.org/mqtt/mqtt/v5.0/mqtt-v5.0.html and view the source code on a few existing libraries. Their test code should give you an idea of the sequences.

If you get stuck at a specific step, you maybe able to ask a more specific question that someone can give you a specific answer to. One other option is to use AWS IoT device sdk as a starting point. See https://docs.aws.amazon.com/iot/latest/developerguide/iot-sdks.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.