.. _SLM_AT_MQTT: MQTT client AT commands *********************** .. contents:: :local: :depth: 2 The following commands list contains the AT commands used to operate the MQTT client. MQTT event #XMQTTEVT ==================== The ``#XMQTTEVT`` is an unsolicited notification that indicates the event of the MQTT client. Unsolicited notification ------------------------ It indicates the event of the MQTT client. Syntax ~~~~~~ :: #XMQTTEVT=, * The ```` value is an integer indicating the type of the event. It can return the following values: * ``0`` - Connection request. * ``1`` - Disconnection. The MQTT client is disconnected from the MQTT broker once this event is notified. * ``2`` - Message received on a topic the client is subscribed to. * ``3`` - Acknowledgment for the published message with QoS 1. * ``4`` - Confirmation of the reception for the published message with QoS 2. * ``5`` - Release of the published message with QoS 2. * ``6`` - Confirmation to a publish release message with QoS 2. * ``7`` - Reception of the subscribe request. * ``8`` - Reception of the unsubscription request. * ``9`` - Ping response from the MQTT broker. * The ```` value is an integer indicating the result of the event. It can return the following values: * ``0`` - Success. * *Negative value* - Failure. It is the error code indicating the reason for the failure. MQTT connect #XMQTTCON ====================== The ``#XMQTTCON`` command allows you to connect to and disconnect from the MQTT broker. Set command ----------- The set command allows you to connect to and disconnect from the MQTT broker. Syntax ~~~~~~ :: AT#XMQTTCON=[,,,,,[,]] * The ```` parameter is an integer. It can accept one of the following values: * ``0`` - Disconnect from the MQTT broker. * ``1`` - Connect to the MQTT broker using IP protocol family version 4. * ``2`` - Connect to the MQTT broker using IP protocol family version 6. * The ```` parameter is a string. It indicates the MQTT Client ID. * The ```` parameter is a string. It indicates the MQTT Client username. * The ```` parameter is a string. It indicates the MQTT Client password in cleartext. * The ```` parameter is a string. It indicates the MQTT broker hostname. * The ```` parameter is an unsigned 16-bit integer (0 - 65535). It indicates the MQTT broker port. * The ```` parameter is an integer. It indicates the credential of the security tag used for establishing a secure connection. Response syntax ~~~~~~~~~~~~~~~ :: #XMQTTEVT: , * The ```` value is an integer. When ``0``, it indicates the acknowledgment of the connection request. * The ```` value is an integer. It can return the following values: * ``0`` - Connection succeeded. * *Negative Value* - Error code. It indicates the reason for the failure. Examples ~~~~~~~~ :: AT#XMQTTCON=1,"MyMQTT-Client-ID","","","mqtt.server.com",1883 OK #XMQTTEVT: 0,0 :: AT#XMQTTCON=0 OK #XMQTTEVT: 1,0 Read command ------------ The read command shows MQTT client information. Syntax ~~~~~~ :: AT#XMQTTCON? Response syntax ~~~~~~~~~~~~~~~ :: #XMQTTCON: ,,[,]] * The ```` value is a string. It indicates the MQTT client ID. * The ```` value is a string. It indicates the MQTT broker hostname. * The ```` value is an unsigned 16-bit integer (0 - 65535). It indicates the MQTT broker port. * The ```` value is an integer. It indicates the credential of the security tag used for establishing a secure connection. Examples ~~~~~~~~ :: AT#XMQTTCON? #XMQTTCON: "MyMQTT-Client-ID","","","mqtt.server.com",1883 OK Test command ------------ The test command is not supported. MQTT subscribe #XMQTTSUB ======================== The ``#XMQTTSUB`` command allows you to subscribe to an MQTT topic. Set command ----------- The set command allows you to subscribe to an MQTT topic. Syntax ~~~~~~ :: AT#XMQTTSUB=, * The ```` parameter is a string. It indicates the topic to be subscribed to. * The ```` parameter is an integer. It indicates the MQTT Quality of Service types. It can accept the following values: * ``0`` - Lowest Quality of Service. No acknowledgment of the reception is needed for the published message. * ``1`` - Medium Quality of Service. If the acknowledgment of the reception is expected for the published message, publishing duplicate messages is permitted. * ``2`` - Highest Quality of Service. The acknowledgment of the reception is expected and the message should be published only once. Response syntax ~~~~~~~~~~~~~~~ :: #XMQTTEVT: , * The ```` value is an integer. It can return the following values: * ``2`` - Notification that a *publish event* has been received on a topic the client is subscribed to. * ``7`` - Acknowledgment of the subscribe request. * The ```` value is an integer. It can return the following values: * ``0`` - Value indicating the acknowledgment of the connection request. * *Negative Value* - Error code indicating the reason for the failure. Unsolicited notification ~~~~~~~~~~~~~~~~~~~~~~~~ If the MQTT client successfully subscribes to a topic, the following unsolicited notification indicates that a message from the topic is received: :: #XMQTTMSG: , * The ```` value is an integer. It indicates the length of the ```` field. * The ```` parameter is an integer. It indicates the length of the ```` field. * The ```` value is a string. It indicates the topic that receives the message. * The ```` value can be a string or a HEX. It contains the message received from a topic. Examples ~~~~~~~~ :: AT#XMQTTSUB="nrf91/slm/mqtt/topic0",0 OK #XMQTTEVT: 7,0 :: AT#XMQTTSUB="nrf91/slm/mqtt/topic1",1 OK #XMQTTEVT: 7,0 :: AT#XMQTTSUB="nrf91/slm/mqtt/topic2",2 OK #XMQTTEVT: 7,0 Read command ------------ The read command is not supported. Test command ------------ The test command is not supported. MQTT unsubscribe #XMQTTUNSUB ============================ The ``#XMQTTUNSUB`` command allows you to unsubscribe from an MQTT topic. Set command ----------- The set command allows you to unsubscribe from an MQTT topic. Syntax ~~~~~~ :: AT#XMQTTUNSUB= * The ```` parameter is a string. It indicates the topic to unsubscribe from. Response syntax ~~~~~~~~~~~~~~~ :: #XMQTTEVT: , * The ```` value is an integer. When ``8``, it acknowledges the reception of the unsubscription request. * The ```` value is an integer. It can return the following values: * ``0`` - Value indicating the successful unsubscription. * *Negative Value* - Error code indicating the reason for the failure. Examples ~~~~~~~~ :: AT#XMQTTUNSUB="nrf91/slm/mqtt/topic0" OK #XMQTTEVT: 8,0 Read command ------------ The read command is not supported. Test command ------------ The test command is not supported. MQTT publish #XMQTTPUB ====================== The ``#XMQTTPUB`` command allows you to publish messages on MQTT topics. Set command ----------- The set command allows you to publish messages on MQTT topics. Syntax ~~~~~~ :: AT#XMQTTPUB=[,[,[,]]] * The ```` parameter is a string. It indicates the topic on which data is published. * The ```` parameter is a string. It contains the payload on the topic being published. The maximum size of the payload is 256 bytes when not empty. If the payload is empty (for example, ``""``), SLM enters ``slm_data_mode``. * The ```` parameter is an integer. It indicates the MQTT Quality of Service types. It can accept the following values: * ``0`` - Lowest Quality of Service (default value). No acknowledgment of the reception is needed for the published message. * ``1`` - Medium Quality of Service. If the acknowledgment of the reception is expected for the published message, publishing duplicate messages is permitted. * ``2`` - Highest Quality of Service. The acknowledgment of the reception is expected and the message should be published only once. * The ```` parameter is an integer. Its default value is ``0``. When ``1``, it indicates that the broker should store the message persistently. Response syntax ~~~~~~~~~~~~~~~ :: #XMQTTEVT: , * The ```` value is an integer. It can return the following values: * ``3`` - Acknowledgment for the published message with QoS 1. * ``4`` - Reception confirmation for the published message with QoS 2. It is notified when PUBREC is received from the broker. * ``5`` - Release of the published message with QoS 2. * ``6`` - Confirmation (PUBREL) to a publish release message with QoS 2. It is notified when PUBREL is received from the broker. * The ```` value is an integer. It can return the following values: * ``0`` - Value indicating the acknowledgment of the connection request. * *Negative Value* - Error code indicating the reason for the failure. Examples ~~~~~~~~ :: AT#XMQTTPUB="nrf91/slm/mqtt/topic0","Test message with QoS 0",0,0 OK #XMQTTMSG: 21,23 nrf91/slm/mqtt/topic0 Test message with QoS 0 #XMQTTEVT: 2,0 :: AT#XMQTTPUB="nrf91/slm/mqtt/topic0" OK {"msg":"Test Json publish"}+++ #XDATAMODE: 0 #XMQTTMSG: 21,27 nrf91/slm/mqtt/topic0 {"msg":"Test Json publish"} #XMQTTEVT: 2,0 :: AT#XMQTTPUB="nrf91/slm/mqtt/topic1","Test message with QoS 1",1,0 OK #XMQTTEVT: 3,0 #XMQTTMSG: 21,23 nrf91/slm/mqtt/topic1 Test message with QoS 1 #XMQTTEVT: 2,0 :: AT#XMQTTPUB="nrf91/slm/mqtt/topic2","",2,0 OK Test message with QoS 2+++ #XDATAMODE: 0 #XMQTTEVT: 4,0 #XMQTTEVT: 6,0 #XMQTTMSG: 21,23 nrf91/slm/mqtt/topic2 Test message with QoS 2 #XMQTTEVT: 2,0 Read command ------------ The read command is not supported. Test command ------------ The test command is not supported.