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":"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":"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":"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"}
|
- {"adr":"0c255d17",location_type":"","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module yunhorn_gateway
|
||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
require (
|
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-contrib/cors v1.3.0
|
||||||
github.com/gin-gonic/gin v1.4.0
|
github.com/gin-gonic/gin v1.4.0
|
||||||
github.com/mattn/go-sqlite3 v1.11.0
|
github.com/mattn/go-sqlite3 v1.11.0
|
||||||
|
|
|
@ -3,19 +3,20 @@ package main
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
// "encoding/json"
|
// "encoding/json"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
|
||||||
// "strconv"
|
// "strconv"
|
||||||
"time"
|
|
||||||
"sync"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/yaml"
|
"k8s.io/apimachinery/pkg/util/yaml"
|
||||||
|
|
||||||
"bytes"
|
"bytes"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Traffic struct {
|
type Traffic struct {
|
||||||
|
@ -99,7 +100,7 @@ type Serialconf struct {
|
||||||
NOTE string `json:"note"`
|
NOTE string `json:"note"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoraNode struct{
|
type LoraNode struct {
|
||||||
ADR string `json:"adr"`
|
ADR string `json:"adr"`
|
||||||
LOCATION_TYPE string `json:"location_type"`
|
LOCATION_TYPE string `json:"location_type"`
|
||||||
LOCATION_CODE string `json:"location_code"`
|
LOCATION_CODE string `json:"location_code"`
|
||||||
|
@ -136,7 +137,6 @@ var loraNodeMap sync.Map
|
||||||
|
|
||||||
var db, _ = sql.Open("sqlite3", "./db/gateway.db")
|
var db, _ = sql.Open("sqlite3", "./db/gateway.db")
|
||||||
|
|
||||||
|
|
||||||
type pluginConfig struct {
|
type pluginConfig struct {
|
||||||
PodNodeSelectorPluginConfig map[string]string
|
PodNodeSelectorPluginConfig map[string]string
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,7 @@ func init() {
|
||||||
configfile, err := os.Open("conf/gateway.yaml")
|
configfile, err := os.Open("conf/gateway.yaml")
|
||||||
check(err)
|
check(err)
|
||||||
defer configfile.Close()
|
defer configfile.Close()
|
||||||
configData,err := ioutil.ReadAll(configfile)
|
configData, err := ioutil.ReadAll(configfile)
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
reader := bytes.NewReader(configData)
|
reader := bytes.NewReader(configData)
|
||||||
|
@ -185,10 +185,10 @@ func init() {
|
||||||
|
|
||||||
log.Println("slaveDevices:", conf.WIRELESSSLAVEDEVICES)
|
log.Println("slaveDevices:", conf.WIRELESSSLAVEDEVICES)
|
||||||
|
|
||||||
for _,v := range conf.LORANODES {
|
for _, v := range conf.LORANODES {
|
||||||
v.CURRENT_DATA = -1
|
v.CURRENT_DATA = -1
|
||||||
v.TIME = time.Now()
|
v.TIME = time.Now()
|
||||||
loraNodeMap.Store(v.ADR,v)
|
loraNodeMap.Store(v.ADR, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
DEVICEDATAS.Lock()
|
DEVICEDATAS.Lock()
|
||||||
|
|
11
main.go
11
main.go
|
@ -1,12 +1,13 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/robfig/cron"
|
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/robfig/cron"
|
||||||
)
|
)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
@ -85,12 +86,12 @@ func main() {
|
||||||
go send_data(CODE1001)
|
go send_data(CODE1001)
|
||||||
}
|
}
|
||||||
|
|
||||||
//一分钟一次 同步数据
|
//一分钟一次 同步数据
|
||||||
c.AddFunc("0, *, *, *, *, *", func() {
|
c.AddFunc("0, *, *, *, *, *", func() {
|
||||||
if conf.SYNDATA {
|
if conf.SYNDATA {
|
||||||
if conf.PROCATEGORY == PRO_CATEGORY_WIRED {
|
if conf.PROCATEGORY == PRO_CATEGORY_WIRED {
|
||||||
send_data(CODE1001)
|
send_data(CODE1001)
|
||||||
}else if conf.PROCATEGORY == PRO_CATEGORY_WIRELESS{
|
} else if conf.PROCATEGORY == PRO_CATEGORY_WIRELESS {
|
||||||
yunhorn_hb_dpark_v1()
|
yunhorn_hb_dpark_v1()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,7 +113,7 @@ func main() {
|
||||||
c.AddFunc("0, 0, 0, *, *, *", insertdata)
|
c.AddFunc("0, 0, 0, *, *, *", insertdata)
|
||||||
c.AddFunc("0, 0, *, *, *, *", get_weather)
|
c.AddFunc("0, 0, *, *, *, *", get_weather)
|
||||||
//定时更新today字段,当前日期
|
//定时更新today字段,当前日期
|
||||||
c.AddFunc("0, *, *, *, *, *", func(){
|
c.AddFunc("0, *, *, *, *, *", func() {
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
today = t.Format("2006-01-02")
|
today = t.Format("2006-01-02")
|
||||||
})
|
})
|
||||||
|
@ -132,7 +133,7 @@ func main() {
|
||||||
|
|
||||||
for {
|
for {
|
||||||
conn, err := listener.Accept()
|
conn, err := listener.Accept()
|
||||||
loragwMap.Store(conn.RemoteAddr().String(),conn)
|
loragwMap.Store(conn.RemoteAddr().String(), conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("accept fail, err: %v\n", err)
|
log.Printf("accept fail, err: %v\n", err)
|
||||||
continue
|
continue
|
||||||
|
|
216
router.go
216
router.go
|
@ -1,19 +1,20 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/gin-contrib/cors"
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"bytes"
|
|
||||||
"net"
|
"github.com/gin-contrib/cors"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var router = gin.Default()
|
var router = gin.Default()
|
||||||
|
@ -36,7 +37,7 @@ func gw_router() {
|
||||||
v1.POST("/push", push)
|
v1.POST("/push", push)
|
||||||
|
|
||||||
v1.GET("/getConf")
|
v1.GET("/getConf")
|
||||||
v1.GET("/writeCommand",writeCommand)
|
v1.GET("/writeCommand", writeCommand)
|
||||||
}
|
}
|
||||||
|
|
||||||
router.LoadHTMLGlob("static/*")
|
router.LoadHTMLGlob("static/*")
|
||||||
|
@ -53,7 +54,7 @@ func gw_router() {
|
||||||
|
|
||||||
api_port := strconv.Itoa(conf.APIPORT)
|
api_port := strconv.Itoa(conf.APIPORT)
|
||||||
|
|
||||||
router.Run(":"+api_port)
|
router.Run(":" + api_port)
|
||||||
}
|
}
|
||||||
|
|
||||||
type DparkConf struct {
|
type DparkConf struct {
|
||||||
|
@ -73,25 +74,25 @@ func writeCommand(c *gin.Context) {
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
commands := []byte(command)
|
commands := []byte(command)
|
||||||
byteAddr,ok := sensorMap.Load(addr)
|
byteAddr, ok := sensorMap.Load(addr)
|
||||||
if !ok{
|
if !ok {
|
||||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "valid addr"})
|
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "valid addr"})
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
loraNode,ok := loraNodeMap.Load(addr)
|
loraNode, ok := loraNodeMap.Load(addr)
|
||||||
if !ok{
|
if !ok {
|
||||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "valid addr"})
|
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "valid addr"})
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
commands = []byte{0x01}
|
commands = []byte{0x01}
|
||||||
if command == "1"{
|
if command == "1" {
|
||||||
commands = []byte{0x01}
|
commands = []byte{0x01}
|
||||||
}else if command == "2"{
|
} else if command == "2" {
|
||||||
commands = []byte{0x02}
|
commands = []byte{0x02}
|
||||||
}else{
|
} else {
|
||||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "valid command"})
|
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "valid command"})
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// strconv.Itoa
|
// strconv.Itoa
|
||||||
|
@ -101,19 +102,19 @@ func writeCommand(c *gin.Context) {
|
||||||
// log.Println(commands)
|
// log.Println(commands)
|
||||||
buffer.Write(commands)
|
buffer.Write(commands)
|
||||||
|
|
||||||
log.Println("loragws ",loraNode.(LoraNode).LORA_GWS)
|
log.Println("loragws ", loraNode.(LoraNode).LORA_GWS)
|
||||||
|
|
||||||
for _,loragwip := range loraNode.(LoraNode).LORA_GWS{
|
for _, loragwip := range loraNode.(LoraNode).LORA_GWS {
|
||||||
loraconn,ok := loragwMap.Load(loragwip)
|
loraconn, ok := loragwMap.Load(loragwip)
|
||||||
if ok{
|
if ok {
|
||||||
log.Println("=======================begin push tcp command ",buffer.Bytes())
|
log.Println("=======================begin push tcp command ", buffer.Bytes())
|
||||||
_, err := loraconn.(net.Conn).Write(buffer.Bytes())
|
_, err := loraconn.(net.Conn).Write(buffer.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("write msg error!", err)
|
log.Println("write msg error!", err)
|
||||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "fail"})
|
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "fail"})
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +122,7 @@ func writeCommand(c *gin.Context) {
|
||||||
|
|
||||||
log.Println(addr)
|
log.Println(addr)
|
||||||
log.Println(command)
|
log.Println(command)
|
||||||
log.Println("will send commands ",commands)
|
log.Println("will send commands ", commands)
|
||||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "success"})
|
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "success"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +151,7 @@ func getConf() {
|
||||||
log.Println("yunhorndebug.getConf.success:", dparkConf)
|
log.Println("yunhorndebug.getConf.success:", dparkConf)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err!=nil{
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +166,7 @@ func getConf() {
|
||||||
if dparkConf.ExtensionOutTime < 0 {
|
if dparkConf.ExtensionOutTime < 0 {
|
||||||
dparkConf.ExtensionOutTime = 0
|
dparkConf.ExtensionOutTime = 0
|
||||||
}
|
}
|
||||||
// time.
|
// time.
|
||||||
extensionInTime = dparkConf.ExtensionInTime
|
extensionInTime = dparkConf.ExtensionInTime
|
||||||
extensionOutTime = dparkConf.ExtensionOutTime
|
extensionOutTime = dparkConf.ExtensionOutTime
|
||||||
|
|
||||||
|
@ -206,7 +207,7 @@ func push(c *gin.Context) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func dealDatav3(data []byte,loragwip string) string{
|
func dealDatav3(data []byte, loragwip string) string {
|
||||||
|
|
||||||
nowtime := time.Now()
|
nowtime := time.Now()
|
||||||
|
|
||||||
|
@ -230,21 +231,21 @@ func dealDatav3(data []byte,loragwip string) string{
|
||||||
datatype := data[5]
|
datatype := data[5]
|
||||||
|
|
||||||
//dpark 1-尿布台 2-吸顶
|
//dpark 1-尿布台 2-吸顶
|
||||||
if datatype==1 || datatype==2{
|
if datatype == 1 || datatype == 2 {
|
||||||
|
|
||||||
//过滤无效数据 adr
|
//过滤无效数据 adr
|
||||||
|
|
||||||
cs2001 := data[6]
|
cs2001 := data[6]
|
||||||
|
|
||||||
var R_data P1004_6
|
var R_data P1004_6
|
||||||
R_data.CODE = 1005
|
R_data.CODE = 1008
|
||||||
R_data.ID = adr
|
R_data.ID = adr
|
||||||
//尿布台
|
//尿布台
|
||||||
R_data.VERSION = "sts_hps_3ir"
|
R_data.VERSION = "sts_hps_3ir"
|
||||||
R_data.ONLINE = true
|
R_data.ONLINE = true
|
||||||
R_data.DATA = make(map[string]interface{})
|
R_data.DATA = make(map[string]interface{})
|
||||||
R_data.DATA["cs2001"]=cs2001
|
R_data.DATA["cs2001"] = cs2001
|
||||||
R_data.DATA["data"]=cs2001
|
R_data.DATA["data"] = cs2001
|
||||||
|
|
||||||
datatypeStr := strconv.FormatInt(int64(data[5]&0xff), 16)
|
datatypeStr := strconv.FormatInt(int64(data[5]&0xff), 16)
|
||||||
|
|
||||||
|
@ -264,15 +265,15 @@ func dealDatav3(data []byte,loragwip string) string{
|
||||||
tmp := []byte{0, 0}
|
tmp := []byte{0, 0}
|
||||||
tof := tmp[0]
|
tof := tmp[0]
|
||||||
|
|
||||||
if newdtype==1{
|
if newdtype == 1 {
|
||||||
tof = data[7]
|
tof = data[7]
|
||||||
R_data.VERSION = "sts_lts_01"
|
R_data.VERSION = "sts_lts_01"
|
||||||
R_data.DATA["tof"]=tof
|
R_data.DATA["tof"] = tof
|
||||||
tofTmp := strconv.FormatInt(int64(data[7]&0xff), 10)
|
tofTmp := strconv.FormatInt(int64(data[7]&0xff), 10)
|
||||||
readyData.WriteString("*")
|
readyData.WriteString("*")
|
||||||
readyData.WriteString(tofTmp)
|
readyData.WriteString(tofTmp)
|
||||||
}
|
}
|
||||||
R_data.TIMESTAMP=time.Now().UnixNano()
|
R_data.TIMESTAMP = time.Now().UnixNano() / 1e6
|
||||||
|
|
||||||
data_bufTmp, _ := json.Marshal(R_data)
|
data_bufTmp, _ := json.Marshal(R_data)
|
||||||
data_buf := string(data_bufTmp)
|
data_buf := string(data_bufTmp)
|
||||||
|
@ -285,13 +286,13 @@ func dealDatav3(data []byte,loragwip string) string{
|
||||||
|
|
||||||
if datatype == 1 {
|
if datatype == 1 {
|
||||||
//尿布台类型
|
//尿布台类型
|
||||||
if cs2001==1 || tof<130{
|
if cs2001 == 1 || tof < 130 {
|
||||||
//有人占用
|
//有人占用
|
||||||
current = 1
|
current = 1
|
||||||
}
|
}
|
||||||
}else if datatype==2{
|
} else if datatype == 2 {
|
||||||
//吸顶类型
|
//吸顶类型
|
||||||
if cs2001 ==1 {
|
if cs2001 == 1 {
|
||||||
//有人占用
|
//有人占用
|
||||||
current = 1
|
current = 1
|
||||||
}
|
}
|
||||||
|
@ -306,7 +307,7 @@ func dealDatav3(data []byte,loragwip string) string{
|
||||||
// log.Println("load loraNode:",loraNode)
|
// log.Println("load loraNode:",loraNode)
|
||||||
|
|
||||||
//log.Println("yunhorndeug.push.data.cuurent_data,current",loraNode.(LoraNode).CURRENT_DATA,current)
|
//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).CURRENT_DATA = current
|
||||||
|
@ -316,31 +317,30 @@ func dealDatav3(data []byte,loragwip string) string{
|
||||||
newLoraNode := LoraNode{}
|
newLoraNode := LoraNode{}
|
||||||
newLoraNode.CURRENT_DATA = current
|
newLoraNode.CURRENT_DATA = current
|
||||||
newLoraNode.TIME = time.Now()
|
newLoraNode.TIME = time.Now()
|
||||||
newLoraNode.CHECK_TIME=true
|
newLoraNode.CHECK_TIME = true
|
||||||
|
|
||||||
newLoraNode.LOCATION_TYPE = loraNode.(LoraNode).LOCATION_TYPE
|
newLoraNode.LOCATION_TYPE = loraNode.(LoraNode).LOCATION_TYPE
|
||||||
newLoraNode.LOCATION_CODE = loraNode.(LoraNode).LOCATION_CODE
|
newLoraNode.LOCATION_CODE = loraNode.(LoraNode).LOCATION_CODE
|
||||||
newLoraNode.LOCATION_DATA = loraNode.(LoraNode).LOCATION_DATA
|
newLoraNode.LOCATION_DATA = loraNode.(LoraNode).LOCATION_DATA
|
||||||
newLoraNode.DEVICE = loraNode.(LoraNode).DEVICE
|
newLoraNode.DEVICE = loraNode.(LoraNode).DEVICE
|
||||||
|
|
||||||
if(!Contains(newLoraNode.LORA_GWS,loragwip)){
|
if !Contains(newLoraNode.LORA_GWS, loragwip) {
|
||||||
newLoraNode.LORA_GWS = append(newLoraNode.LORA_GWS,loragwip)
|
newLoraNode.LORA_GWS = append(newLoraNode.LORA_GWS, loragwip)
|
||||||
}
|
}
|
||||||
|
|
||||||
loraNodeMap.Store(adr,newLoraNode)
|
loraNodeMap.Store(adr, newLoraNode)
|
||||||
|
|
||||||
//初次启动
|
//初次启动
|
||||||
if loraNode.(LoraNode).CURRENT_DATA == -1{
|
if loraNode.(LoraNode).CURRENT_DATA == -1 {
|
||||||
changeDataV2(newLoraNode)
|
changeDataV2(newLoraNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (datatype==2 && (extensionInTime2<=0 || extensionOutTime2<=0)){
|
if datatype == 2 && (extensionInTime2 <= 0 || extensionOutTime2 <= 0) {
|
||||||
newLoraNode.CURRENT_DATA = current
|
newLoraNode.CURRENT_DATA = current
|
||||||
changeDataV2(newLoraNode)
|
changeDataV2(newLoraNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
}else{
|
|
||||||
// 非首次
|
// 非首次
|
||||||
if loraNode.(LoraNode).CHECK_TIME {
|
if loraNode.(LoraNode).CHECK_TIME {
|
||||||
|
|
||||||
|
@ -351,24 +351,24 @@ func dealDatav3(data []byte,loragwip string) string{
|
||||||
|
|
||||||
if current == 0 {
|
if current == 0 {
|
||||||
//类型2 吸顶
|
//类型2 吸顶
|
||||||
if datatype==2{
|
if datatype == 2 {
|
||||||
if durationAsInt64 < extensionOutTime2 && extensionOutTime2>0 {
|
if durationAsInt64 < extensionOutTime2 && extensionOutTime2 > 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
if durationAsInt64 < extensionOutTime && extensionOutTime>0 {
|
if durationAsInt64 < extensionOutTime && extensionOutTime > 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
} else {
|
||||||
//类型2 吸顶
|
//类型2 吸顶
|
||||||
if datatype==2{
|
if datatype == 2 {
|
||||||
if durationAsInt64 < extensionInTime2 && extensionInTime2>0 {
|
if durationAsInt64 < extensionInTime2 && extensionInTime2 > 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
if durationAsInt64 < extensionInTime && extensionInTime>0 {
|
if durationAsInt64 < extensionInTime && extensionInTime > 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -381,46 +381,45 @@ func dealDatav3(data []byte,loragwip string) string{
|
||||||
newLoraNode := LoraNode{}
|
newLoraNode := LoraNode{}
|
||||||
newLoraNode.CURRENT_DATA = current
|
newLoraNode.CURRENT_DATA = current
|
||||||
newLoraNode.TIME = loraNode.(LoraNode).TIME
|
newLoraNode.TIME = loraNode.(LoraNode).TIME
|
||||||
newLoraNode.CHECK_TIME= false
|
newLoraNode.CHECK_TIME = false
|
||||||
|
|
||||||
newLoraNode.LOCATION_TYPE = loraNode.(LoraNode).LOCATION_TYPE
|
newLoraNode.LOCATION_TYPE = loraNode.(LoraNode).LOCATION_TYPE
|
||||||
newLoraNode.LOCATION_CODE = loraNode.(LoraNode).LOCATION_CODE
|
newLoraNode.LOCATION_CODE = loraNode.(LoraNode).LOCATION_CODE
|
||||||
newLoraNode.LOCATION_DATA = loraNode.(LoraNode).LOCATION_DATA
|
newLoraNode.LOCATION_DATA = loraNode.(LoraNode).LOCATION_DATA
|
||||||
newLoraNode.DEVICE = loraNode.(LoraNode).DEVICE
|
newLoraNode.DEVICE = loraNode.(LoraNode).DEVICE
|
||||||
if(!Contains(newLoraNode.LORA_GWS,loragwip)){
|
if !Contains(newLoraNode.LORA_GWS, loragwip) {
|
||||||
newLoraNode.LORA_GWS = append(newLoraNode.LORA_GWS,loragwip)
|
newLoraNode.LORA_GWS = append(newLoraNode.LORA_GWS, loragwip)
|
||||||
}
|
}
|
||||||
loraNodeMap.Store(adr,newLoraNode)
|
loraNodeMap.Store(adr, newLoraNode)
|
||||||
|
|
||||||
changeDataV2(newLoraNode)
|
changeDataV2(newLoraNode)
|
||||||
}else{
|
} else {
|
||||||
// loraNode.(LoraNode).CHECK_TIME = true
|
// loraNode.(LoraNode).CHECK_TIME = true
|
||||||
|
|
||||||
newLoraNode := LoraNode{}
|
newLoraNode := LoraNode{}
|
||||||
newLoraNode.CURRENT_DATA = loraNode.(LoraNode).CURRENT_DATA
|
newLoraNode.CURRENT_DATA = loraNode.(LoraNode).CURRENT_DATA
|
||||||
newLoraNode.TIME = time.Now()
|
newLoraNode.TIME = time.Now()
|
||||||
newLoraNode.CHECK_TIME= true
|
newLoraNode.CHECK_TIME = true
|
||||||
|
|
||||||
newLoraNode.LOCATION_TYPE = loraNode.(LoraNode).LOCATION_TYPE
|
newLoraNode.LOCATION_TYPE = loraNode.(LoraNode).LOCATION_TYPE
|
||||||
newLoraNode.LOCATION_CODE = loraNode.(LoraNode).LOCATION_CODE
|
newLoraNode.LOCATION_CODE = loraNode.(LoraNode).LOCATION_CODE
|
||||||
newLoraNode.LOCATION_DATA = loraNode.(LoraNode).LOCATION_DATA
|
newLoraNode.LOCATION_DATA = loraNode.(LoraNode).LOCATION_DATA
|
||||||
newLoraNode.DEVICE = loraNode.(LoraNode).DEVICE
|
newLoraNode.DEVICE = loraNode.(LoraNode).DEVICE
|
||||||
if(!Contains(newLoraNode.LORA_GWS,loragwip)){
|
if !Contains(newLoraNode.LORA_GWS, loragwip) {
|
||||||
newLoraNode.LORA_GWS = append(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
|
newLoraNode.CURRENT_DATA = current
|
||||||
changeDataV2(newLoraNode)
|
changeDataV2(newLoraNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
loraNodeMap.Store(adr,newLoraNode)
|
loraNodeMap.Store(adr, newLoraNode)
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}else if datatype==3{
|
} else if datatype == 3 {
|
||||||
var R_data P1004_6
|
var R_data P1004_6
|
||||||
R_data.CODE = 1005
|
R_data.CODE = 1005
|
||||||
R_data.ID = adr
|
R_data.ID = adr
|
||||||
|
@ -429,20 +428,20 @@ func dealDatav3(data []byte,loragwip string) string{
|
||||||
R_data.VERSION = "yunhorn_door_c_v1"
|
R_data.VERSION = "yunhorn_door_c_v1"
|
||||||
R_data.ONLINE = true
|
R_data.ONLINE = true
|
||||||
R_data.DATA = make(map[string]interface{})
|
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_bufTmp, _ := json.Marshal(R_data)
|
||||||
data_buf := string(data_bufTmp)
|
data_buf := string(data_bufTmp)
|
||||||
go post_to_server(data_buf)
|
go post_to_server(data_buf)
|
||||||
|
|
||||||
}else if datatype==4{
|
} else if datatype == 4 {
|
||||||
buffer := new(bytes.Buffer)
|
buffer := new(bytes.Buffer)
|
||||||
|
|
||||||
// log.Println("data[9]",int64(data[9]))
|
// log.Println("data[9]",int64(data[9]))
|
||||||
// log.Println("data[10]",int64(data[10]))
|
// 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("-")
|
buffer.WriteString("-")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,12 +450,11 @@ func dealDatav3(data []byte,loragwip string) string{
|
||||||
buffer.WriteString(".")
|
buffer.WriteString(".")
|
||||||
wdfh := int(data[10])
|
wdfh := int(data[10])
|
||||||
wdint2 := strconv.FormatInt(int64(data[8]&0xff), 10)
|
wdint2 := strconv.FormatInt(int64(data[8]&0xff), 10)
|
||||||
if wdfh<10{
|
if wdfh < 10 {
|
||||||
buffer.WriteString("0")
|
buffer.WriteString("0")
|
||||||
}
|
}
|
||||||
buffer.WriteString(wdint2)
|
buffer.WriteString(wdint2)
|
||||||
|
|
||||||
|
|
||||||
// log.Println("aqdata|wdfh",data[6])
|
// log.Println("aqdata|wdfh",data[6])
|
||||||
|
|
||||||
wddata := buffer.String()
|
wddata := buffer.String()
|
||||||
|
@ -468,7 +466,7 @@ func dealDatav3(data []byte,loragwip string) string{
|
||||||
buffer.WriteString(sdint1)
|
buffer.WriteString(sdint1)
|
||||||
buffer.WriteString(".")
|
buffer.WriteString(".")
|
||||||
sdint2 := strconv.FormatInt(int64(data[10]&0xff), 10)
|
sdint2 := strconv.FormatInt(int64(data[10]&0xff), 10)
|
||||||
if wdfh<10{
|
if wdfh < 10 {
|
||||||
buffer.WriteString("0")
|
buffer.WriteString("0")
|
||||||
}
|
}
|
||||||
buffer.WriteString(sdint2)
|
buffer.WriteString(sdint2)
|
||||||
|
@ -482,7 +480,7 @@ func dealDatav3(data []byte,loragwip string) string{
|
||||||
buffer.WriteString(nh3int1)
|
buffer.WriteString(nh3int1)
|
||||||
buffer.WriteString(".")
|
buffer.WriteString(".")
|
||||||
nh3int2 := strconv.Itoa(int(data[12]))
|
nh3int2 := strconv.Itoa(int(data[12]))
|
||||||
if int64(data[12])<10{
|
if int64(data[12]) < 10 {
|
||||||
buffer.WriteString("0")
|
buffer.WriteString("0")
|
||||||
}
|
}
|
||||||
buffer.WriteString(nh3int2)
|
buffer.WriteString(nh3int2)
|
||||||
|
@ -490,13 +488,12 @@ func dealDatav3(data []byte,loragwip string) string{
|
||||||
|
|
||||||
// log.Println("aqdata|nh3",nh3data)
|
// log.Println("aqdata|nh3",nh3data)
|
||||||
|
|
||||||
|
|
||||||
buffer = new(bytes.Buffer)
|
buffer = new(bytes.Buffer)
|
||||||
h2sint1 := strconv.Itoa(int(data[13]))
|
h2sint1 := strconv.Itoa(int(data[13]))
|
||||||
buffer.WriteString(h2sint1)
|
buffer.WriteString(h2sint1)
|
||||||
buffer.WriteString(".")
|
buffer.WriteString(".")
|
||||||
h2sint2 := strconv.Itoa(int(data[14]))
|
h2sint2 := strconv.Itoa(int(data[14]))
|
||||||
if int64(data[14])<10{
|
if int64(data[14]) < 10 {
|
||||||
buffer.WriteString("0")
|
buffer.WriteString("0")
|
||||||
}
|
}
|
||||||
buffer.WriteString(h2sint2)
|
buffer.WriteString(h2sint2)
|
||||||
|
@ -508,7 +505,7 @@ func dealDatav3(data []byte,loragwip string) string{
|
||||||
buffer.WriteString(ch2o1)
|
buffer.WriteString(ch2o1)
|
||||||
buffer.WriteString(".")
|
buffer.WriteString(".")
|
||||||
ch2o2 := strconv.Itoa(int(data[16]))
|
ch2o2 := strconv.Itoa(int(data[16]))
|
||||||
if int64(data[16])<10{
|
if int64(data[16]) < 10 {
|
||||||
buffer.WriteString("0")
|
buffer.WriteString("0")
|
||||||
}
|
}
|
||||||
buffer.WriteString(ch2o2)
|
buffer.WriteString(ch2o2)
|
||||||
|
@ -517,7 +514,7 @@ func dealDatav3(data []byte,loragwip string) string{
|
||||||
// ch2o := uint32(data[14])*256+uint32(data[15])
|
// ch2o := uint32(data[14])*256+uint32(data[15])
|
||||||
// log.Println("aqdata|ch2o",ch2o)
|
// 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)
|
// log.Println("aqdata|co2data",co2data)
|
||||||
|
|
||||||
tvocdata := data[19]
|
tvocdata := data[19]
|
||||||
|
@ -525,17 +522,17 @@ func dealDatav3(data []byte,loragwip string) string{
|
||||||
|
|
||||||
// log.Println("pm25data1",data[19])
|
// log.Println("pm25data1",data[19])
|
||||||
// log.Println("pm25data2",data[20])
|
// 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("aqdata|pm25data",pm25data)
|
||||||
|
|
||||||
// log.Println("pm10data1",data[21])
|
// log.Println("pm10data1",data[21])
|
||||||
// log.Println("pm10data2",data[22])
|
// 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)
|
// log.Println("aqdata|pm10data",pm10data)
|
||||||
|
|
||||||
//wdfh
|
//wdfh
|
||||||
log.Printf("aqdata|wddata|sddata|nh3data|h2sdata|ch2o|co2data|tvocdata|pm25data|pm10data")
|
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
|
var R_data P1004_6
|
||||||
R_data.CODE = 1005
|
R_data.CODE = 1005
|
||||||
|
@ -545,16 +542,16 @@ func dealDatav3(data []byte,loragwip string) string{
|
||||||
R_data.VERSION = "yunhorn_kq_c_v1"
|
R_data.VERSION = "yunhorn_kq_c_v1"
|
||||||
R_data.ONLINE = true
|
R_data.ONLINE = true
|
||||||
R_data.DATA = make(map[string]interface{})
|
R_data.DATA = make(map[string]interface{})
|
||||||
R_data.DATA["temperature"]=wddata
|
R_data.DATA["temperature"] = wddata
|
||||||
R_data.DATA["humidity"]=sddata
|
R_data.DATA["humidity"] = sddata
|
||||||
|
|
||||||
R_data.DATA["nh3"]=nh3data
|
R_data.DATA["nh3"] = nh3data
|
||||||
R_data.DATA["h2s"]=h2sdata
|
R_data.DATA["h2s"] = h2sdata
|
||||||
R_data.DATA["ch2o"]=ch2o
|
R_data.DATA["ch2o"] = ch2o
|
||||||
R_data.DATA["co2"]=co2data
|
R_data.DATA["co2"] = co2data
|
||||||
R_data.DATA["tvoc"]=tvocdata
|
R_data.DATA["tvoc"] = tvocdata
|
||||||
R_data.DATA["pm25"]=pm25data
|
R_data.DATA["pm25"] = pm25data
|
||||||
R_data.DATA["pm10"]=pm10data
|
R_data.DATA["pm10"] = pm10data
|
||||||
|
|
||||||
data_bufTmp, _ := json.Marshal(R_data)
|
data_bufTmp, _ := json.Marshal(R_data)
|
||||||
data_buf := string(data_bufTmp)
|
data_buf := string(data_bufTmp)
|
||||||
|
@ -574,22 +571,22 @@ func changeData(num int, device Device) {
|
||||||
DEVICEDATAS.DATA[demoDevice.VERSION+"_"+strconv.Itoa(num)] = device
|
DEVICEDATAS.DATA[demoDevice.VERSION+"_"+strconv.Itoa(num)] = device
|
||||||
}
|
}
|
||||||
|
|
||||||
func changeDataV2(loraNode LoraNode){
|
func changeDataV2(loraNode LoraNode) {
|
||||||
// log.Println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
|
// log.Println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
|
||||||
// log.Println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@00000:",loraNode)
|
// log.Println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@00000:",loraNode)
|
||||||
// log.Println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111:",DEVICEDATAS.DATA[loraNode.DEVICE])
|
// log.Println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@11111:",DEVICEDATAS.DATA[loraNode.DEVICE])
|
||||||
// DEVICEDATAS.RLock()
|
// DEVICEDATAS.RLock()
|
||||||
DEVICEDATAS.Lock()
|
DEVICEDATAS.Lock()
|
||||||
if DEVICEDATAS.DATA !=nil{
|
if DEVICEDATAS.DATA != nil {
|
||||||
_,ok := DEVICEDATAS.DATA[loraNode.DEVICE]
|
_, ok := DEVICEDATAS.DATA[loraNode.DEVICE]
|
||||||
if ok {
|
if ok {
|
||||||
DEVICEDATAS.DATA[loraNode.DEVICE].DATA[loraNode.LOCATION_DATA] = loraNode.CURRENT_DATA
|
DEVICEDATAS.DATA[loraNode.DEVICE].DATA[loraNode.LOCATION_DATA] = loraNode.CURRENT_DATA
|
||||||
log.Println("yunhorndeug.push.data.change:",DEVICEDATAS.DATA[loraNode.DEVICE])
|
log.Println("yunhorndeug.push.data.change:", DEVICEDATAS.DATA[loraNode.DEVICE])
|
||||||
}else{
|
} else {
|
||||||
log.Println("changeDataV2.DEVICEDATAS load not ok:",loraNode.DEVICE)
|
log.Println("changeDataV2.DEVICEDATAS load not ok:", loraNode.DEVICE)
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
log.Println("changeDataV2.DEVICEDATAS not init:",loraNode.DEVICE)
|
log.Println("changeDataV2.DEVICEDATAS not init:", loraNode.DEVICE)
|
||||||
}
|
}
|
||||||
DEVICEDATAS.Unlock()
|
DEVICEDATAS.Unlock()
|
||||||
// log.Println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
|
// log.Println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
|
||||||
|
@ -631,10 +628,23 @@ var rl_data EventNotificationAlert
|
||||||
|
|
||||||
// 提交人流量api
|
// 提交人流量api
|
||||||
func get_renliu_api(c *gin.Context) {
|
func get_renliu_api(c *gin.Context) {
|
||||||
|
|
||||||
|
var rl_data_tmp EventNotificationAlert
|
||||||
|
|
||||||
err := c.Bind(&rl_data)
|
err := c.Bind(&rl_data)
|
||||||
if conf.DEBUG {
|
if conf.DEBUG {
|
||||||
log.Println(rl_data)
|
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)
|
check(err)
|
||||||
send_data(1004)
|
send_data(1004)
|
||||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "data": rl_data})
|
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "data": rl_data})
|
||||||
|
@ -779,11 +789,11 @@ func seat_api(c *gin.Context) {
|
||||||
//获取到设备版本
|
//获取到设备版本
|
||||||
version, num := arr[0], arr[1]
|
version, num := arr[0], arr[1]
|
||||||
|
|
||||||
if version=="null" || num == "null"{
|
if version == "null" || num == "null" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if DEVICEDATAS.DATA[version+"_"+num].DATA != nil {
|
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 {
|
for k, j := range i.DATA {
|
||||||
//log.Println("@@@@@@@@@@@@@@@@@@@@@@@@@@,i.DATA-j",j)
|
//log.Println("@@@@@@@@@@@@@@@@@@@@@@@@@@,i.DATA-j",j)
|
||||||
// log.Println("============================devicedatas.data:", DEVICEDATAS.DATA[version+"_"+num].DATA)
|
// log.Println("============================devicedatas.data:", DEVICEDATAS.DATA[version+"_"+num].DATA)
|
||||||
|
@ -825,7 +835,7 @@ func get_seat_device_data(id string) []string {
|
||||||
for _, i := range conf.DEVICES_LIST {
|
for _, i := range conf.DEVICES_LIST {
|
||||||
if id == i[0] {
|
if id == i[0] {
|
||||||
data[0], data[1] = i[2], i[3]
|
data[0], data[1] = i[2], i[3]
|
||||||
log.Println("get_seat_device_data",data)
|
log.Println("get_seat_device_data", data)
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
data[0], data[1] = "null", "null"
|
data[0], data[1] = "null", "null"
|
||||||
|
|
|
@ -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