Publishing/Subscribing to MQTT broker from SigCell M1-N1 using certificates

Note: In the following example, certificates are loaded to sectag 3.

Wait until startup completes

+notify,event:init,result:0,firmware:v1.0.9
+notify,carrier:connecting
+notify,carrier:connected
+notify,imei:352656100169179
+notify,event:coap,init:1

Disable connecting to setup certificates and server details

+set,connect:0

expect this response

+rsp,connect:0

Enable the protocol

+set,enabled:0

expect this response

+rsp,enabled:0

Take the modem offline (AT+CFUN=4) for updating certificates. 

+set,at:AT+CFUN=4

expected response

+rsp,at:OK

Setup sectag to use to store the certificates

+set,sectag:3

expected response

+rsp,sectag:3

Perform this additional step for device internals to be informed about the sectag

+set,sectagq:3

expected response

+rsp,sectagq:3

Send cacert (copy paste multi line text from a text editor. )

+set,cacert:"--—BEGIN CERTIFICATE--—..."

expected response

+rsp,cacert:0

Send device private key (copy paste multi line text from a text editor. )

+set,privkey:"--—BEGIN PRIVATE KEY--—..."

expected response

+rsp,privkey:0

Send device certificate (copy paste multi line text from a text editor. )

+set,privcert:"--—BEGIN CERTIFICATE--—..."

expected response

+rsp,privcert:0

Bring modem online

+set,at:AT+CFUN=1

expected response

+rsp,at:OK

Setup protocol

+set,proto:mqtt

expected response

+rsp,proto:mqtt

Wait to receive notification about device completing MQTT initialization

+notify,event:mqtt,init:1

Disable until we setup distills to connect to server

+set,enabled:0

expected

+rsp,enabled:0

Setup MQTT clean_session property if desired.

+set,clean_session:1

expected response

+rsp,clean_session:1

set device ID

+set,devid:abcd

expected response

+rsp,devid:abcd

set MQTT broker server address

+set,server_address:broker.site.com

expected response

+rsp,server_address:broker.site.com

set MQTT broker server port

+set,server_port:8883

expected response

+rsp,server_port:8883

Set user/password. Some MQTT brokers require username password in addition to cert/keys.

+set,user:uname

expected output

+rsp,user:uname
+set,pw:password

expected output

+rsp,pw:password

Setup publish topic

+set,pubtopic:sensor/abcd/cellular_uplink_raw

expected output

+rsp,pubtopic:sensor/abcd/cellular_uplink_raw

Setup subscribe topic

 +set,subtopic:sensor/abcd/#

expected response

+rsp,subtopic:sensor/abcd/#

Enable connection to sever

+set,enabled:1

expected output

+rsp,enabled:1

Upon successfully connecting, device will send notify messages like these

+notify,event:mqtt,connecting:1,host:broker.site.com,devid:abcd,user:uname,pw:password
+notify,event:mqtt,connected:1

You can send your data by "pushing" it to a queue. For testing, just use the first queue: queue1. The data payload here is temp:1,humid:2

+push,queue1,temp:1,humid:2

Expect response like this. result:0 is success.

+rsp,result:0,mark:1
+notify,mqtt:pub,topic:sensor/abcd/cellular_uplink_raw,data:temp:1,humid:2,error:0
+notify,mqtt:pub,mark:1,id:55544
+notify,mqtt:puback,id:55544

If you send a message to the sub topic, device will send these notify messages

+notify,mqtt:sub,topic1:sensor/abcd/#
+notify,mqtt:subevent,qos:1,topic:sensor/abcd/down,payload:howdy

Device will report mqtt server pings like this

+notify,mqtt:ping
+notify,mqtt:ping

You are now connected, using secure certificates!

Read more