---
description: >-
  MQTT-SN是作为一种MQTT适应Lora或其他443本地无线通信技术方案的补充协议，基于UDP与MQTT主Borker连接，节点代理网关接收Lora无线终端信息后通过UDP中转给MQTT主Borker
---

# MQTT-SN代理服务

![Coolpy7 MQTT-SN技术流概览](https://33059891-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LPz4APWKTuf0FRQG1lh%2F-LScAdcUxRx1ipVJ1cEz%2F-LSbmlXPnzVsldnflPVM%2FCoolpy7%20\(1\).jpg?alt=media\&token=9d7c0965-f74d-4a94-8bb5-dbd5a01a1ecd)

### 适用场境

1. 工业物联网
2. 农业物联网
3. 本地组建无线物联网络

### 开始运行

```
# 下载服务器端
$ git clone https://github.com/Coolpy7/mqttsn-gateway.git && cd mqttsn-gateway

# data/mqttsn.yml配置文件
$ vim data/mqttsn.yml

# 使用聚合管道模式
IsAggregate: true 
# 代理服务宿主ip
Host: 0.0.0.0
# 代理服务端口 
Port: 1884 
# Coolpy7 Broker所在ip
BrokerHost: "192.168.200.238"
# Coolpy7 Broker 端口
BrokerPort: 1883
# 登陆Coolpy7如开启身份验证需填以下两项
BrokerUser:
BrokerPassword:
# 日志文件名字
LogFilePath: mqttsn.log
# 消息队列最大值
MessageQueueSize: 1000
# 网络流限制
ReadBuffSize: 212992
WriteBuffSize: 212992

# 提权
chmod -R 777 go_build_Coolpy7_sngw_go_linux_linux
# 启动Coolpy7 mqtt-sn gateway
./go_build_Coolpy7_sngw_go_linux_linux

# 启动成功后大概会显示如下信息即启动成功
2018/12/01 11:36:10 aggregating_gw_impl.go:33: Connect to broker
2018/12/01 11:36:10 gateway.go:59: set read buff size :  212992
2018/12/01 11:36:10 gateway.go:65: set write buff size :  212992
```

### 测试SDK

#### Coolpy7 Mqtt-sn Smart Client智能客户端直联模式

![](https://33059891-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LPz4APWKTuf0FRQG1lh%2F-LScHgQa4g-XdOjzSZ09%2F-LSc_l3bCE9rzbeQ1g3l%2FCoolpy7%20\(3\).jpg?alt=media\&token=3bf26db8-b373-4732-8f6f-06428e65a970)

此客户端示例使用NodeMcu(Esp8266)作为终端实现自动连接到网关然后与Coolpy7实现通信链路

开源地址：[https://github.com/Coolpy7/mqttsn-sdk/tree/master/Coolpy7SmartClient](https://github.com/Coolpy7/mqttsn-sdk/tree/master/Coolpy7SmartClient)

#### Coolpy7 Mqtt-sn Gateway Smart Client智能客户端网关中转模式

![](https://33059891-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LPz4APWKTuf0FRQG1lh%2F-LScHgQa4g-XdOjzSZ09%2F-LScdIhbofPcBtwa-Vvx%2FCoolpy7%20\(5\).jpg?alt=media\&token=4b577c14-3870-40ea-b63b-df37e77b94e0)

此示例使用NodeMcu(Esp8266)作为Lora网关中转消息连接到Coolpy7 MQTT-SN Gateway代理服务，终端设备使用Lora(433)无线通信与网关通信后与Coolpy7实现通信链路

Lora网关开源地址：[https://github.com/Coolpy7/mqttsn-sdk/blob/master/Coolpy7SnGateway/Coolpy7SnGateway.ino](https://github.com/Coolpy7/mqttsn-sdk/blob/master/Coolpy7SnGateway/Coolpy7SnGateway.ino)

Smart Client Lora终端开源地址：[https://github.com/Coolpy7/mqttsn-sdk/tree/master/Coolpy7SnGateway/Coolpy7SN-TTL-zigbee-xbee-client](https://github.com/Coolpy7/mqttsn-sdk/tree/master/Coolpy7SnGateway/Coolpy7SN-TTL-zigbee-xbee-client)
