YHGW/main.go

62 lines
1019 B
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"
)
var err error
func main() {
go gw_router()
go serial_run()
c := cron.New()
send_data(1001)
c.AddFunc("0, *, *, *, *, *", func() {
send_data(1001)
})
c.AddFunc("*/10, *, *, *, *, *", func() {
// devices := []Device{}
// log.Println(string(build_data(1001,devices)))
})
c.AddFunc("0, */10, *, *, *, *", savedata_cron)
c.AddFunc("0, 0, 0, *, *, *", insertdata)
c.AddFunc("0, 0, *, *, *, *", get_weather)
c.Start()
listener, err := net.Listen("tcp", "0.0.0.0:10090")
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)
}
}