完善本地web数据

This commit is contained in:
fish 2019-03-28 11:46:23 +08:00
parent 2446847ae9
commit 41d2d2d3ee
4 changed files with 55 additions and 46 deletions

View File

@ -75,6 +75,8 @@ var conf Conf
var DEVICEDATAS Devicedatas var DEVICEDATAS Devicedatas
var demoDevice Device var demoDevice Device
var airDevice Device
var db, _ = sql.Open("sqlite3", "./db/gateway.db") var db, _ = sql.Open("sqlite3", "./db/gateway.db")
// 加载配置文件 // 加载配置文件
@ -114,6 +116,9 @@ func init() {
demoDevice.ONLINE = true demoDevice.ONLINE = true
log.Println("init demoDevice success:", demoDevice) log.Println("init demoDevice success:", demoDevice)
airDevice.DATA = make(map[string]interface{})
airDevice.DATA["data"]=0
dbdata_init() dbdata_init()
} }

View File

@ -10,10 +10,12 @@ import (
var err error var err error
func main() { func main() {
go gw_router() go gw_router()
go serial_run() go serial_run()
c := cron.New() c := cron.New()
send_data(1001) send_data(1001)
c.AddFunc("0, *, *, *, *, *", func() { c.AddFunc("0, *, *, *, *, *", func() {
send_data(1001) send_data(1001)
}) })

3
mq.go
View File

@ -1,3 +1,6 @@
package main package main
func init() {
//var data []byte = []byte{0x01,0x01,0x01,0x00}
}

View File

@ -43,11 +43,9 @@ func yunhorn_wireless(data_buf []byte){
// log.Println("adrh:%d,adrl:%d,conf.adrh:%d,conf.adrl:%d",int(adrh),int(adrl),item.ADRH,item.ADRL) // log.Println("adrh:%d,adrl:%d,conf.adrh:%d,conf.adrl:%d",int(adrh),int(adrl),item.ADRH,item.ADRL)
if int(adrh) != item.ADRH || int(adrl) != item.ADRL { if int(adrh) != item.ADRH || int(adrl) != item.ADRL {
continue; continue
} }
if item.FLIP { if item.FLIP {
if data == 0 { if data == 0 {
data = 1 data = 1
@ -142,7 +140,7 @@ func yunhorn_ys_l_v1(data_buf []byte) {
demoDevice.DATA["data"+strconv.Itoa(2)] = 0 demoDevice.DATA["data"+strconv.Itoa(2)] = 0
demoDevice.DATA["data"+strconv.Itoa(3)] = 0 demoDevice.DATA["data"+strconv.Itoa(3)] = 0
if data_int0[0]==0 && data_int1[0]==0 { if data_int0[0] == 0 && data_int1[0] == 0 && data_type[0] == 0 {
demoDevice.DATA["data"+strconv.Itoa(8)] = data_int[0] demoDevice.DATA["data"+strconv.Itoa(8)] = data_int[0]
var device Device var device Device
device.Lock() device.Lock()
@ -225,6 +223,7 @@ func yunhorn_kgl_l_v1(data_buf []byte) {
// 采集并解析水表数据 // 采集并解析水表数据
func yunhorn_sb_c_v1(s *serial.Port, device_id string, command [][]byte, num string) { func yunhorn_sb_c_v1(s *serial.Port, device_id string, command [][]byte, num string) {
_, err = s.Write([]byte(command[0])) _, err = s.Write([]byte(command[0]))
check(err) check(err)
if conf.DEBUG { if conf.DEBUG {