YHGW/main.go

77 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"github.com/robfig/cron"
"log"
"net"
"os"
"strconv"
)
var err error
func main() {
go gw_router()
go serial_run()
c := cron.New()
// send_data(CODE1001)
//获取数据防抖处理时间配置
go getConf()
// c.AddFunc("0, *, *, *, *, *", func() {
// send_data(CODE1001)
// })
//一分钟一次 同步数据
c.AddFunc("0, *, *, *, *, *", func() {
yunhorn_hb_dpark_v1()
})
c.AddFunc("*/10, *, *, *, *, *", func() {
// devices := []Device{}
// log.Println(string(build_data(1001,devices)))
})
c.AddFunc("*/30, *, *, *, *, *", func() {
getConf()
})
c.AddFunc("0, */10, *, *, *, *", savedata_cron)
c.AddFunc("0, 0, 0, *, *, *", insertdata)
c.AddFunc("0, 0, *, *, *, *", get_weather)
c.Start()
tcp_port := strconv.Itoa(conf.TCPPORT)
listener, err := net.Listen("tcp", "0.0.0.0:"+tcp_port)
if err != nil {
log.Printf("listen fail, err: %v\n", err)
return
}
if conf.OPENTCPSETVER {
for {
conn, err := listener.Accept()
if err != nil {
log.Printf("accept fail, err: %v\n", err)
continue
}
// go process(conn)
go handleConn(conn)
}
} else {
//如果不启动tcpserver则需要执行这里 让程序不退出
select {}
}
}
func check(err error) {
if err != nil {
log.Println(err)
os.Exit(1)
}
}