# 消息通信功能测试

### 测试连接CP7核心服务

#### 安装MQTT客户端工具 MQTTlens

1. 安装谷歌浏览器
2. 搜索 MQTTLens
3. 点击安装应用
4. 启动应用
5. 点击 connections +按扭

{% hint style="danger" %}
CP7默认情况下ClientId不允许为空，并且不允许包含 “-”字符，否则连接将被服务端丢弃（V7.3.2.8版本开始不再限制"-"字符）
{% endhint %}

![建立连接到服务器端IP:192.168.200.201](/files/-LQOQf29qg_M0fGr9BXF)

![消息发送测试](/files/-LQORQakEcnundJTv2cK)

1. 连接为绿色说明已与服务器端正常建立连接
2. 先通过SUBSCRIBE按扭向服务器端订单 a/b/c主题
3. 通过PUBLISH按扭推送测试消息到a/b/c主题

{% hint style="info" %}
因为第2步已先订阅了a/b/c主题，所以当推送消息时当前应用会接收到所发送的消息，消息过程如下：

pub a/b/c message -> Coolpy7 -> sub a/b/c message

同时还可以测试Qos消息质量通信，当SUB订单主题时Coolpy7会以订阅为Qos基准，即当PUB推送消息时Qos级别低于订阅Qos级别时Coolpy7会自动升级为订单级别的Qos级别。
{% endhint %}

### 测试连接CP7 WebSocket代理服务

![Hostname设置为ws://，Port设备为8083](/files/-LQObuCzW99nHR2yObb9)

{% hint style="info" %}
连接建立后与测试Coolpy7核心服务操作一致，CP7 TLS代理服务和CP7 WS TLS代理服务使用方法一致，只需把连接协议标识为tls\://和wss\://开头即可。请确保证书与域名一致即可。
{% endhint %}

### 开源 MQTT 示例性应用项目

| 项目说明          | 开源地址                                      |
| ------------- | ----------------------------------------- |
| 网页版聊天室示例      | <https://github.com/Coolpy7/Cp7Chat>      |
| 微信小程序版聊天室示例   | <https://github.com/Coolpy7/wxsmallapp>   |
| ESP单片机IOT示例   | <https://github.com/Coolpy7/EspSdk>       |
| DbPoxy网页端操作示例 | <https://github.com/Coolpy7/dbpoxyclient> |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://coolpy7.gitbook.io/coolpy7book/kai-shi-shi-yong/xi-tong-gong-neng-yan-zheng.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
