Block Diagram:
This post will fully introduce how to use at command of Wiznet module(WizFi250) to communicate with MQTT Server.
After read the article, you can get more understanding on the relationship between Publisher and Subscriber on MQTT with WizFi250.
Block
Diagram2:
Step
1: Create your own Cloud Server.
For example: https://www.cloudmqtt.com/
After
you created your cloud server, you will get your server detail.
Step 2: Create the TCP connection between the client and
broker
AT
Command
for making the Client as Station mode and TCP client:
at+wset=0,SSID
at+wsec=0,,PASSWORD
at+wnet=1
at+wjoin
———Join AP————
at+scon=SO,TCN, broker IP,port,,1
———–Connect to Broker————-
Right now, client is connecting to broker with TCP connection.
Server: m10.cloudmqtt.com
Server IP: 54.92.237.174
Port: 10250
Step 3: Create the MQTT “Connect” between the client and
broker
AT+SCON=SO,TCN,54.92.237.174,10250,,1
104400044d51545404c6003c|0017|Handkie8911111111111111|0003|ABC|0002|hi|0008|ynxbaern|000c|cctdGq-Go7Ce
Fixed Header: 0x10,0x34
Variable Header: 0x00, 0x04, 0x4d,
0x51, 0x54, 0x54, 0x04, 0xc6,
0x00, 0x3c
Payload:
Client ID: 0x00,
0x07, 0x48, 0x61, 0x6e, 0x64, 0x6b, 0x69,
0x65 (Handkie)
Will Topic: 0x00,
0x03 0x41, 0x42, 0x43 (abc)
Will Message: 0x00, 0x03, 0x65, 0x6e, 0x65 (end)
Username: 0x00, 0x08,
0x79, 0x6e, 0x78, 0x62, 0x61, 0x65,
0x72, 0x6e (ynxbaern)
Password: 0x00, 0x0c,
0x63, 0x63, 0x74, 0x64, 0x47, 0x71,
0x2d, 0x47, 0x6f,
0x37, 0x43, 0x 65(cctdGq-Go7Ce)
PS: For each items of payload need to add 1 byte of MSB and LSB
CONNECT coding (in HEX):
103500044d51545404c6003c000748616e646b696500036162630003656e640008796e78626165726e000c6363746447712d476f374365
Respond in Serial Terminal:
5MQTT?<HandkieabcenynxbaerncctdGq-Go7Ce
Step 4: Subscribe the Topic (refer to Block Diagram2)
Topic1: 0x57, 0x69, 0x7a, 0x46, 0x69, 0x32, 0x35, 0x30(WizFi250)
Topic2: 0x57, 0x69, 0x7a, 0x46, 0x69, 0x32, 0x37, 0x30(WizFi270)
SUBSCRIBE coding (in HEX):
820D0004000857697a466932353000
820D0004000857697a466932373000
Respond in Serial Terminal:
5MQTT?<HandkieabcenynxbaerncctdGq-Go7Ce ?WizFi250??WizFi270?
Step 5: Publish the message to Topic
Topic1: 0x57, 0x69, 0x7a, 0x46, 0x69, 0x32, 0x35, 0x30(WizFi250)
Message1: 0x68, 0x61, 0x6c,0x6c, 0x6f(hallo)
Topic2: 0x57, 0x69, 0x7a, 0x46, 0x69, 0x32, 0x37, 0x30(WizFi270)
Message2: 0x68, 0x69 (hi)
PUBLISH coding (in HEX):
300F000857697a466932353068616c6c6f
300C000857697a46693237306869
Respond in Serial Terminal:
5MQTT?<HandkieabcenynxbaerncctdGq-Go7Ce ?WizFi250??WizFi270?WizFi250halloWizFi250halloWizFi270hiWizFi270hi
The Received messages in Websocket UI:
Publish message in Serial Terminal
300F000857697a466932353068616c6c6f
300C000857697a46693237306869
Timeout and Disconnect
If there is no message send out or receive, it will timeout and disconnect.
Will Topic: 0x00, 0x03 0x41, 0x42, 0x43 (abc)
Will Message: 0x00, 0x03, 0x65, 0x6e, 0x65 (end)
Keep Alive Timer MSB: 0x00
Keep Alive Timer LSB: 0x3c