Introduction: How to Use A9G Board to Subscribe to MQTT Topics and Receive Messages Using Ai-Thinker Serial Tool

In today's era of interconnected devices and Internet of Things (IoT) applications, seamless communication between devices is paramount. MQTT (Message Queuing Telemetry Transport) has emerged as a lightweight messaging protocol ideal for IoT deployments due to its efficiency and reliability. Leveraging MQTT, devices can publish and subscribe to topics, facilitating real-time data exchange.

In this guide, we'll explore how to harness the power of MQTT with the A9G board—a versatile cellular module capable of connecting to the internet. We'll walk through the process of configuring the A9G board to subscribe to MQTT topics and receive messages from an MQTT broker. With the A9G board and MQTT, you can enable bidirectional communication between your IoT devices and the cloud, unlocking a plethora of possibilities for IoT applications.

Let's dive into the details of setting up the A9G board for MQTT subscription and receiving messages using the Ai-Thinker Serial Tool

Step 1: Activating GPRS

GPRS (General Packet Radio Service) activation is essential for establishing cellular communication. Use the AT+CGATT=1 command to activate GPRS and enable data transmission over the cellular network.

AT+CGATT=1

Step 2: Configuring Access Point Name (APN)

Configure the Access Point Name (APN) settings using the AT+CGDCONT command. APN settings provide the necessary connection parameters for accessing the internet via the cellular network.

AT+CGDCONT=1,"IP","CMNET"

Step 3: Activating PDP Context

Activate the Packet Data Protocol (PDP) context using the AT+CGACT command. PDP context activation establishes a data connection, enabling internet access for the A9G board.

AT+CGACT=1,1

Step 4: Connecting to MQTT Broker

Establish a connection to the MQTT broker using the AT+MQTTCONN command. Provide the broker address, port, client ID, and authentication credentials to establish the MQTT connection.

AT+MQTTCONN="0.tcp.in.ngrok.io",14722,12345,120,0,"",""


AT+MQTTCONN="<Host>",<Port>,<ClientID>,<KeepAlive>,<CleanSession>,"<Username>","<Password>"


Here's a breakdown of the AT+MQTTCONN command parameters:

  • <Host>: MQTT broker hostname or IP address.
  • <Port>: Port number on which the MQTT broker is listening.
  • <ClientID>: Unique client identifier for the A9G board.
  • <KeepAlive>: Keep-alive interval for the MQTT connection.
  • <CleanSession>: Indicates whether the broker should clean session state.
  • <Username> and <Password>: Optional authentication credentials.

Step 5: Subscribing to MQTT Topics

Subscribe Command: Use the AT+MQTTSUB command to subscribe to MQTT topics. Specify the topic to subscribe to, along with the desired Quality of Service (QoS) level.

AT+MQTTSUB="Test",1,0


AT+MQTTSUB=<topic>,<QoS>,<Retain>
  • <topic>: MQTT topic to subscribe to.
  • <QoS>: Quality of Service level for message delivery.


Receiving Messages: Upon successful subscription, the A9G board will start receiving messages published to the subscribed topics from the MQTT broker.

Step 6: Conclusion

By following these steps, you can configure the A9G board to subscribe to MQTT topics and receive messages over a cellular connection. MQTT subscription capabilities enable the A9G board to interact with IoT applications and receive real-time updates from MQTT-enabled devices and systems.