@cpvrt/cp-mqtt-client
v1.0.17
Published
the client for cpvrt emqx server
Downloads
12
Readme
CpvrtMqttClient For EmqX
Install
使用npm install
或yarn install
进行依赖包安装.
使用tsc
进行打包, 生成文件位于./dist/
下, 更多见./tsconfig.json
.
Usage
在项目中使用npm
或者yarn
进行安装
npm install @cpvrt/cp-record-player
或
yarn add @cpvrt/cp-record-player
引入, 可分模块引入
import {
MqttClient,
SimulatorStatusModel,
SimulatorByClassroomModel
} from '@cpvrt/cp-mqtt-client'
启用, 需要先设置链接参数
// 设置链接参数
// MqttClient.Debug = true;
MqttClient.setConnectOptions('cpvrt.com', '6083', {
clientId: 'controller_' + MqttClient.generateUuid(),
username: 'controller',
password: '3hMi0lwVmvoMz31ZSTPXdb9KDA18YRyx'
});
// 接收全部设备状态
SimulatorStatusModel.Instance.Enable();
SimulatorStatusModel.Instance.on('rec_device_status', (data) => {
console.log(data);
});
// 仅接收某教室设备状态
this.model = new SimulatorByClassroomModel('192.168.10.254');
this.model.Enable();
this.model.on('rec_device_status', (data) => {
console.log(data);
});
停用
// 关闭前需要停用
SimulatorStatusModel.Instance.Disable();
this.model.Disable();
MqttClient.Instance.disconnect();
Model Function&Event
SimulatorStatusModel
| Name | Type | Comments | |:------------------|:---------|:------------| | rec_device_status | Event | 当接收到状态变更时触发 | | RefreshAll | Function | 发送强制刷新消息 |
Develop & Todo list
- 模拟器异常信息模块
- 教室服务器信息模块
Publish
注册npm账号并加入cpvrt, 之后再publish. publish之前注意升版本号, 版本号的管理规范暂时没有, 开发人员之间务必做好相互协同.