4

I have used the pubsubclient library for Arduino for communicating with an MQTT broker in the past, however the library works only with Ethernet connecction. I need to use GSM in my application and am using the SIM900 at the moment. However, I cannot seem to find any library for MQTT communication using an Arduino as MQTT client and SIM900 as gateway. I found this to be surprising as there must surely be many instances where one would want to upload data from Arduino to a MQTT broker in a mobile scenario where cellular network is the only option (in place of Ethernet). So my questions are:

  1. Is it possible to use the Arduino as MQTT client and SIM900 as gateway for communicating with an MQTT broker? Are there any libraries for the same?
  2. What is the current standard way (gateway / communication protocol) of uploading some sensor data from Arduino to an internet server in a mobile scenario (i.e., where Ethernet is not an option)?
  • I too had the same problem. Mine was a self powered(battery) arduino sensor kit. I tried many and at last ,as the last resort had to use the usual HTTP requests to send data. – Laksith Jan 25 '16 at 9:14
3

MQTT Library for SIM800 GSM Modem is available at ElementzTechBlog, ElementzGithubRepository

Functionalities:

Auto connect

   Automatically connect to TCP and to MQTT server.

connect function

   This function can be used to connect your client to MQTT broker.
   Use only if you do not use Auto connect functionality.
   Optionally  you can use username, password, WILL topic and WILL Message.

OnConnect CallBack function

   This call back function is called when MQTT connection is established.
   You can call subscription and publish functions inside it (according to your need).

publish function

   This function can be used to publish messages to different topics.
   You can select  QoS levels and RETAIN flag according to your need.

subscribe function

   This function can be used to subscribe messages from different topics.

OnMessage CallBack function

   This callback function is called when messages are received from  subscribed topics
   Topic, TopicLength, Message, MessageLength are the arguments of  OnMessage callback function.
   Inside this, you can write your custom code.

unsubscribe function

   This function can be used to unsubscribe from a previously subscribed topic.

disconnect function

   This function can be used to disconnect your client from MQTT broker.

Keep Alive

   You can specify your KeepAlive duration while initializing.
   Ping requests are sent and received automatically.
1
  1. MQTT by definition is a TCP/IP protocol, so if you don't have a TCP/IP stack, then it is a no go.
  2. A common pattern/infrastructure in the IoT is to have your "things" connect to a hub of some kind (via BLE, XBee, or ... etc.) and then the hub will connect to the network and post the data. Another option would be to get a cellular device that provides a data connection (i.e. 2G/3G) and therefore a TCP/IP stack. It looks like the SIM900 only supports calls and texts, and as of this moment I am not aware of such a device that has libraries for Arduino.
  • Actually, the SIM900 comes with a built-in TCP/IP stack. Also 'pubsubclient' accepts a generic Client, which has defined the usual read(), print(), connect(), etc methods; it is definitely possible to create these methods for a 'SIM900 object' and pass it to the pubsubclient constructor and so achieve MQTT functionality. – TisteAndii Jul 16 '16 at 14:06
1

The SIM900 allows creation of TCP sockets through an AT style command language, so this addresses point #1 of the previous comments concern.

This is only half the story though, you'll still need to learn how to create the requests, and handle the responses of the MQTT protocol using the SIM900's protocol.

There may be usable examples to start from in the ESP8266 community, as their style of TCP API looks similar to the SIM900.

1

Take a look at the FONA library from Adafruit.

https://github.com/adafruit/Adafruit_MQTT_Library/blob/master/examples/mqtt_fona/

The FONA Library uses SIM800 which is a newer version of SIM900. You will find MQTT and FONA within the same library. They also run an MQTT Broker service in adafruit.io

0

These tutorials should help on getting started with MQTT on SIM900 or SIM800.

MQTT Protocol tutorial - LIVE DEMO using Mosquitto and CloudMQTT https://youtu.be/Oh3ZYAQBTko

This video explains about the main important control packets of MQTT protocol by explaining what each byte in a MQTT packet means and also shows how to send and receive data using TCP and Websockets UI of CloudMQTT.com Control panel. We also learn on how to use the Mosquitto Open source broker on Windows machine to Publish and subscribe to MQTT message and topics on localhost and to cloud servers with and without Authentication.

MQTT Protocol tutorial using SIM900/SIM800 modules - LIVE DEMO https://youtu.be/dcpMa2UwEeA

This video demonstrates how you can use the light weight MQTT protocol on the SIM900 or SIM800 GSM modules using TCP over the GPRS connection. Here you will learn, how you can use the SIM900/SIM800 TCP commands to send and receive messages as a publisher and a subscriber in almost realtime.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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