调整格式

This commit is contained in:
huang 2023-10-07 14:59:41 +08:00
parent cf565f5d69
commit e07d4e2711
37 changed files with 71 additions and 23 deletions

View File

@ -1,14 +1,5 @@
SRC_FILES += test_mqttclient.c\
MQTTPacket.c\
MQTTConnectClient.c \
MQTTConnectServer.c \
MQTTDeserializePublish.c \
MQTTFormat.c \
MQTTSerializePublish.c \
MQTTSubscribeClient.c \
MQTTSubscribeServer.c \
MQTTUnsubscribeClient.c \
MQTTUnsubscribeServer.c \
transport.c
SRC_FILES += test_mqttclient.c
SRC_DIR += mqtt
include $(KERNEL_ROOT)/compiler.mk

View File

@ -1,15 +1,55 @@
## 1. 简介
本代码实现了MQTT对服务器订阅主体并发送信息功能
## 2. 数据结构设计说明
### 2.1 MQTT数据结构定义
![image-20231007142702891](.\imgs\图片4.png)
### 2.2 数据解析与加密
![image-20231007143235579](.\imgs\图片5.png)
### 2.3 MQTT连接与订阅
![image-20231007143448685](.\imgs\图片6.png)
![image-20231007143607579](.\imgs\图片7.png)
## 3. 测试程序说明
MQTT基于TCP/IP协议分为客户端与服务端。在本任务中ARM终端作为客户端与服务端连接并进行主题订阅。
以下代码设置了进行订阅时需要的Client ID、用户名、密码及订阅主题。
![image-20231007144555989](.\imgs\图片8.png)
客户端首先需要根据以上信息向服务端发起连接请求,验证用户名及密码
![image-20231007144710185](.\imgs\图片9.png)
随后进行主题订阅,接收服务端发布的消息
![image-20231007144823940](.\imgs\图片10.png)
在订阅过程中需要对获取的信息进行读取同时每隔一段时间向服务端发送保持活性ping请求以维持与服务端的连接
![image-20231007144921430](.\imgs\图片11.png)
## 4. 测试流程
测试流程为:
首先执行setip命令设置设备ip地址
![图片2](.\图片2.png)
![图片2](.\imgs\图片2.png)
随后执行“MqttSocketSendTest 服务器ip”命令订阅主题并发送test信息
随后执行“MqttSocketRecvTest 服务器ip”命令订阅主题然后在服务器端发布消息如图所示
![图片1](.\图片1.png)
![图片1](.\imgs\pic1.png)
最终服务器接收到信息,如图所示
最终设备端接收到信息
![图片3](.\图片3.png)
![图片3](.\imgs\pic2.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

View File

@ -0,0 +1,13 @@
SRC_FILES +=MQTTPacket.c\
MQTTConnectClient.c \
MQTTConnectServer.c \
MQTTDeserializePublish.c \
MQTTFormat.c \
MQTTSerializePublish.c \
MQTTSubscribeClient.c \
MQTTSubscribeServer.c \
MQTTUnsubscribeClient.c \
MQTTUnsubscribeServer.c \
transport.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -27,9 +27,9 @@
#include "lwip/sys.h"
#include "lwip/api.h"
#include "MQTTPacket.h"
#include "MQTTSubscribe.h"
#include "transport.h"
#include "mqtt/MQTTPacket.h"
#include "mqtt/MQTTSubscribe.h"
#include "mqtt/transport.h"
#include <cJSON_Process.h>
#endif

View File

@ -39,14 +39,18 @@
#define USER_NAME "test&iw3rn3pa11K" //用户名
#define PASSWORD "7b948d22fe46f0f63d1a403376d26e7cb298abc227d29e44311d7040307a71f8" //秘钥
// #define CLIENT_ID "hc123456789" //随机的id
// #define USER_NAME "xiuos" //用户名
// #define PASSWORD "xiuos" //秘钥
#define TOPIC "/iw3rn3pa11K/test/user/Test" //订阅的主题
#define TEST_MESSAGE "test_message" //发送测试消息
// #define CLIENT_ID "hc123456789" //随机的id
// #define USER_NAME "xiuos" //用户名
// #define PASSWORD "xiuos" //秘钥
enum QoS
{ QOS0 = 0,
QOS1,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB