在订阅之后再连接mqtt
This commit is contained in:
@@ -108,16 +108,6 @@ func Run() {
|
||||
zap.S().Infof("未处理消息,topic: %s\n payload: %s\n", c.Topic, c.Payload)
|
||||
})
|
||||
|
||||
// 构建 MQTT 连接
|
||||
mqttBuild := buildMqtt(config.C.Mqtt, router, topicPrefix+"#")
|
||||
|
||||
// 连接 MQTT
|
||||
cm, err := autopaho.NewConnection(ctx, mqttBuild)
|
||||
if err != nil {
|
||||
zap.S().Panicln("连接 MQTT 异常: ", err)
|
||||
}
|
||||
utils.GlobalMqttClient = cm
|
||||
|
||||
// 构建语音合成对象
|
||||
tts.DefaultTTS = tts.New(ctx, config.C.Aliyun)
|
||||
|
||||
@@ -165,6 +155,16 @@ func Run() {
|
||||
routes.Command(device),
|
||||
)
|
||||
|
||||
// 构建 MQTT 连接
|
||||
mqttBuild := buildMqtt(config.C.Mqtt, router, topicPrefix+"#")
|
||||
|
||||
// 连接 MQTT
|
||||
cm, err := autopaho.NewConnection(ctx, mqttBuild)
|
||||
if err != nil {
|
||||
zap.S().Panicln("连接 MQTT 异常: ", err)
|
||||
}
|
||||
utils.GlobalMqttClient = cm
|
||||
|
||||
// 启动完成发送一次设备状态
|
||||
device.PublishStatus()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user