> For the complete documentation index, see [llms.txt](https://coolpy7.gitbook.io/coolpy7book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coolpy7.gitbook.io/coolpy7book/kai-shi-shi-yong/mqttsn-dai-li-fu-wu.md).

# MQTT-SN代理服务

![Coolpy7 MQTT-SN技术流概览](/files/-LSbmlXPnzVsldnflPVM)

### 适用场境

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智能客户端直联模式

![](/files/-LSc_l3bCE9rzbeQ1g3l)

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

开源地址：<https://github.com/Coolpy7/mqttsn-sdk/tree/master/Coolpy7SmartClient>

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

![](/files/-LScdIhbofPcBtwa-Vvx)

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

Lora网关开源地址：<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>
