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 Answer
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
how to connect over cellular to a remote server using MQTT
... it think that the thinking should behow to connect over cellular to the internet
, because without an internet connection, you cannot connect to the MQTT broker