How to Use MQTT with MOBITEK Q25 4G Modem

MOBITEK Q25 SETTINGS — MOSQUITTO MQTT SERVER

  1. Q25’s Setting:-
    • Remote Host: 175.*.*.* / *.dyndns.*
    • Remote Port: 1883
    • User Name: ***
    • User Password: ***
    • Subscribe Topic: Test
    • Publish Topic: Test
  2. Mosquitto version 2.0.14‘s Settings:-
    • In “C:\Program Files\mosquitto\mosquitto.conf”:
      • find “Listeners” and add
        listener 1883 0.0.0.0
      • find “Security” and add
        allow_anonymous true
    • Stop “Mosquitto Broker” in “Services”
    • Open command prompt as administrator and enter:
      • cd “C:\Program Files\mosquitto”
      • mosquitto -v -c mosquitto.conf
    • Add port forwarding in router:
      • Service Type = TCP
      • External Port = 1883
      • Internal IP = (Public IP of router)
      • Internal Port = 1883
      • Protocol = ALL

 

AT COMMANDS — MOSQUITTO MQTT SERVER

DESCRIPTION AT COMMAND

Configure Parameters of a TCP/IP Context

AT+QICSGP=<contextID>,<context_type>,<APN>,<username>,<password>, <authentication>

AT+QICSGP=1,1,”yoodo”,””,””,1
OK

Activate a PDP Context

AT+QIACT=<contextID>

AT+QIACT=1
OK

AT+QIACT?
+QIACT: 1,1,1,”10.*.*.*”

Configure receiving mode when data is received from server

AT+QMTCFG=“recv/mode”,<client_idx>,<msg_recv_mode>, <msg_len_enable>

AT+QMTCFG=”recv/mode”,0
+QMTCFG: “recv/mode”,0,0
OK

Open a network for MQTT client

AT+QMTOPEN=<client_idx>,“<host_name>”,<port>

AT+QMTOPEN=0,”175.*.*.*”,1883
OK
+QMTOPEN: 0,0

AT+QMTOPEN?

+QMTOPEN: 0,”175.*.*.*”,1883
OK

Connect a client to MQTT Server

AT+QMTCONN=<client_idx>,“<clientID>”,“<username>”,“<password>”

AT+QMTCONN=0,”Q25″,””,””
OK
+QMTCONN: 0,0,0

AT+QMTCONN?

+QMTCONN: 0,3
OK

Publish messages

AT+QMTPUBEX=<client_idx>,<msgID>,<qos>,<retain>,“<topic>”,<msg_length>

AT+QMTPUBEX=0,0,0,0, “Test”,30
> Q25 publish from Hyper Terminal
OK
+QMTPUBEX: 0,0,0

Subscribe to Topics

AT+QMTSUB=<client_idx>,<msgID>,“<topic1>”,<qos1>[,“<topic2>”,<qos2>…]

AT+QMTSUB=0,1, “Test”,0
OK
+QMTSUB: 0,1,0,0
+QMTRECV: 0,0, “Test”, “Publish from MQTT Explorer in HPC-8300”

Disconnect a client to MQTT Server

AT+QMTDISC=<client_idx>

AT+QMTDISC=0
OK

Close a network for MQTT client

AT+QMTCLOSE=<client_idx>

AT+QMTCLOSE=0
OK

Deactivate a PDP Context

AT+QIDEACT=<contextID>

AT+QIDEACT=1
OK

 

MOBITEK Q25 SETTINGS — FAVORIOT

  • Remote Host: mqtt.favoriot.com
  • Remote Port: 1883
  • User Name: ***
  • User Password: ***
  • Subscribe Topic: XYoUfrDZ8mzvHNKJAtkLIvVBOw23dGnb/v2/streams/status
  • Publish Topic: XYoUfrDZ8mzvHNKJAtkLIvVBOw23dGnb/v2/streams

 

AT COMMANDS — FAVORIOT

DESCRIPTION AT COMMAND

Configure Parameters of a TCP/IP Context

AT+QICSGP=<contextID>,<context_type>,<APN>,<username>,<password>, <authentication>

Parameter:

  • <contextID> – Integer type. The context ID. The range is 1-16.
  • <context_type> – Integer type. The protocol type:
    • 1 – IPV4
    • 2 – IPV4V6
  • <APN> – String type. The access point name.
  • <username> – String type. The username.
  • <password> – String type. The password.
  • <authentication> – Integer type. The authentication methods:
    • 0 – NONE
    • 1 – PAP
    • 2 – CHAP
    • 3 – PAP or CHAP
