task.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package util
  2. import (
  3. "github.com/robfig/cron"
  4. )
  5. var commandQueue = make(chan []byte, 5)
  6. func TimeTasks() {
  7. c := cron.New()
  8. //每3分钟监测状态
  9. //_ = c.AddFunc("0 0/5 * * * ? ", func() {
  10. _ = c.AddFunc("0/5 * * * * ?", func() {
  11. //for _, dev := range config.DevConfig.LampDevs {
  12. // pack := lampControl.DataPack{Addr: dev.Address, Data: []byte{0x01}}
  13. // command := pack.GetLampTurnOnOffCommand()
  14. // //dataPack := lampControl.DataPack{Addr: dev.Address}
  15. // //command := dataPack.GetLampSetBrightCommand(10)
  16. // fmt.Println("命令:", hex.EncodeToString(command.Bytes()))
  17. // port, err := GetSerialPort(dev.SerialId)
  18. // if err != nil {
  19. // logger.Logger.Infof(err.Error())
  20. // continue
  21. // }
  22. // write, err := port.Write(command.Bytes())
  23. // fmt.Println("write.....,", write)
  24. // if err != nil {
  25. // fmt.Println(err.Error())
  26. // }
  27. //}
  28. //data := EnvData{Temperature: float64(98) / 10.0, Humidity: float64(345) / 10.0, Illuminance: 666}
  29. //
  30. //jsonData, _ := json.Marshal(data)
  31. //topic := mqtt.MqttService.GetTopic(mqtt.TopicGatherDataEnv)
  32. //err := mqtt.MqttService.Publish(topic, jsonData)
  33. //if err != nil {
  34. // logger.Logger.Errorf("MQTT Publish err = %s", err.Error())
  35. //}
  36. //parseTopic, s, _ := mqtt.ParseTopic("smart_tunnel/xyzSuiDao/gatherDataEnv")
  37. //fmt.Println("====", parseTopic)
  38. //fmt.Println("====", s)
  39. //
  40. //fmt.Println("主题:", topic)
  41. //fmt.Println("实时更新。。。", config.Instance().Policy.StartTime)
  42. //fmt.Println("实时更新。。。", config.Instance().Mqtt.Server)
  43. //config.ReloadConfig()
  44. //fmt.Println(config.Instance().Policy.Id == 2)
  45. //fmt.Println(config.Instance().Policy.Control == "regulateSwitch")
  46. })
  47. c.Start()
  48. }