1 环境依赖

1.1 EMQX

版本:4.4.3

文档https://www.emqx.io/docs/zh/v4.4/

认证:启用auth_http

1.2 IoTServer

环境:支持Windows 、Linux

依赖:.netcore Runtime 6.0+

下载地址: https://dotnet.microsoft.com/zh-cn/download/dotnet/6.0

1.3 IoTWeb

环境:支持Windows、Linux

依赖:.netcore runtime 6.0+

下载地址https://dotnet.microsoft.com/zh-cn/download/dotnet/6.0

1.4 客户端

环境:支持Windows7以上、ios、android

分辨率:推荐1366*768 及以上

浏览器:建议使用chrome浏览器

下载地址https://www.google.cn/intl/zh-CN/chrome/

1.5 MQTT客户端

NewLife.Mqtt

2 EMQX

2.1 Auth_http配置

以docker emq镜像为例

  • docker ps 查看镜像进程

  • docker exec -it emqx bash 进入emqx镜像

  • cd /opt/emqx/etc/plugins 进入配置文件存在路径

  • 编辑 emqx_auth_http.cnf 认证文件(参考:官网方文档 /认证/http认证)

注:auth.http.auth_req.url = IotServer部署地址 + 端口

  • 进入管理后台

启用http认证插件 Plugins - emqx_auth_http - start(图1),成功启动(图2)

图1

图2

3 客户端

3.1 Http认证

参数说明

参数名称

格式

备注

ClientId

$"{ProductKey}|{DeviceCode}|{ip}|{mi.UUID}"

认证客户端编号

UserName

$"{DeviceCode}|{DateTime.UtcNow.ToLong()}"

认证用户名

Password

Hash(Secret)

认证密码Md5散列

3.2 心跳

3.2.1 Topic

$"sys/{ProductKey}/{DeviceCode}/thing/event/ping/post"

3.2.2 数据报文

名称

类型

备注

AvailableMemory

ulong

可用内存大小

AvailableFreeSpace

ulong

磁盘可用空间。应用所在盘

CpuRate

float

主频

Temperature

double

温度

Battery

double

电量

UplinkSpeed

ulong

上行速度。网络发送速度,字节每秒

DownlinkSpeed

ulong

下行速度。网络接收速度,字节每秒

Macs

string

MAC地址

IP

string

本地IP地址。随着网卡变动,可能改变

Processes

string

进程列表

ProcessCount

int

进程个数

TcpConnections

int

正在传输的Tcp连接数

TcpTimeWait

int

主动关闭的Tcp连接数

TcpCloseWait

int

被动关闭的Tcp连接数

Uptime

int

开机时间,单位s

Time

long

本地UTC时间。ms毫秒

Delay

int

延迟

3.3 属性上报

3.3.1 Topic

$"sys/{ProductKey}/{DeviceCode}/thing/property/post"

3.3.2 数据报文

名称

类型

备注

DeviceCode

String

设备编号

Items

Object[]

数据集合

Time

long

采集时间戳(UTC)

Name

String

属性名称

Value

String

属性值



3.4 指令接收(暂时未实现)

3.4.1 Topic

Topic

备注

$"sys/{ProductKey}/{DeviceCode}/thing/event/ping/post_reply"

心跳回复

$"sys/{ProductKey}/{DeviceCode}/thing/property/post_reply"

属性回复

$"sys/{ProductKey}/{DeviceCode}/thing/service/property/set"

属性设置

$"device/{ProductKey}/{DeviceCode}/upgrade"

升级


4 服务端

4.1 MQTT服务器配置

默认访问地址:部署服务器:1880


作者:郗 发布:2022-06-07 23:56:16 浏览:3,566)