AT+QICSGP=1,1,”yoodo”,””,””,1
OK

Activate a PDP Context

AT+QIACT=<contextID>

AT+QIACT=1

AT+QIACT?
+QIACT: 1,1,1,”10.*.*.*”

Configure receiving mode when data is received from server

AT+QMTCFG=“recv/mode”,<client_idx>,<msg_recv_mode>, <msg_len_enable>

Parameter:

  • <client_idx> – Integer type. MQTT client identifier. The range is 0-5.
  • <msg_recv_mode> – Integer type. Configure the MQTT message receiving mode:
    • 0 – MQTT message received from server will be contained in URC.
    • 1 – MQTT message received from server will not be contained in URC.
  • <msg_len_enable>
    • 0 – Length of MQTT message received from server will not be contained in URC.
    • 1 – Length of MQTT message received from server will be contained in URC.
AT+QMTCFG=“recv/mode”,0,0,1

+QMTCFG: “recv/mode”,0,1

OK

Open a network for MQTT client

AT+QMTOPEN=<client_idx>,“<host_name>”,<port>

Parameter:

  • <client_idx> – Integer type. MQTT client identifier. The range is 0-5.
  • <host_name> – String type. The address of the server. It could be an IP address or a domain name. The maximum size is 100 bytes.
  • <port> – Integer type. The port of the server. The range is 1-65535.
AT+QMTOPEN=0,”mqtt.favoriot.com”,1883
OK
+QMTOPEN: 0,0

AT+QMTOPEN?

+QMTOPEN: 0,”mqtt.favoriot.com”,1883
OK

Connect a client to MQTT Server

AT+QMTCONN=<client_idx>,“<clientID>”,“<username>”,“<password>”

Parameter:

  • <client_idx> – Integer type. MQTT client identifier. The range is 0-5.
  • <clientID> – String type. The client identifier string.
  • <username> – String type. User name of the client. It can be used for authentication.
  • <password> – String type. Password corresponding to the user name of the client. It can be used for authentication.
AT+QMTCONN=0,”Q25″, “***”, “***”
OK
+QMTCONN: 0,0,0

Publish messages

AT+QMTPUBEX=<client_idx>,<msgID>,<qos>,<retain>,“<topic>”,<msg_length>

Parameter:

  • <client_idx> – Integer type. MQTT client identifier. The range is 0-5.
  • <msgID> – Integer type. Message identifier of packet. The range is 0-65535. It will be 0 only
    when <qos>=0.
  • <qos> – Integer type. The QoS level at which the client wants to publish the messages.
    • 0 – At most once
    • 1 – At least once
    • 2 – Exactly once
  • <retain> – Integer type. Whether or not the server will retain the message after it has been
    delivered to the current subscribers.

    • 0 – The server will not retain the message after it has been delivered to the
      current subscribers
    • 1 – The server will retain the message after it has been delivered to the current
      subscribers
  • <topic> – String type. Topic that needs to be published.
  • <msg_length> – Integer type. Length of message to be published.
AT+QMTPUBEX=0,0,0,0, “XYoUfrDZ8mzvHNKJAtkLIvVBOw23dGnb/v2/streams”,30
> Q25 send from Hyper Terminal
OK
+QMTPUBEX: 0,0,0

Subscribe to Topics

AT+QMTSUB=<client_idx>,<msgID>,“<topic1>”,<qos1>[,“<topic2>”,<qos2>…]

Parameter:

  • <client_idx> – Integer type. MQTT client identifier. The range is 0-5.
  • <msgID> – Integer type. Message identifier of packet. The range is 1-65535.
  • <topic> – String type. Topic that the client wants to subscribe to or unsubscribe from.
  • <qos> – Integer type. The QoS level at which the client wants to publish the messages:
    • 0 – At most once
    • 1 – At least once
    • 2 – Exactly once
AT+QMTSUB=0,0, “XYoUfrDZ8mzvHNKJAtkLIvVBOw23dGnb/v2/streams”,0
OK
+QMTSUB: 0,0,0,0
+QMTRECV: 0,0, “XYoUfrDZ8mzvHNKJAtkLIvVBOw23dGnb/v2/streams”,38, “Publish from MQTT Explorer in HPC-8300″

+QMTRECV: 0,0,”XYoUfrDZ8mzvHNKJAtkLIvVBOw23dGnb/v2/streams”,46, “Publish from MQTT Explorer in Taufiq’s desktop”

Close a network for MQTT client

AT+QMTCLOSE=<client_idx>

Parameter:

  • <client_idx> – Integer type. MQTT client identifier. The range is 0-5.
AT+QMTCLOSE=0

OK