How to Connect with MQTT Broker and Subscribe to Any MQTT Topics and Receive Updates via A9G Board using AT Commands over Cellular Internet
Setting up A9G Board for MQTT Communication
Configuring A9G Board for MQTT Subscription
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
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"
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
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.
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.
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.
Comments
Post a Comment