前三个点位所有功能已调通
This commit is contained in:
@@ -28,6 +28,7 @@ func buildMqtt(c config.MqttConfig, r *leaf.Engine, subTopics ...string) autopah
|
||||
|
||||
subscriptions := make([]paho.SubscribeOptions, 0)
|
||||
for _, topic := range subTopics {
|
||||
log.Println("订阅主题: ", topic)
|
||||
subscriptions = append(subscriptions, paho.SubscribeOptions{Topic: topic, QoS: 0})
|
||||
}
|
||||
|
||||
@@ -75,15 +76,13 @@ func Run() {
|
||||
topicPrefix := fmt.Sprintf("server/%s/%v/", config.C.Location, config.C.Point)
|
||||
publishTopic := fmt.Sprintf("device/%s/%v/status", config.C.Location, config.C.Point)
|
||||
|
||||
log.Println("topicPrefix: ", topicPrefix)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
router := leaf.Default(ctx)
|
||||
|
||||
router.DefaultHandler(func(c *leaf.Context) {
|
||||
log.Println("接收到未处理消息: " + string(c.Payload))
|
||||
log.Printf("未处理消息 topic: %s\n payload: %s\n", c.Topic, c.Payload)
|
||||
})
|
||||
|
||||
// 构建 MQTT 连接
|
||||
@@ -114,6 +113,7 @@ func Run() {
|
||||
|
||||
// 处理启动报文
|
||||
router.RegisterHandler(topicPrefix+"play",
|
||||
middleware.RunLog(),
|
||||
middleware.PayloadJSON[schema.PlayModal](),
|
||||
middleware.DeviceLock(device),
|
||||
middleware.EmergencyStop(common.GlobalStopper),
|
||||
@@ -122,22 +122,20 @@ func Run() {
|
||||
middleware.TimeoutOver(config.C.Game.MaxTimeout),
|
||||
middleware.TickerAction(),
|
||||
middleware.PlayBgm(),
|
||||
func(c *leaf.Context) {
|
||||
log.Println("接收到启动消息: ", string(c.Payload))
|
||||
select {
|
||||
case <-c.Done():
|
||||
log.Println("执行结束")
|
||||
}
|
||||
},
|
||||
routes.PlayRouter(config.C.Location, config.C.Point),
|
||||
)
|
||||
// 处理待机线程报文
|
||||
router.RegisterHandler(topicPrefix+"wait",
|
||||
middleware.RunLog(),
|
||||
middleware.PayloadJSON[schema.WaitModel](),
|
||||
middleware.EmergencyStop(common.GlobalBgStopper),
|
||||
routes.WaitAction,
|
||||
)
|
||||
// 处理指令
|
||||
router.RegisterHandler(topicPrefix+"command", routes.Command(device))
|
||||
router.RegisterHandler(topicPrefix+"command",
|
||||
middleware.RunLog(),
|
||||
routes.Command(device),
|
||||
)
|
||||
|
||||
// 启动完成发送一次设备状态
|
||||
device.PublishStatus()
|
||||
@@ -150,8 +148,8 @@ func Run() {
|
||||
|
||||
ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
if err := cm.Disconnect(ctx); err != nil {
|
||||
fmt.Printf("断开连接异常: %s\n", err)
|
||||
if e := cm.Disconnect(ctx); e != nil {
|
||||
fmt.Printf("断开连接异常: %s\n", e)
|
||||
}
|
||||
|
||||
fmt.Println("关闭完成")
|
||||
|
||||
Reference in New Issue
Block a user