12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- package util
- import (
- "github.com/robfig/cron"
- )
- var commandQueue = make(chan []byte, 5)
- func TimeTasks() {
- c := cron.New()
- //每3分钟监测状态
- //_ = c.AddFunc("0 0/5 * * * ? ", func() {
- _ = c.AddFunc("0/5 * * * * ?", func() {
- //for _, dev := range config.DevConfig.LampDevs {
- // pack := lampControl.DataPack{Addr: dev.Address, Data: []byte{0x01}}
- // command := pack.GetLampTurnOnOffCommand()
- // //dataPack := lampControl.DataPack{Addr: dev.Address}
- // //command := dataPack.GetLampSetBrightCommand(10)
- // fmt.Println("命令:", hex.EncodeToString(command.Bytes()))
- // port, err := GetSerialPort(dev.SerialId)
- // if err != nil {
- // logger.Logger.Infof(err.Error())
- // continue
- // }
- // write, err := port.Write(command.Bytes())
- // fmt.Println("write.....,", write)
- // if err != nil {
- // fmt.Println(err.Error())
- // }
- //}
- //data := EnvData{Temperature: float64(98) / 10.0, Humidity: float64(345) / 10.0, Illuminance: 666}
- //
- //jsonData, _ := json.Marshal(data)
- //topic := mqtt.MqttService.GetTopic(mqtt.TopicGatherDataEnv)
- //err := mqtt.MqttService.Publish(topic, jsonData)
- //if err != nil {
- // logger.Logger.Errorf("MQTT Publish err = %s", err.Error())
- //}
- //parseTopic, s, _ := mqtt.ParseTopic("smart_tunnel/xyzSuiDao/gatherDataEnv")
- //fmt.Println("====", parseTopic)
- //fmt.Println("====", s)
- //
- //fmt.Println("主题:", topic)
- //fmt.Println("实时更新。。。", config.Instance().Policy.StartTime)
- //fmt.Println("实时更新。。。", config.Instance().Mqtt.Server)
- //config.ReloadConfig()
- //fmt.Println(config.Instance().Policy.Id == 2)
- //fmt.Println(config.Instance().Policy.Control == "regulateSwitch")
- })
- c.Start()
- }
|