update and add static file
This commit is contained in:
parent
b11f72bc54
commit
e19355ed9a
|
@ -55,10 +55,10 @@ lora_nodes:
|
|||
- {"adr":"0c073f18",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c0c1d18",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c3b1518",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c4c4c17",location_type":"","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c2d1319",location_type":"","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
|
||||
#吸顶
|
||||
- {"adr":"0c4b5a17",location_type":"","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"f6400000",location_type":"","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
|
||||
#门磁
|
||||
- {"adr":"0c255d17",location_type":"","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
|
@ -132,4 +132,4 @@ mqtt_username: "dpark"
|
|||
mqtt_password: "Jev@nwd0409"
|
||||
|
||||
|
||||
#2019/08/16 06:50:00 Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub
|
||||
#2019/08/16 06:50:00 Binary was compiled with 'CGO_ENABLED=0', go-sqlite3 requires cgo to work. This is a stub
|
||||
|
|
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module yunhorn_gateway
|
|||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/eclipse/paho.mqtt.golang v1.2.0 // indirect
|
||||
github.com/eclipse/paho.mqtt.golang v1.2.0
|
||||
github.com/gin-contrib/cors v1.3.0
|
||||
github.com/gin-gonic/gin v1.4.0
|
||||
github.com/mattn/go-sqlite3 v1.11.0
|
||||
|
|
|
@ -3,19 +3,20 @@ package main
|
|||
import (
|
||||
"database/sql"
|
||||
// "encoding/json"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
|
||||
// "strconv"
|
||||
"time"
|
||||
"sync"
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/yaml"
|
||||
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
|
||||
)
|
||||
|
||||
type Traffic struct {
|
||||
|
@ -40,23 +41,23 @@ type Conf struct {
|
|||
//无线 设备
|
||||
WIRELESSSLAVEDEVICES []WirelessSlaveDevice `json:"wireless_slave_devices"`
|
||||
//是否启动tcpserver
|
||||
OPENTCPSETVER bool `json:"open_tcp_server"`
|
||||
CHECKSERIAL bool `json:"check_serial"`
|
||||
LORANODES []LoraNode `json:"lora_nodes"`
|
||||
DPARKLOCATION string `json:"dpark_location"`
|
||||
TCPPORT int `json:"tcp_port"`
|
||||
APIPORT int `json:"api_port"`
|
||||
PROCATEGORY int `json:"pro_category"`
|
||||
SYNDATA bool `json:"syn_data"`
|
||||
SYNEXTENSIONTIME bool `json:"syn_extension_Time"`
|
||||
RECORD_LOG_PATH string `json:"record_log_path"`
|
||||
MQTT_OPEN bool `json:"mqtt_open"`
|
||||
MQTT_BROKER string `json:"mqtt_broker"`
|
||||
MQTT_USERNAME string `json:"mqtt_username"`
|
||||
MQTT_PASSWORD string `json:"mqtt_password"`
|
||||
MQTT_KEEPALIVE int `json:"mqtt_keepAlive"`
|
||||
MQTT_TOPIC string `json:"mqtt_topic"`
|
||||
MQTT_TIMEOUT int `json:"mqtt_timeout"`
|
||||
OPENTCPSETVER bool `json:"open_tcp_server"`
|
||||
CHECKSERIAL bool `json:"check_serial"`
|
||||
LORANODES []LoraNode `json:"lora_nodes"`
|
||||
DPARKLOCATION string `json:"dpark_location"`
|
||||
TCPPORT int `json:"tcp_port"`
|
||||
APIPORT int `json:"api_port"`
|
||||
PROCATEGORY int `json:"pro_category"`
|
||||
SYNDATA bool `json:"syn_data"`
|
||||
SYNEXTENSIONTIME bool `json:"syn_extension_Time"`
|
||||
RECORD_LOG_PATH string `json:"record_log_path"`
|
||||
MQTT_OPEN bool `json:"mqtt_open"`
|
||||
MQTT_BROKER string `json:"mqtt_broker"`
|
||||
MQTT_USERNAME string `json:"mqtt_username"`
|
||||
MQTT_PASSWORD string `json:"mqtt_password"`
|
||||
MQTT_KEEPALIVE int `json:"mqtt_keepAlive"`
|
||||
MQTT_TOPIC string `json:"mqtt_topic"`
|
||||
MQTT_TIMEOUT int `json:"mqtt_timeout"`
|
||||
}
|
||||
|
||||
//无线 下位机
|
||||
|
@ -99,17 +100,17 @@ type Serialconf struct {
|
|||
NOTE string `json:"note"`
|
||||
}
|
||||
|
||||
type LoraNode struct{
|
||||
ADR string `json:"adr"`
|
||||
LOCATION_TYPE string `json:"location_type"`
|
||||
LOCATION_CODE string `json:"location_code"`
|
||||
LOCATION_DATA string `json:"location_data"`
|
||||
TIME time.Time `json:"time"`
|
||||
CURRENT_DATA int `json:"current_data"`
|
||||
CHECK_TIME bool `json:"check_time"`
|
||||
DEVICE string `json:"device"`
|
||||
UPDATE_TIME time.Time `json:"update_time"`
|
||||
LORA_GWS []string `json:"lora_gws"`
|
||||
type LoraNode struct {
|
||||
ADR string `json:"adr"`
|
||||
LOCATION_TYPE string `json:"location_type"`
|
||||
LOCATION_CODE string `json:"location_code"`
|
||||
LOCATION_DATA string `json:"location_data"`
|
||||
TIME time.Time `json:"time"`
|
||||
CURRENT_DATA int `json:"current_data"`
|
||||
CHECK_TIME bool `json:"check_time"`
|
||||
DEVICE string `json:"device"`
|
||||
UPDATE_TIME time.Time `json:"update_time"`
|
||||
LORA_GWS []string `json:"lora_gws"`
|
||||
}
|
||||
|
||||
var conf Conf
|
||||
|
@ -136,7 +137,6 @@ var loraNodeMap sync.Map
|
|||
|
||||
var db, _ = sql.Open("sqlite3", "./db/gateway.db")
|
||||
|
||||
|
||||
type pluginConfig struct {
|
||||
PodNodeSelectorPluginConfig map[string]string
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ func init() {
|
|||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
t := time.Now()
|
||||
today = t.Format("2006-01-02")
|
||||
today = t.Format("2006-01-02")
|
||||
|
||||
// configfile, err := os.Open("conf/gateway.conf")
|
||||
// check(err)
|
||||
|
@ -160,17 +160,17 @@ func init() {
|
|||
configfile, err := os.Open("conf/gateway.yaml")
|
||||
check(err)
|
||||
defer configfile.Close()
|
||||
configData,err := ioutil.ReadAll(configfile)
|
||||
configData, err := ioutil.ReadAll(configfile)
|
||||
check(err)
|
||||
|
||||
reader := bytes.NewReader(configData)
|
||||
// ext := runtime.RawExtension{}
|
||||
d := yaml.NewYAMLOrJSONDecoder(reader, 4096)
|
||||
|
||||
|
||||
// defaultConfig := &pluginConfig{}
|
||||
|
||||
// if err := d.Decode(&defaultConfig); err != nil {
|
||||
// check(err)
|
||||
// check(err)
|
||||
// }
|
||||
|
||||
// log.Println("======================yaml.data:",defaultConfig)
|
||||
|
@ -185,10 +185,10 @@ func init() {
|
|||
|
||||
log.Println("slaveDevices:", conf.WIRELESSSLAVEDEVICES)
|
||||
|
||||
for _,v := range conf.LORANODES {
|
||||
v.CURRENT_DATA = -1
|
||||
v.TIME = time.Now()
|
||||
loraNodeMap.Store(v.ADR,v)
|
||||
for _, v := range conf.LORANODES {
|
||||
v.CURRENT_DATA = -1
|
||||
v.TIME = time.Now()
|
||||
loraNodeMap.Store(v.ADR, v)
|
||||
}
|
||||
|
||||
DEVICEDATAS.Lock()
|
||||
|
|
19
main.go
19
main.go
|
@ -1,12 +1,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/robfig/cron"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/robfig/cron"
|
||||
)
|
||||
|
||||
var err error
|
||||
|
@ -75,7 +76,7 @@ func main() {
|
|||
go gw_router()
|
||||
go serial_run()
|
||||
c := cron.New()
|
||||
|
||||
|
||||
//获取数据防抖处理时间配置
|
||||
if conf.SYNEXTENSIONTIME {
|
||||
go getConf()
|
||||
|
@ -85,20 +86,20 @@ func main() {
|
|||
go send_data(CODE1001)
|
||||
}
|
||||
|
||||
//一分钟一次 同步数据
|
||||
//一分钟一次 同步数据
|
||||
c.AddFunc("0, *, *, *, *, *", func() {
|
||||
if conf.SYNDATA {
|
||||
if conf.PROCATEGORY == PRO_CATEGORY_WIRED {
|
||||
send_data(CODE1001)
|
||||
}else if conf.PROCATEGORY == PRO_CATEGORY_WIRELESS{
|
||||
} else if conf.PROCATEGORY == PRO_CATEGORY_WIRELESS {
|
||||
yunhorn_hb_dpark_v1()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// c.AddFunc("*/10, *, *, *, *, *", func() {
|
||||
// devices := []Device{}
|
||||
// log.Println(string(build_data(1001,devices)))
|
||||
// devices := []Device{}
|
||||
// log.Println(string(build_data(1001,devices)))
|
||||
// })
|
||||
|
||||
c.AddFunc("*/30, *, *, *, *, *", func() {
|
||||
|
@ -112,9 +113,9 @@ func main() {
|
|||
c.AddFunc("0, 0, 0, *, *, *", insertdata)
|
||||
c.AddFunc("0, 0, *, *, *, *", get_weather)
|
||||
//定时更新today字段,当前日期
|
||||
c.AddFunc("0, *, *, *, *, *", func(){
|
||||
c.AddFunc("0, *, *, *, *, *", func() {
|
||||
t := time.Now()
|
||||
today = t.Format("2006-01-02")
|
||||
today = t.Format("2006-01-02")
|
||||
})
|
||||
c.Start()
|
||||
|
||||
|
@ -132,7 +133,7 @@ func main() {
|
|||
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
loragwMap.Store(conn.RemoteAddr().String(),conn)
|
||||
loragwMap.Store(conn.RemoteAddr().String(), conn)
|
||||
if err != nil {
|
||||
log.Printf("accept fail, err: %v\n", err)
|
||||
continue
|
||||
|
|
412
router.go
412
router.go
|
@ -1,19 +1,20 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
"bytes"
|
||||
"net"
|
||||
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
var router = gin.Default()
|
||||
|
@ -36,7 +37,7 @@ func gw_router() {
|
|||
v1.POST("/push", push)
|
||||
|
||||
v1.GET("/getConf")
|
||||
v1.GET("/writeCommand",writeCommand)
|
||||
v1.GET("/writeCommand", writeCommand)
|
||||
}
|
||||
|
||||
router.LoadHTMLGlob("static/*")
|
||||
|
@ -44,85 +45,85 @@ func gw_router() {
|
|||
opsV1 := router.Group("/ops/v1")
|
||||
{
|
||||
opsV1.GET("/index", func(c *gin.Context) {
|
||||
c.HTML(http.StatusOK, "index.html", gin.H{
|
||||
"title": "hello Go",
|
||||
c.HTML(http.StatusOK, "index.html", gin.H{
|
||||
"title": "hello Go",
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
api_port := strconv.Itoa(conf.APIPORT)
|
||||
|
||||
router.Run(":"+api_port)
|
||||
router.Run(":" + api_port)
|
||||
}
|
||||
|
||||
type DparkConf struct {
|
||||
ExtensionInTime int `json:"in"`
|
||||
ExtensionOutTime int `json:"out"`
|
||||
ExtensionInTime int `json:"in"`
|
||||
ExtensionOutTime int `json:"out"`
|
||||
ExtensionInTime2 int `json:"in2"`
|
||||
ExtensionOutTime2 int `json:"out2"`
|
||||
}
|
||||
|
||||
func writeCommand(c *gin.Context) {
|
||||
// var heartbeat []byte = []byte{0x01}
|
||||
addr := c.Query("addr")
|
||||
command := c.Query("command")
|
||||
// commandInt,err := strconv.Atoi(command)
|
||||
// if err !=nil{
|
||||
// c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "command"})
|
||||
// return;
|
||||
// }
|
||||
commands := []byte(command)
|
||||
byteAddr,ok := sensorMap.Load(addr)
|
||||
if !ok{
|
||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "valid addr"})
|
||||
return;
|
||||
}
|
||||
// var heartbeat []byte = []byte{0x01}
|
||||
addr := c.Query("addr")
|
||||
command := c.Query("command")
|
||||
// commandInt,err := strconv.Atoi(command)
|
||||
// if err !=nil{
|
||||
// c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "command"})
|
||||
// return;
|
||||
// }
|
||||
commands := []byte(command)
|
||||
byteAddr, ok := sensorMap.Load(addr)
|
||||
if !ok {
|
||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "valid addr"})
|
||||
return
|
||||
}
|
||||
|
||||
loraNode,ok := loraNodeMap.Load(addr)
|
||||
if !ok{
|
||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "valid addr"})
|
||||
return;
|
||||
}
|
||||
commands = []byte{0x01}
|
||||
if command == "1"{
|
||||
commands = []byte{0x01}
|
||||
}else if command == "2"{
|
||||
commands = []byte{0x02}
|
||||
}else{
|
||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "valid command"})
|
||||
return;
|
||||
}
|
||||
loraNode, ok := loraNodeMap.Load(addr)
|
||||
if !ok {
|
||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "valid addr"})
|
||||
return
|
||||
}
|
||||
commands = []byte{0x01}
|
||||
if command == "1" {
|
||||
commands = []byte{0x01}
|
||||
} else if command == "2" {
|
||||
commands = []byte{0x02}
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "valid command"})
|
||||
return
|
||||
}
|
||||
|
||||
// strconv.Itoa
|
||||
// strconv.Itoa
|
||||
|
||||
var buffer bytes.Buffer
|
||||
buffer.Write(byteAddr.([]byte))
|
||||
// log.Println(commands)
|
||||
buffer.Write(commands)
|
||||
var buffer bytes.Buffer
|
||||
buffer.Write(byteAddr.([]byte))
|
||||
// log.Println(commands)
|
||||
buffer.Write(commands)
|
||||
|
||||
log.Println("loragws ",loraNode.(LoraNode).LORA_GWS)
|
||||
|
||||
for _,loragwip := range loraNode.(LoraNode).LORA_GWS{
|
||||
loraconn,ok := loragwMap.Load(loragwip)
|
||||
if ok{
|
||||
log.Println("=======================begin push tcp command ",buffer.Bytes())
|
||||
_, err := loraconn.(net.Conn).Write(buffer.Bytes())
|
||||
if err != nil {
|
||||
log.Println("write msg error!", err)
|
||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "fail"})
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
log.Println("loragws ", loraNode.(LoraNode).LORA_GWS)
|
||||
|
||||
for _, loragwip := range loraNode.(LoraNode).LORA_GWS {
|
||||
loraconn, ok := loragwMap.Load(loragwip)
|
||||
if ok {
|
||||
log.Println("=======================begin push tcp command ", buffer.Bytes())
|
||||
_, err := loraconn.(net.Conn).Write(buffer.Bytes())
|
||||
if err != nil {
|
||||
log.Println("write msg error!", err)
|
||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "fail"})
|
||||
return
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
log.Println(addr)
|
||||
log.Println(command)
|
||||
log.Println("will send commands ",commands)
|
||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "success"})
|
||||
}
|
||||
|
||||
log.Println(addr)
|
||||
log.Println(command)
|
||||
log.Println("will send commands ", commands)
|
||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "success"})
|
||||
}
|
||||
|
||||
var dparkConf DparkConf
|
||||
|
@ -150,7 +151,7 @@ func getConf() {
|
|||
log.Println("yunhorndebug.getConf.success:", dparkConf)
|
||||
}
|
||||
|
||||
if err!=nil{
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -165,7 +166,7 @@ func getConf() {
|
|||
if dparkConf.ExtensionOutTime < 0 {
|
||||
dparkConf.ExtensionOutTime = 0
|
||||
}
|
||||
// time.
|
||||
// time.
|
||||
extensionInTime = dparkConf.ExtensionInTime
|
||||
extensionOutTime = dparkConf.ExtensionOutTime
|
||||
|
||||
|
@ -197,16 +198,16 @@ var dataMap sync.Map
|
|||
//接收传感器push来的数据,解析并上传到云端
|
||||
func push(c *gin.Context) {
|
||||
|
||||
data := c.PostForm("d")
|
||||
data := c.PostForm("d")
|
||||
|
||||
// go dealData(data)
|
||||
// go dealData(data)
|
||||
|
||||
log.Println("data:", data)
|
||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "data": data})
|
||||
log.Println("data:", data)
|
||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "data": data})
|
||||
|
||||
}
|
||||
|
||||
func dealDatav3(data []byte,loragwip string) string{
|
||||
func dealDatav3(data []byte, loragwip string) string {
|
||||
|
||||
nowtime := time.Now()
|
||||
|
||||
|
@ -214,11 +215,11 @@ func dealDatav3(data []byte,loragwip string) string{
|
|||
|
||||
strs := data
|
||||
|
||||
buffer := new(bytes.Buffer)
|
||||
buffer := new(bytes.Buffer)
|
||||
for _, b := range data[:4] {
|
||||
s := strconv.FormatInt(int64(b&0xff), 16)
|
||||
if len(s) == 1 {
|
||||
buffer.WriteString("0")
|
||||
buffer.WriteString("0")
|
||||
}
|
||||
buffer.WriteString(s)
|
||||
}
|
||||
|
@ -230,21 +231,21 @@ func dealDatav3(data []byte,loragwip string) string{
|
|||
datatype := data[5]
|
||||
|
||||
//dpark 1-尿布台 2-吸顶
|
||||
if datatype==1 || datatype==2{
|
||||
if datatype == 1 || datatype == 2 {
|
||||
|
||||
//过滤无效数据 adr
|
||||
|
||||
cs2001 := data[6]
|
||||
|
||||
var R_data P1004_6
|
||||
R_data.CODE = 1005
|
||||
R_data.CODE = 1008
|
||||
R_data.ID = adr
|
||||
//尿布台
|
||||
R_data.VERSION = "sts_hps_3ir"
|
||||
R_data.ONLINE = true
|
||||
R_data.DATA = make(map[string]interface{})
|
||||
R_data.DATA["cs2001"]=cs2001
|
||||
R_data.DATA["data"]=cs2001
|
||||
R_data.DATA["cs2001"] = cs2001
|
||||
R_data.DATA["data"] = cs2001
|
||||
|
||||
datatypeStr := strconv.FormatInt(int64(data[5]&0xff), 16)
|
||||
|
||||
|
@ -259,20 +260,20 @@ func dealDatav3(data []byte,loragwip string) string{
|
|||
//红外人体感应
|
||||
readyData.WriteString(cs2001Str)
|
||||
|
||||
newdtype := strs[5]
|
||||
newdtype := strs[5]
|
||||
|
||||
tmp := []byte{0, 0}
|
||||
tof := tmp[0]
|
||||
|
||||
if newdtype==1{
|
||||
if newdtype == 1 {
|
||||
tof = data[7]
|
||||
R_data.VERSION = "sts_lts_01"
|
||||
R_data.DATA["tof"]=tof
|
||||
R_data.DATA["tof"] = tof
|
||||
tofTmp := strconv.FormatInt(int64(data[7]&0xff), 10)
|
||||
readyData.WriteString("*")
|
||||
readyData.WriteString(tofTmp)
|
||||
}
|
||||
R_data.TIMESTAMP=time.Now().UnixNano()
|
||||
R_data.TIMESTAMP = time.Now().UnixNano() / 1e6
|
||||
|
||||
data_bufTmp, _ := json.Marshal(R_data)
|
||||
data_buf := string(data_bufTmp)
|
||||
|
@ -285,13 +286,13 @@ func dealDatav3(data []byte,loragwip string) string{
|
|||
|
||||
if datatype == 1 {
|
||||
//尿布台类型
|
||||
if cs2001==1 || tof<130{
|
||||
if cs2001 == 1 || tof < 130 {
|
||||
//有人占用
|
||||
current = 1
|
||||
}
|
||||
}else if datatype==2{
|
||||
} else if datatype == 2 {
|
||||
//吸顶类型
|
||||
if cs2001 ==1 {
|
||||
if cs2001 == 1 {
|
||||
//有人占用
|
||||
current = 1
|
||||
}
|
||||
|
@ -306,41 +307,40 @@ func dealDatav3(data []byte,loragwip string) string{
|
|||
// log.Println("load loraNode:",loraNode)
|
||||
|
||||
//log.Println("yunhorndeug.push.data.cuurent_data,current",loraNode.(LoraNode).CURRENT_DATA,current)
|
||||
if loraNode.(LoraNode).CURRENT_DATA != current{
|
||||
//不相同,直接改变状态,更新时间
|
||||
if loraNode.(LoraNode).CURRENT_DATA != current {
|
||||
//不相同,直接改变状态,更新时间
|
||||
|
||||
// loraNode.(LoraNode).CURRENT_DATA = current
|
||||
// loraNode.(LoraNode).TIME = time.Now()
|
||||
// loraNode.(LoraNode).CHECK_TIME = true
|
||||
// loraNode.(LoraNode).CURRENT_DATA = current
|
||||
// loraNode.(LoraNode).TIME = time.Now()
|
||||
// loraNode.(LoraNode).CHECK_TIME = true
|
||||
|
||||
newLoraNode := LoraNode{}
|
||||
newLoraNode := LoraNode{}
|
||||
newLoraNode.CURRENT_DATA = current
|
||||
newLoraNode.TIME = time.Now()
|
||||
newLoraNode.CHECK_TIME = true
|
||||
|
||||
newLoraNode.LOCATION_TYPE = loraNode.(LoraNode).LOCATION_TYPE
|
||||
newLoraNode.LOCATION_CODE = loraNode.(LoraNode).LOCATION_CODE
|
||||
newLoraNode.LOCATION_DATA = loraNode.(LoraNode).LOCATION_DATA
|
||||
newLoraNode.DEVICE = loraNode.(LoraNode).DEVICE
|
||||
|
||||
if !Contains(newLoraNode.LORA_GWS, loragwip) {
|
||||
newLoraNode.LORA_GWS = append(newLoraNode.LORA_GWS, loragwip)
|
||||
}
|
||||
|
||||
loraNodeMap.Store(adr, newLoraNode)
|
||||
|
||||
//初次启动
|
||||
if loraNode.(LoraNode).CURRENT_DATA == -1 {
|
||||
changeDataV2(newLoraNode)
|
||||
}
|
||||
|
||||
if datatype == 2 && (extensionInTime2 <= 0 || extensionOutTime2 <= 0) {
|
||||
newLoraNode.CURRENT_DATA = current
|
||||
newLoraNode.TIME = time.Now()
|
||||
newLoraNode.CHECK_TIME=true
|
||||
changeDataV2(newLoraNode)
|
||||
}
|
||||
|
||||
newLoraNode.LOCATION_TYPE = loraNode.(LoraNode).LOCATION_TYPE
|
||||
newLoraNode.LOCATION_CODE = loraNode.(LoraNode).LOCATION_CODE
|
||||
newLoraNode.LOCATION_DATA = loraNode.(LoraNode).LOCATION_DATA
|
||||
newLoraNode.DEVICE = loraNode.(LoraNode).DEVICE
|
||||
|
||||
if(!Contains(newLoraNode.LORA_GWS,loragwip)){
|
||||
newLoraNode.LORA_GWS = append(newLoraNode.LORA_GWS,loragwip)
|
||||
}
|
||||
|
||||
loraNodeMap.Store(adr,newLoraNode)
|
||||
|
||||
//初次启动
|
||||
if loraNode.(LoraNode).CURRENT_DATA == -1{
|
||||
changeDataV2(newLoraNode)
|
||||
}
|
||||
|
||||
if (datatype==2 && (extensionInTime2<=0 || extensionOutTime2<=0)){
|
||||
newLoraNode.CURRENT_DATA = current
|
||||
changeDataV2(newLoraNode)
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
} else {
|
||||
// 非首次
|
||||
if loraNode.(LoraNode).CHECK_TIME {
|
||||
|
||||
|
@ -351,24 +351,24 @@ func dealDatav3(data []byte,loragwip string) string{
|
|||
|
||||
if current == 0 {
|
||||
//类型2 吸顶
|
||||
if datatype==2{
|
||||
if durationAsInt64 < extensionOutTime2 && extensionOutTime2>0 {
|
||||
return ""
|
||||
}
|
||||
}else{
|
||||
if durationAsInt64 < extensionOutTime && extensionOutTime>0 {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
//类型2 吸顶
|
||||
if datatype==2{
|
||||
if durationAsInt64 < extensionInTime2 && extensionInTime2>0 {
|
||||
if datatype == 2 {
|
||||
if durationAsInt64 < extensionOutTime2 && extensionOutTime2 > 0 {
|
||||
return ""
|
||||
}
|
||||
}else{
|
||||
if durationAsInt64 < extensionInTime && extensionInTime>0 {
|
||||
} else {
|
||||
if durationAsInt64 < extensionOutTime && extensionOutTime > 0 {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
//类型2 吸顶
|
||||
if datatype == 2 {
|
||||
if durationAsInt64 < extensionInTime2 && extensionInTime2 > 0 {
|
||||
return ""
|
||||
}
|
||||
} else {
|
||||
if durationAsInt64 < extensionInTime && extensionInTime > 0 {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
@ -381,68 +381,67 @@ func dealDatav3(data []byte,loragwip string) string{
|
|||
newLoraNode := LoraNode{}
|
||||
newLoraNode.CURRENT_DATA = current
|
||||
newLoraNode.TIME = loraNode.(LoraNode).TIME
|
||||
newLoraNode.CHECK_TIME= false
|
||||
newLoraNode.CHECK_TIME = false
|
||||
|
||||
newLoraNode.LOCATION_TYPE = loraNode.(LoraNode).LOCATION_TYPE
|
||||
newLoraNode.LOCATION_CODE = loraNode.(LoraNode).LOCATION_CODE
|
||||
newLoraNode.LOCATION_DATA = loraNode.(LoraNode).LOCATION_DATA
|
||||
newLoraNode.DEVICE = loraNode.(LoraNode).DEVICE
|
||||
if(!Contains(newLoraNode.LORA_GWS,loragwip)){
|
||||
newLoraNode.LORA_GWS = append(newLoraNode.LORA_GWS,loragwip)
|
||||
if !Contains(newLoraNode.LORA_GWS, loragwip) {
|
||||
newLoraNode.LORA_GWS = append(newLoraNode.LORA_GWS, loragwip)
|
||||
}
|
||||
loraNodeMap.Store(adr,newLoraNode)
|
||||
loraNodeMap.Store(adr, newLoraNode)
|
||||
|
||||
changeDataV2(newLoraNode)
|
||||
}else{
|
||||
} else {
|
||||
// loraNode.(LoraNode).CHECK_TIME = true
|
||||
|
||||
newLoraNode := LoraNode{}
|
||||
newLoraNode.CURRENT_DATA = loraNode.(LoraNode).CURRENT_DATA
|
||||
newLoraNode.TIME = time.Now()
|
||||
newLoraNode.CHECK_TIME= true
|
||||
newLoraNode.CHECK_TIME = true
|
||||
|
||||
newLoraNode.LOCATION_TYPE = loraNode.(LoraNode).LOCATION_TYPE
|
||||
newLoraNode.LOCATION_CODE = loraNode.(LoraNode).LOCATION_CODE
|
||||
newLoraNode.LOCATION_DATA = loraNode.(LoraNode).LOCATION_DATA
|
||||
newLoraNode.DEVICE = loraNode.(LoraNode).DEVICE
|
||||
if(!Contains(newLoraNode.LORA_GWS,loragwip)){
|
||||
newLoraNode.LORA_GWS = append(newLoraNode.LORA_GWS,loragwip)
|
||||
if !Contains(newLoraNode.LORA_GWS, loragwip) {
|
||||
newLoraNode.LORA_GWS = append(newLoraNode.LORA_GWS, loragwip)
|
||||
}
|
||||
|
||||
if (datatype==2 && (extensionInTime2<=0 || extensionOutTime2<=0)){
|
||||
if datatype == 2 && (extensionInTime2 <= 0 || extensionOutTime2 <= 0) {
|
||||
newLoraNode.CURRENT_DATA = current
|
||||
changeDataV2(newLoraNode)
|
||||
}
|
||||
|
||||
loraNodeMap.Store(adr,newLoraNode)
|
||||
|
||||
loraNodeMap.Store(adr, newLoraNode)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}else if datatype==3{
|
||||
} else if datatype == 3 {
|
||||
var R_data P1004_6
|
||||
R_data.CODE = 1005
|
||||
R_data.ID = adr
|
||||
// "853c0000"
|
||||
//尿布台
|
||||
R_data.VERSION = "yunhorn_door_c_v1"
|
||||
R_data.VERSION = "yunhorn_door_c_v1"
|
||||
R_data.ONLINE = true
|
||||
R_data.DATA = make(map[string]interface{})
|
||||
R_data.DATA["data"]=int64(data[6])
|
||||
R_data.DATA["data"] = int64(data[6])
|
||||
data_bufTmp, _ := json.Marshal(R_data)
|
||||
data_buf := string(data_bufTmp)
|
||||
go post_to_server(data_buf)
|
||||
|
||||
}else if datatype==4{
|
||||
} else if datatype == 4 {
|
||||
buffer := new(bytes.Buffer)
|
||||
|
||||
// log.Println("data[9]",int64(data[9]))
|
||||
// log.Println("data[10]",int64(data[10]))
|
||||
|
||||
log.Println("aqdata|all:",data)
|
||||
log.Println("aqdata|all:", data)
|
||||
|
||||
if data[6] == 0{
|
||||
if data[6] == 0 {
|
||||
buffer.WriteString("-")
|
||||
}
|
||||
|
||||
|
@ -451,12 +450,11 @@ func dealDatav3(data []byte,loragwip string) string{
|
|||
buffer.WriteString(".")
|
||||
wdfh := int(data[10])
|
||||
wdint2 := strconv.FormatInt(int64(data[8]&0xff), 10)
|
||||
if wdfh<10{
|
||||
if wdfh < 10 {
|
||||
buffer.WriteString("0")
|
||||
}
|
||||
buffer.WriteString(wdint2)
|
||||
|
||||
|
||||
// log.Println("aqdata|wdfh",data[6])
|
||||
|
||||
wddata := buffer.String()
|
||||
|
@ -468,7 +466,7 @@ func dealDatav3(data []byte,loragwip string) string{
|
|||
buffer.WriteString(sdint1)
|
||||
buffer.WriteString(".")
|
||||
sdint2 := strconv.FormatInt(int64(data[10]&0xff), 10)
|
||||
if wdfh<10{
|
||||
if wdfh < 10 {
|
||||
buffer.WriteString("0")
|
||||
}
|
||||
buffer.WriteString(sdint2)
|
||||
|
@ -482,7 +480,7 @@ func dealDatav3(data []byte,loragwip string) string{
|
|||
buffer.WriteString(nh3int1)
|
||||
buffer.WriteString(".")
|
||||
nh3int2 := strconv.Itoa(int(data[12]))
|
||||
if int64(data[12])<10{
|
||||
if int64(data[12]) < 10 {
|
||||
buffer.WriteString("0")
|
||||
}
|
||||
buffer.WriteString(nh3int2)
|
||||
|
@ -490,13 +488,12 @@ func dealDatav3(data []byte,loragwip string) string{
|
|||
|
||||
// log.Println("aqdata|nh3",nh3data)
|
||||
|
||||
|
||||
buffer = new(bytes.Buffer)
|
||||
h2sint1 := strconv.Itoa(int(data[13]))
|
||||
buffer.WriteString(h2sint1)
|
||||
buffer.WriteString(".")
|
||||
h2sint2 := strconv.Itoa(int(data[14]))
|
||||
if int64(data[14])<10{
|
||||
if int64(data[14]) < 10 {
|
||||
buffer.WriteString("0")
|
||||
}
|
||||
buffer.WriteString(h2sint2)
|
||||
|
@ -508,7 +505,7 @@ func dealDatav3(data []byte,loragwip string) string{
|
|||
buffer.WriteString(ch2o1)
|
||||
buffer.WriteString(".")
|
||||
ch2o2 := strconv.Itoa(int(data[16]))
|
||||
if int64(data[16])<10{
|
||||
if int64(data[16]) < 10 {
|
||||
buffer.WriteString("0")
|
||||
}
|
||||
buffer.WriteString(ch2o2)
|
||||
|
@ -517,7 +514,7 @@ func dealDatav3(data []byte,loragwip string) string{
|
|||
// ch2o := uint32(data[14])*256+uint32(data[15])
|
||||
// log.Println("aqdata|ch2o",ch2o)
|
||||
|
||||
co2data := uint32(data[17])*256+uint32(data[18])
|
||||
co2data := uint32(data[17])*256 + uint32(data[18])
|
||||
// log.Println("aqdata|co2data",co2data)
|
||||
|
||||
tvocdata := data[19]
|
||||
|
@ -525,17 +522,17 @@ func dealDatav3(data []byte,loragwip string) string{
|
|||
|
||||
// log.Println("pm25data1",data[19])
|
||||
// log.Println("pm25data2",data[20])
|
||||
pm25data := uint32(data[20])*256+uint32(data[21])
|
||||
pm25data := uint32(data[20])*256 + uint32(data[21])
|
||||
// log.Println("aqdata|pm25data",pm25data)
|
||||
|
||||
// log.Println("pm10data1",data[21])
|
||||
// log.Println("pm10data2",data[22])
|
||||
pm10data := uint32(data[22])*256+uint32(data[23])
|
||||
pm10data := uint32(data[22])*256 + uint32(data[23])
|
||||
// log.Println("aqdata|pm10data",pm10data)
|
||||
|
||||
//wdfh
|
||||
log.Printf("aqdata|wddata|sddata|nh3data|h2sdata|ch2o|co2data|tvocdata|pm25data|pm10data")
|
||||
log.Printf("aqdata|%s|%s|%s|%s|%s|%d|%d|%d|%d",wddata,sddata,nh3data,h2sdata,ch2o,co2data,tvocdata,pm25data,pm10data)
|
||||
log.Printf("aqdata|%s|%s|%s|%s|%s|%d|%d|%d|%d", wddata, sddata, nh3data, h2sdata, ch2o, co2data, tvocdata, pm25data, pm10data)
|
||||
|
||||
var R_data P1004_6
|
||||
R_data.CODE = 1005
|
||||
|
@ -545,16 +542,16 @@ func dealDatav3(data []byte,loragwip string) string{
|
|||
R_data.VERSION = "yunhorn_kq_c_v1"
|
||||
R_data.ONLINE = true
|
||||
R_data.DATA = make(map[string]interface{})
|
||||
R_data.DATA["temperature"]=wddata
|
||||
R_data.DATA["humidity"]=sddata
|
||||
R_data.DATA["temperature"] = wddata
|
||||
R_data.DATA["humidity"] = sddata
|
||||
|
||||
R_data.DATA["nh3"]=nh3data
|
||||
R_data.DATA["h2s"]=h2sdata
|
||||
R_data.DATA["ch2o"]=ch2o
|
||||
R_data.DATA["co2"]=co2data
|
||||
R_data.DATA["tvoc"]=tvocdata
|
||||
R_data.DATA["pm25"]=pm25data
|
||||
R_data.DATA["pm10"]=pm10data
|
||||
R_data.DATA["nh3"] = nh3data
|
||||
R_data.DATA["h2s"] = h2sdata
|
||||
R_data.DATA["ch2o"] = ch2o
|
||||
R_data.DATA["co2"] = co2data
|
||||
R_data.DATA["tvoc"] = tvocdata
|
||||
R_data.DATA["pm25"] = pm25data
|
||||
R_data.DATA["pm10"] = pm10data
|
||||
|
||||
data_bufTmp, _ := json.Marshal(R_data)
|
||||
data_buf := string(data_bufTmp)
|
||||
|
@ -574,22 +571,22 @@ func changeData(num int, device Device) {
|
|||
DEVICEDATAS.DATA[demoDevice.VERSION+"_"+strconv.Itoa(num)] = device
|
||||
}
|
||||
|
||||
func changeDataV2(loraNode LoraNode){
|
||||
func changeDataV2(loraNode LoraNode) {
|
||||
// log.Println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
|
||||
// log.Println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@00000:",loraNode)
|
||||
// log.Println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111:",DEVICEDATAS.DATA[loraNode.DEVICE])
|
||||
// DEVICEDATAS.RLock()
|
||||
DEVICEDATAS.Lock()
|
||||
if DEVICEDATAS.DATA !=nil{
|
||||
_,ok := DEVICEDATAS.DATA[loraNode.DEVICE]
|
||||
if ok {
|
||||
if DEVICEDATAS.DATA != nil {
|
||||
_, ok := DEVICEDATAS.DATA[loraNode.DEVICE]
|
||||
if ok {
|
||||
DEVICEDATAS.DATA[loraNode.DEVICE].DATA[loraNode.LOCATION_DATA] = loraNode.CURRENT_DATA
|
||||
log.Println("yunhorndeug.push.data.change:",DEVICEDATAS.DATA[loraNode.DEVICE])
|
||||
}else{
|
||||
log.Println("changeDataV2.DEVICEDATAS load not ok:",loraNode.DEVICE)
|
||||
log.Println("yunhorndeug.push.data.change:", DEVICEDATAS.DATA[loraNode.DEVICE])
|
||||
} else {
|
||||
log.Println("changeDataV2.DEVICEDATAS load not ok:", loraNode.DEVICE)
|
||||
}
|
||||
}else{
|
||||
log.Println("changeDataV2.DEVICEDATAS not init:",loraNode.DEVICE)
|
||||
} else {
|
||||
log.Println("changeDataV2.DEVICEDATAS not init:", loraNode.DEVICE)
|
||||
}
|
||||
DEVICEDATAS.Unlock()
|
||||
// log.Println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
|
||||
|
@ -631,10 +628,23 @@ var rl_data EventNotificationAlert
|
|||
|
||||
// 提交人流量api
|
||||
func get_renliu_api(c *gin.Context) {
|
||||
|
||||
var rl_data_tmp EventNotificationAlert
|
||||
|
||||
err := c.Bind(&rl_data)
|
||||
if conf.DEBUG {
|
||||
log.Println(rl_data)
|
||||
}
|
||||
|
||||
err2 := c.Bind(&rl_data_tmp)
|
||||
if conf.DEBUG {
|
||||
log.Println("rl_data_tmp:", rl_data_tmp)
|
||||
}
|
||||
|
||||
if 2 > 3 {
|
||||
check(err2)
|
||||
}
|
||||
|
||||
check(err)
|
||||
send_data(1004)
|
||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "data": rl_data})
|
||||
|
@ -779,19 +789,19 @@ func seat_api(c *gin.Context) {
|
|||
//获取到设备版本
|
||||
version, num := arr[0], arr[1]
|
||||
|
||||
if version=="null" || num == "null"{
|
||||
if version == "null" || num == "null" {
|
||||
continue
|
||||
}
|
||||
if DEVICEDATAS.DATA[version+"_"+num].DATA != nil {
|
||||
log.Println("^^^^^^^^^^^^^^^^^^DEVICEDATAS.DATA-version_num",DEVICEDATAS.DATA[version+"_"+num])
|
||||
log.Println("^^^^^^^^^^^^^^^^^^DEVICEDATAS.DATA-version_num", DEVICEDATAS.DATA[version+"_"+num])
|
||||
for k, j := range i.DATA {
|
||||
//log.Println("@@@@@@@@@@@@@@@@@@@@@@@@@@,i.DATA-j",j)
|
||||
// log.Println("============================devicedatas.data:", DEVICEDATAS.DATA[version+"_"+num].DATA)
|
||||
if DEVICEDATAS.DATA[version+"_"+num].DATA["data"+strconv.Itoa(k+1)] != nil {
|
||||
//这里不会改变DEVICEDATAS.DATA的数据,只是判断一下有没有数据,如果有,则加上
|
||||
// log.Println("==========================do.data:", DEVICEDATAS.DATA[version+"_"+num].DATA["data"+strconv.Itoa(k+1)])
|
||||
j = append(j, DEVICEDATAS.DATA[version+"_"+num].DATA["data"+strconv.Itoa(k+1)])
|
||||
}
|
||||
//log.Println("@@@@@@@@@@@@@@@@@@@@@@@@@@,i.DATA-j",j)
|
||||
// log.Println("============================devicedatas.data:", DEVICEDATAS.DATA[version+"_"+num].DATA)
|
||||
if DEVICEDATAS.DATA[version+"_"+num].DATA["data"+strconv.Itoa(k+1)] != nil {
|
||||
//这里不会改变DEVICEDATAS.DATA的数据,只是判断一下有没有数据,如果有,则加上
|
||||
// log.Println("==========================do.data:", DEVICEDATAS.DATA[version+"_"+num].DATA["data"+strconv.Itoa(k+1)])
|
||||
j = append(j, DEVICEDATAS.DATA[version+"_"+num].DATA["data"+strconv.Itoa(k+1)])
|
||||
}
|
||||
conf_data = append(conf_data, j)
|
||||
//log.Println("@@@@@@@@@@@@@@@@@@@@@@@@@@,i.DATA-j,appended.conf_data",conf_data)
|
||||
}
|
||||
|
@ -801,16 +811,16 @@ func seat_api(c *gin.Context) {
|
|||
log.Println("=================end conf.data:", conf_data)
|
||||
|
||||
switch type_id {
|
||||
case "1":
|
||||
data = scan_seat_from_confdata("男厕位", conf_data)
|
||||
case "2":
|
||||
data = scan_seat_from_confdata("男便池", conf_data)
|
||||
case "3":
|
||||
data = scan_seat_from_confdata("女厕位", conf_data)
|
||||
case "4":
|
||||
data = scan_seat_from_confdata("母婴", conf_data)
|
||||
case "5":
|
||||
data = scan_seat_from_confdata("残卫", conf_data)
|
||||
case "1":
|
||||
data = scan_seat_from_confdata("男厕位", conf_data)
|
||||
case "2":
|
||||
data = scan_seat_from_confdata("男便池", conf_data)
|
||||
case "3":
|
||||
data = scan_seat_from_confdata("女厕位", conf_data)
|
||||
case "4":
|
||||
data = scan_seat_from_confdata("母婴", conf_data)
|
||||
case "5":
|
||||
data = scan_seat_from_confdata("残卫", conf_data)
|
||||
}
|
||||
DEVICEDATAS.RUnlock()
|
||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "data": data})
|
||||
|
@ -825,7 +835,7 @@ func get_seat_device_data(id string) []string {
|
|||
for _, i := range conf.DEVICES_LIST {
|
||||
if id == i[0] {
|
||||
data[0], data[1] = i[2], i[3]
|
||||
log.Println("get_seat_device_data",data)
|
||||
log.Println("get_seat_device_data", data)
|
||||
break
|
||||
} else {
|
||||
data[0], data[1] = "null", "null"
|
||||
|
@ -842,7 +852,7 @@ func scan_seat_from_confdata(T string, conf_data [][]interface{}) Seat_data {
|
|||
data.POSITIONLIST = make([]interface{}, 0)
|
||||
data.HASPERSONLIST = make([]interface{}, 0)
|
||||
for _, i := range conf_data {
|
||||
//T 男厕位 女厕位
|
||||
//T 男厕位 女厕位
|
||||
//conf_data [[男厕位 1],[女厕位 1]]
|
||||
// 第一位是数据类型 第二位是位置 第三位是有无人占用
|
||||
//conf_data [男厕位 1 0/1]
|
||||
|
@ -855,10 +865,10 @@ func scan_seat_from_confdata(T string, conf_data [][]interface{}) Seat_data {
|
|||
}
|
||||
data.HASPERSONLIST = append(data.HASPERSONLIST, i[2])
|
||||
switch i[2] {
|
||||
case 0:
|
||||
data.EMPTYPOSITION++
|
||||
case 1:
|
||||
data.OCCUPYPOSITION++
|
||||
case 0:
|
||||
data.EMPTYPOSITION++
|
||||
case 1:
|
||||
data.OCCUPYPOSITION++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
<!DOCTYPE html>
|
||||
<html xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
|
||||
lang="zh-CN">
|
||||
<meta http-equiv="content-type" content="txt/html; charset=utf-8" />
|
||||
|
||||
<head>
|
||||
<script type="text/javascript"
|
||||
src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
|
||||
|
||||
<title>yunhorn-dev</title>
|
||||
</head>
|
||||
<body>
|
||||
lorawan 数据调试
|
||||
<div id="content"></div>
|
||||
<!--
|
||||
<button onclick="closeWebSocket()">测试添加内容</button>
|
||||
-->
|
||||
<script>
|
||||
function closeWebSocket(){
|
||||
$("#content").append("<p>测试</p>");
|
||||
}
|
||||
</script>
|
||||
<script type="text/javascript">
|
||||
var websocket = null;
|
||||
|
||||
//判断当前浏览器是否支持WebSocket
|
||||
if ('WebSocket' in window) {
|
||||
websocket = new WebSocket("wss://" + "smartoilets.cn/socketServer" + "/socket");
|
||||
} else {
|
||||
alert('当前浏览器 Not support websocket')
|
||||
}
|
||||
|
||||
//连接发生错误的回调方法
|
||||
websocket.onerror = function() {
|
||||
console.log("onerror")
|
||||
|
||||
};
|
||||
websocket.onopen = function() {
|
||||
console.log("onopen")
|
||||
websocket.send("{'code':131}")
|
||||
console.log("sned code 131")
|
||||
}
|
||||
//接收到消息的回调方法
|
||||
websocket.onmessage = function(event) {
|
||||
// setMessageInnerHTML(event.data);
|
||||
//console.log("websocket.message:",event.data)
|
||||
console.log("websocket.message")
|
||||
console.log(event.data)
|
||||
var obj=eval("("+event.data+")");
|
||||
console.log(obj.time)
|
||||
$("#content").prepend("<p>"+event.data+"</p>");
|
||||
//websocket.send("{'code':0111,'wcId':15}")
|
||||
}
|
||||
//连接关闭的回调方法
|
||||
websocket.onclose = function() {
|
||||
// setMessageInnerHTML("WebSocket连接关闭");
|
||||
$("#content").prepend("<p>websocket已断开</p>");
|
||||
|
||||
console.log("onclose")
|
||||
}
|
||||
|
||||
//监听窗口关闭事件,当窗口关闭时,主动去关闭websocket连接,防止连接还没断开就关闭窗口,server端会抛异常。
|
||||
window.onbeforeunload = function() {
|
||||
console.log("onbeforeunload")
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue