增加待机报文缓存,无网状态也能执行待机任务;投影仪指令结果以设备状态为准
This commit is contained in:
@@ -13,9 +13,6 @@ import (
|
||||
"game-driver/pkg/relay"
|
||||
"game-driver/pkg/tts"
|
||||
"game-driver/pkg/utils"
|
||||
"github.com/eclipse/paho.golang/autopaho"
|
||||
"github.com/eclipse/paho.golang/paho"
|
||||
"go.uber.org/zap"
|
||||
"log"
|
||||
"net"
|
||||
"net/url"
|
||||
@@ -23,6 +20,10 @@ import (
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/eclipse/paho.golang/autopaho"
|
||||
"github.com/eclipse/paho.golang/paho"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func buildMqtt(c config.MqttConfig, r *leaf.Engine, subTopics ...string) autopaho.ClientConfig {
|
||||
@@ -153,9 +154,10 @@ func Run() {
|
||||
router.RegisterHandler(topicPrefix+"wait",
|
||||
middleware.RunLog(),
|
||||
middleware.PayloadJSON[schema.WaitModel](),
|
||||
middleware.Cache(config.C.StandbyCache),
|
||||
middleware.Unique(common.GlobalBgStopper),
|
||||
middleware.EmergencyStop(common.GlobalBgStopper),
|
||||
routes.WaitAction(common.PassCtrl, device),
|
||||
routes.StandbyAction(common.PassCtrl, device),
|
||||
)
|
||||
// 处理指令
|
||||
router.RegisterHandler(topicPrefix+"command",
|
||||
@@ -163,13 +165,21 @@ func Run() {
|
||||
routes.Command(device),
|
||||
)
|
||||
|
||||
// 从缓存中读取待机报文,如果存在则直接执行
|
||||
publish, err := config.C.StandbyCache.Get()
|
||||
if err != nil {
|
||||
zap.S().Infoln("读取待机缓存失败: ", err)
|
||||
} else {
|
||||
router.HandlerRun(topicPrefix+"wait", publish)
|
||||
}
|
||||
|
||||
// 构建 MQTT 连接
|
||||
mqttBuild := buildMqtt(config.C.Mqtt, router, topicPrefix+"#")
|
||||
|
||||
// 连接 MQTT
|
||||
// 开始连接 MQTT
|
||||
cm, err := autopaho.NewConnection(ctx, mqttBuild)
|
||||
if err != nil {
|
||||
zap.S().Panicln("连接 MQTT 异常: ", err)
|
||||
zap.S().Panicln("创建 MQTT 连接器异常: ", err)
|
||||
}
|
||||
utils.GlobalMqttClient = cm
|
||||
|
||||
|
||||
Reference in New Issue
Block a user