完善配置,添加是否启动tcpserver配置项

This commit is contained in:
fish 2019-03-28 11:50:56 +08:00
parent 41d2d2d3ee
commit d82e284bb7
3 changed files with 30 additions and 22 deletions

View File

@ -210,5 +210,6 @@
"websocketurl": ["192.168.3.216:8080", "/echo"], "websocketurl": ["192.168.3.216:8080", "/echo"],
"post_to_server": "https://smartoilets.cn/socketServer/statis/push", "post_to_server": "https://smartoilets.cn/socketServer/statis/push",
"debug": true, "debug": true,
"openserial":false "openserial":false,
"open_tcp_server":false
} }

View File

@ -27,8 +27,12 @@ type Conf struct {
WEBSOCKETURL []string `json:"websocketurl"` WEBSOCKETURL []string `json:"websocketurl"`
POST_TO_SERVER string `json:"post_to_server"` POST_TO_SERVER string `json:"post_to_server"`
DEBUG bool `json:"debug"` DEBUG bool `json:"debug"`
//是否初始化时打开串口
OPENSERIAL bool `json:"openserial"` OPENSERIAL bool `json:"openserial"`
//无线 设备
WIRELESSSLAVEDEVICES []WirelessSlaveDevice `json:"wireless_slave_devices"` WIRELESSSLAVEDEVICES []WirelessSlaveDevice `json:"wireless_slave_devices"`
//是否启动tcpserver
OPENTCPSETVER bool `json:"open_tcp_server"`
} }
//无线 下位机 //无线 下位机
@ -117,7 +121,7 @@ func init() {
log.Println("init demoDevice success:", demoDevice) log.Println("init demoDevice success:", demoDevice)
airDevice.DATA = make(map[string]interface{}) airDevice.DATA = make(map[string]interface{})
airDevice.DATA["data"]=0 airDevice.DATA["data"] = 0
dbdata_init() dbdata_init()

View File

@ -36,6 +36,7 @@ func main() {
return return
} }
if conf.OPENTCPSETVER {
for { for {
conn, err := listener.Accept() conn, err := listener.Accept()
if err != nil { if err != nil {
@ -45,8 +46,10 @@ func main() {
// go process(conn) // go process(conn)
go handleConn(conn) go handleConn(conn)
} }
} else {
// select {} //如果不启动tcpserver则需要执行这里 让程序不退出
select {}
}
} }