在订阅之后再连接mqtt

This commit is contained in:
2025-03-01 15:05:53 +08:00
parent 53d9df6e0a
commit 6d52ddb572
2 changed files with 11 additions and 14 deletions

View File

@@ -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()

View File

@@ -60,11 +60,8 @@ url: `server/wushan/5/play`
"bgm": "file://./青云龙台.mp3",
"power": true,
"volume":1,
"tts": {
"start": "刘佳勇者,恭喜你成功通关!"
},
"game": {
"wait": 10
"wait": 36
}
}
```