This post is intended to help readers to use the SIM7600 4G GSM Modem with the Arduino for sending and receiving messages using MQTT protocol. The MQTT protocol facilitates easy deployment of internet-connected devices and makes the data flow of the Internet Of Things, simple and hassle-free.

 

 

SIM7600 MQTT AT Commands

 

The SIM7600 GSM Modem is having MQTT stack builtin. This enables us to use simple AT commands to connect to an MQTT broker and publish messages. The MQTT topics can also be subscribed for receiving messages from other MQTT client. See the following table showing usage of various MQTT related AT commands. 


 

Command

Function 

Example

AT+CMQTTSTART

Open network

 

AT_CMQTTSTOP

Close network

 

AT+CMQTTACCQ

Initialise MQTT client

AT+CMQTTACCQ=0,"elementz123”

AT+CMQTTREL

Destroy MQTT client 

 

AT+CMQTTCONNECT

Connect to Server

AT+CMQTTCONNECT=0,"tcp://test.mosquitto.org:1883",90,1

AT+CMQTTDISC

Disconnect from server

 

AT+CMQTTTOPIC

Set topic for publishing

AT+CMQTTTOPIC=0,8

AT+CMQTTPAYLOAD

Set payload for publishing

AT+CMQTTPAYLOAD=0,1

AT+CMQTTPUB

Publish the topic and payload set with CMQTTTOPIC and CMQTTPAYLOAD

AT+CMQTTPUB=0,1,60

AT+CMQTTSUBTOPIC

Set topic for subscription

AT+CMQTTSUBTOPIC=0,9,1

AT+CMQTTSUB

Subscribe the topic set in CMQTTSUBTOPIC 

AT+CMQTTSUB=0,4,1,1

AT+CMQTTUNSUBTOPIC

Set topic for unsubscribe

 

AT+CMQTTUNSUB

Unsubscribe the MQTT topic set by CMQTTUNSUB

 


 

For more information, consult the MQTT application document. 

Download link: https://www.elementzonline.com/downloads/SIM7600/SIM7500_SIM7600%20Series_MQTT_ATC_V1.01.pdf

 

AT command manual:

https://www.elementzonline.com/downloads/SIM7600/SIM7500_SIM7600%20Series_AT_Command_Manual%20_V1.10.pdf


 

Components Required

 

 

Connection Diagram

 


 

The SIM7600 RX-TX pins cannot be directly connected to Arduino Uno, as these pins are only 1.8Volt tolerant. You need to use a level shifter for this purpose. The board in the following link already have the level shifters on board, so that you can start using the AT command port straightaway. 

 

https://www.elementzonline.com/sim7600e-4g-gsm-ttl-usb-modem-with-sma-antenna

 

If you don’t have a board with the level shifter, the following circuitry can be used for interfacing GSM RX-TX pins with Arduino Uno.

 

Sample Code 

How to run the code

  • Download the code from here
  • Open Arduino IDE and copy-paste the below code
  • Select board and port to upload the code 
 

Code explanation

LED connected to Digital Output pin D7 can be controlled using switch which is connected to PIN 5 and through MQTT subscription at the same time. 

 

In the setup loop, the required topic is subscribed after connecting to the MQTT server. 

When a switch press is detected, the LED status is toggled. Also, the LED status is published to the publish topic. 

 

Also when a data is sent to the subscribed topic by another client, the data is received and the LED logic is changed according to the message received. In the code, when the message “a” is received, LED will be turned on and when the message “b” is received, LED is turned off. 

 

Code link: https://github.com/elementzonline/Arduino-Sample-Codes/blob/master/SIM7600/Sim7600_MQTT/Sim7600_MQTT.ino

 

Purchase link: https://www.elementzonline.com/sim7600e-4g-gsm-ttl-usb-modem-with-sma-antenna

 

Video Demo: https://www.youtube.com/watch?v=v42pwvVjII4