Contributed by 爱笑, organized by Ai-Thinker
Ai-WB2 Module MQTT over TLS Connection to Server Usage Example
1. Preparation Hardware and software required: an Ai-WB2 series module or development board, and a Type-C data cable 2. Connect to a Router
First make sure the module or development board prints "ready" after power-on, as shown below:

Send AT+CWMODE=1;AT+CWJAP="WIFI名称","WIFI密码". For example, the WIFI I am testing now is named aithinker123 with the password 123456789, as shown below:

3. MQTT over TLS Connection
The MQTT server used in this example can be debugged at this URL: <https://www.emqx.com/zh/mqtt/public-mqtt5-broker>

First open the online MQTT client, click the settings icon, and change the language to Simplified Chinese, as shown below

Click the + icon to create a new MQTT client connection. The specific parameters are shown in the figure below

(1) Pick a random test name
(2) Pick a random client ID (3) TLS encryption is used here, so select "wss://" as the host prefix (4) For a wss connection, the port number must be 8084; for an MQTT connection, use 8883 (5) Pick a random account and password (6) Select SSL/TLS encryption and choose the CA-signed server (7) Select MQTT version 3.1.1 (8) Leave the Last Will section unconfigured If the parameters are correct, clicking the Connect button will establish the connection successfully. Then click Add Subscription, enter aithinker as the Topic, and click OK. Also enter aithinker as the topic name above the publish data box, as shown below

(1) Add a "subscription" (2) Configure the "sub" related parameters, and enter aithinker as the topic (3) Also enter aithinker as the publish topic (4) Publish data Go back to the serial port debugging assistant and send the MQTT related commands. The specific commands are as follows
Click to expand full code
AT+CIPSNTPCFG=1,8,"ntp1.aliyun.com"
AT+CIPSNTPTIME?
AT+MQTTUSERCFG=0,4,"aithinker888","admin","public",0,0,""
AT+MQTTCONN=0,"broker.emqx.io",8883,1
AT+MQTTSUB=0,"aithinker",0
AT+MQTTPUB=0,"aithinker","I am a aithinker fan",1,0After the commands are sent, the data reported by the module can be read in the MQTT client


4. Contact Us
That is all for this sharing session. Its purpose is to help everyone quickly adapt to developing with the new product solutions. More materials are available on our official website. Official website: <https://www.ai-thinker.com>
Development resources: <https://docs.ai-thinker.com/> Technical support: support@aithinker.com

