MQTT Protocol tutorial using SIM900/SIM800 modules – MQTT over TCP

Free test servers for demo,

Mosquitto, the creator of open source Mosquitto MQTT software also provides a free test server/broker at test.mosquitto.org,

The commercial MQTT services provider CloudMQTT.com also provides free and commercial versions for users who want to test their services.

Adafruit Industries also provides free and commercial versions of MQTT broker services at io.adafruit.com, They also provide HTTP REST API services for the same platform.

Users can use the free versions of the services mentioned above to test their MQTT enabled (Internet of Things) IOT devices.

Before we begin i recommend to read this tutorial – MQTT Protocol tutorial using Mosquitto and CloudMQTT

or watch this video on MQTT protocol basics where i explain how the CONNECT, PUBLISH, SUBSCRIBE packets are formed.

Once you are familiar with the packet formation, we can use the below packets to communicate using MQTT over TCP connection created by SIM900/SIM800.

The first step is we need to do is create a TCP connection using SIM900 or SIM800 module to the brokers, whichever you are using. 

Here i will show how you can connect to CloudMQTT.com broker from your GPRS module,

You need to create an account in cloudmqtt.com to get the necessary credentials for logging into their server. Here are the credentials i got for my free account,

Host : m10.cloudmqtt.com

Port :  17434 

Username : dxxkgkpp

Password : qAUZBdaSIULx

We will be publishing and subscribing to the topic valetron

To create a TCP connection use the following series of commands,

Set the APN parameters according to your SIM card network, Username and password are blank in my case

AT+CSTT=”www”,””,””

OK

Enable the GPRS connection

AT+CIICR

OK

Check if we have been allocated an IP address

AT+CIFSR

.10.175.97.80

Now connect to the given TCP  IP/Host and port number

AT+CIPSTART=”TCP”,”m10.cloudmqtt.com”,”17434″

OK

CONNECT OK

These are the packets we created in earlier tutorial i had mentioned earlier, 

Connect packet (Connects to server)

10 2C 00 06 4D 51 49 73 64 70 03 C2 00 3C 00 06 41 42 43 44 45 46 00 08 64 78 78 6B 67 6B 70 70 00 0C 71 41 55 5A 42 64 61 53 49 55 4C 78

Publish packet (Publishes message “helloravi” to topic “valetron”)

30 13 00 08 76 61 6C 65 74 72 6F 6E 68 65 6C 6C 6F 72 61 76 69

Subscribe packet (Subscribe packet which subscribes to topic “valetron”)

82 0D 00 01 00 08 76 61 6C 65 74 72 6F 6E 00

Send the CONNECT packet  and publish packet as shown above (Remember you need to enter these in HEX format, not in asciii format. Use tools like TMFT or Hercules for this)  End the packet with 0x1A so that the message gets sent

AT+CIPSEND

>

10 2C 00 06 4D 51 49 73 64 70 03 C2 00 3C 00 06 41 42 43 44 45 46 00 08 64 78 78 6B 67 6B 70 70 00 0C 71 41 55 5A 42 64 61 53 49 55 4C 78 30 13 00 08 76 61 6C 65 74 72 6F 6E 68 65 6C 6C 6F 72 61 76 69 1A

SEND OK

Now you should be able to see the message arrive on the subscriber or the cloudmqtt control panel. 

  

Send the SUBSCRIBE packet as shown above (Remember you need to enter these in HEX format, not in asciii format. Use tools like TMFT or Hercules for this)  End the packet with 0x1A so that the message gets sent

AT+CIPSEND 

>

82 0D 00 01 00 08 76 61 6C 65 74 72 6F 6E 00 1A

SEND OK 

 ……0…valetronLED0

The above message is received from the publisher somewhere else which sent the message “LED0” to the topic “valetron” because we have subscribed to “valetron” topic

For more detailed demonstration of the commands and the working, check this video,

 

 

 

2 thoughts on “MQTT Protocol tutorial using SIM900/SIM800 modules – MQTT over TCP”

Leave a Comment

Your email address will not be published. Required fields are marked *