完善下行指令下发控制逻辑,配置文件更新为yaml
This commit is contained in:
parent
b3b45e1397
commit
f6588955f3
|
@ -26,19 +26,36 @@ lora_nodes:
|
|||
#location_data
|
||||
#current_data 当前状态数据
|
||||
#device 设备版本号
|
||||
- {"adr":"dc390000","location_type":"changing_desk","location_code":"spao","location_data":"data13","current_data":0,"device":"yunhorn_kq_d_v1_1"}
|
||||
- {"adr":"0c521618","location_type":"changing_desk","location_code":"spao","location_data":"data6","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c473018","location_type":"changing_desk","location_code":"spao","location_data":"data7","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c451d14","location_type":"changing_desk","location_code":"spao","location_data":"data3","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c471714","location_type":"changing_desk","location_code":"spao","location_data":"data4","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c093e17","location_type":"changing_desk","location_code":"spao","location_data":"data5","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c3e3c14","location_type":"changing_desk","location_code":"spao","location_data":"data2","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c3c1214","location_type":"changing_desk","location_code":"spao","location_data":"data8","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c3d3c14","location_type":"changing_desk","location_code":"spao","location_data":"data10","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c3b4f14","location_type":"changing_desk","location_code":"spao","location_data":"data9","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c360514","location_type":"changing_desk","location_code":"spao","location_data":"data1","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"853c0000","location_type":"changing_desk","location_code":"spao","location_data":"data11","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c0a2017",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c521618","location_type":"","location_code":"spao","location_data":"data13","current_data":0,"device":"yunhorn_kq_d_v1_1"}
|
||||
- {"adr":"fd3c0000","location_type":"","location_code":"spao","location_data":"data6","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c451d14","location_type":"","location_code":"spao","location_data":"data7","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c0a2017","location_type":"","location_code":"spao","location_data":"data3","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c093e17","location_type":"","location_code":"spao","location_data":"data4","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"d93c0000","location_type":"","location_code":"spao","location_data":"data5","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c3c1214","location_type":"","location_code":"spao","location_data":"data2","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c3d3c14","location_type":"","location_code":"spao","location_data":"data10","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c3b4f14","location_type":"","location_code":"spao","location_data":"data9","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"4f3c0000","location_type":"","location_code":"spao","location_data":"data1","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c471714","location_type":"","location_code":"spao","location_data":"data11","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"c53a0000",location_type":"","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"} "lora_nodes":[
|
||||
- {"adr":"083c0000",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"} "lora_nodes":[
|
||||
- {"adr":"f73b0000",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"} "lora_nodes":[
|
||||
- {"adr":"123c0000",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"} "lora_nodes":[
|
||||
- {"adr":"a33a0000",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"} "lora_nodes":[
|
||||
- {"adr":"103c0000",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"} "lora_nodes":[
|
||||
- {"adr":"0c3a3117",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"} "lora_nodes":[
|
||||
- {"adr":"013a0000",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"} "lora_nodes":[
|
||||
- {"adr":"063d0000",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"} "lora_nodes":[
|
||||
- {"adr":"f53b0000",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"} "lora_nodes":[
|
||||
- {"adr":"0c360514",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"} "lora_nodes":[
|
||||
- {"adr":"1c3c0000",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"} "lora_nodes":[
|
||||
- {"adr":"d4400000",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"} "lora_nodes":[
|
||||
- {"adr":"0c480a17",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"} "lora_nodes":[
|
||||
- {"adr":"0c495017",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"} "lora_nodes":[
|
||||
- {"adr":"0c073f18",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"} "lora_nodes":[
|
||||
- {"adr":"0c0c1d18",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"} "lora_nodes":[
|
||||
- {"adr":"0c3b1518",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"} "lora_nodes":[
|
||||
- {"adr":"0c4c4c17",location_type":"","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"} "lora_nodes":[
|
||||
devices_list:
|
||||
# num0 设备ID号
|
||||
- ["4E5D52DD-EB81-43C0-A2B6-04E432412EBA", "loraport", "yunhorn_kgl_l_v1", "1"]
|
||||
|
@ -89,8 +106,8 @@ api_port: 10086 #本地web api port
|
|||
pro_category: 1
|
||||
syn_data: false
|
||||
syn_extension_Time: false
|
||||
record_log_path: "/usr/local/dpark" #无线原始数据收集的log目录
|
||||
mqtt_open: true
|
||||
mqtt_broker: "tcp://120.77.206.101:1883"
|
||||
record_log_path: "/usr/local/dpark" #/usr/local/dpark #无线原始数据收集的log目录
|
||||
mqtt_open: false
|
||||
mqtt_broker: "tcp://localhost:1883"
|
||||
mqtt_username: ""
|
||||
mqtt_password: ""
|
|
@ -0,0 +1,96 @@
|
|||
gateway_info: #本地网关信息
|
||||
id: F23FACD2-7D85-4FCC-88E3-C5B78931A26D #网关ID
|
||||
version: yunhorn_gw_c_v1 #网关版本
|
||||
location: [113.960347, 22.54143] #本地网关经纬度 目前暂无用
|
||||
config:
|
||||
-
|
||||
id: 7BB22E6A-ED0D-4161-8370-6B722D3683B7 #配置采集器ID
|
||||
version: yunhorn_kgl_c16_v1 #采集器版本号
|
||||
data:
|
||||
- ["男厕位", 1] #key:类型 value:数据索引号
|
||||
- ["男厕位", 2]
|
||||
- ["女厕位", 1]
|
||||
- ["女厕位", 2]
|
||||
- ["男厕位", 3]
|
||||
- ["男厕位", 4]
|
||||
- ["男厕位", 5]
|
||||
- ["男厕位", 6]
|
||||
- ["男厕位", 7]
|
||||
- ["男厕位", 8]
|
||||
- ["女厕位", 3]
|
||||
- ["女厕位", 4]
|
||||
lora_nodes:
|
||||
#adr:设备地址
|
||||
#资源位类型 尿布台 吸顶
|
||||
# location_code 目前暂无用
|
||||
#location_data
|
||||
#current_data 当前状态数据
|
||||
#device 设备版本号
|
||||
- {"adr":"0c0d3118","location_type":"changing_desk","location_code":"spao","location_data":"data13","current_data":0,"device":"yunhorn_kq_d_v1_1"}
|
||||
- {"adr":"0c521618","location_type":"changing_desk","location_code":"spao","location_data":"data6","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c473018","location_type":"changing_desk","location_code":"spao","location_data":"data7","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c451d14","location_type":"changing_desk","location_code":"spao","location_data":"data3","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c471714","location_type":"changing_desk","location_code":"spao","location_data":"data4","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c093e17","location_type":"changing_desk","location_code":"spao","location_data":"data5","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c3e3c14","location_type":"changing_desk","location_code":"spao","location_data":"data2","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c3c1214","location_type":"changing_desk","location_code":"spao","location_data":"data8","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c3d3c14","location_type":"changing_desk","location_code":"spao","location_data":"data10","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c3b4f14","location_type":"changing_desk","location_code":"spao","location_data":"data9","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c360514","location_type":"changing_desk","location_code":"spao","location_data":"data1","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"853c0000","location_type":"changing_desk","location_code":"spao","location_data":"data11","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
- {"adr":"0c0a2017",location_type":"changing_desk","location_code":"spao","location_data":"data12","current_data":0,"device":"yunhorn_kgl_c16_v1_1"}
|
||||
devices_list:
|
||||
# num0 设备ID号
|
||||
- ["4E5D52DD-EB81-43C0-A2B6-04E432412EBA", "loraport", "yunhorn_kgl_l_v1", "1"]
|
||||
- ["deb03e28-ddcb-4e5d-aa31-d870a1f0f09b", "loraport", "yunhorn_kgl_c8_v1", "1"]
|
||||
- ["7BB22E6A-ED0D-4161-8370-6B722D3683B7", "loraport", "yunhorn_kgl_c16_v1", "1"]
|
||||
- ["8E146028-E1B1-4AC9-8F47-01376A22CB35", "loraport", "yunhorn_kgl_c8_v1", "2"]
|
||||
serialports_list:
|
||||
loraport: {"com": "/dev/cu.wchusbserial141420","bauds": 115200,"size": 8,"parity": "E","stopbits": 1,"readtimeout": 100,"note": "lorawan"}
|
||||
rs485devices:
|
||||
15394892-E8B0-4FF2-BC35-1BF380BD1B68:
|
||||
version: yunhorn_xsy_c_v1
|
||||
num: 1
|
||||
command: #采集命令
|
||||
- [8, 3, 0, 1, 0, 2, 149, 82]
|
||||
EC13C2D9-6A93-4894-BB5B-89BDAA786D8A:
|
||||
version: yunhorn_kgl_c8_v1
|
||||
num: 1
|
||||
command: #采集盒对应位置的采集命令
|
||||
- [1, 2, 0, 0, 0, 1, 185, 202]
|
||||
- [1, 2, 0, 1, 0, 1, 232, 10]
|
||||
- [1, 2, 0, 2, 0, 1, 24, 10]
|
||||
- [1, 2, 0, 3, 0, 1, 73, 202]
|
||||
- [1, 2, 0, 4, 0, 1, 248, 11]
|
||||
- [1, 2, 0, 5, 0, 1, 169, 203]
|
||||
- [1, 2, 0, 6, 0, 1, 89, 203]
|
||||
- [1, 2, 0, 7, 0, 1, 8, 11]
|
||||
00DD66A6-378E-450D-98AA-44AC02741980:
|
||||
version: yunhorn_kgl_c16_v1
|
||||
num": 1,
|
||||
command:
|
||||
- [3, 2, 0, 0, 0, 16, 120, 36]
|
||||
loradevices_list:
|
||||
4E5D52DD-EB81-43C0-A2B6-04E432412EBA:
|
||||
version: yunhorn_zjj_l_v1
|
||||
num: 1
|
||||
command:
|
||||
- [85, 2, 242, 170]
|
||||
iconurl: "http://192.168.3.188/icons/"
|
||||
websocketurl: ["192.168.3.216:8080", "/echo"]
|
||||
post_to_server: "https://smartoilets.cn/socketServer/statis/push" #数据收集服务器
|
||||
debug: true #是否打印debug log
|
||||
openserial: false #是否采集串口数据
|
||||
open_tcp_server: true #是否开启TCP端口接收无线数据
|
||||
check_serial: true
|
||||
dpark_location: "spaoDevs"
|
||||
tcp_port: 10090
|
||||
api_port: 10086 #本地web api port
|
||||
pro_category: 1
|
||||
syn_data: false
|
||||
syn_extension_Time: false
|
||||
record_log_path: "/Users/lanren/Documents/repositorys/git/yunhorn_gateway/logs" #无线原始数据收集的log目录
|
||||
mqtt_open: true
|
||||
mqtt_broker: "tcp://120.77.206.101:1883"
|
||||
mqtt_username: ""
|
||||
mqtt_password: ""
|
|
@ -27,3 +27,13 @@ const (
|
|||
//混合
|
||||
PRO_CATEGORY_HYBRID = 2
|
||||
)
|
||||
|
||||
|
||||
func Contains(s []string, e string) bool {
|
||||
for _, a := range s {
|
||||
if a == e {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
|
@ -107,6 +107,7 @@ type LoraNode struct{
|
|||
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
|
||||
|
@ -120,6 +121,12 @@ var nodeUpdateMap sync.Map
|
|||
//sensor data update map
|
||||
var sensorUpdateMap sync.Map
|
||||
|
||||
//key:loragateway ip value:conn object
|
||||
var loragwMap sync.Map
|
||||
|
||||
//key:字符串addr value:byte[] addr
|
||||
var sensorMap sync.Map
|
||||
|
||||
//log channel
|
||||
var logch = make(chan []byte)
|
||||
|
||||
|
|
2
main.go
2
main.go
|
@ -7,7 +7,6 @@ import (
|
|||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
)
|
||||
|
||||
var err error
|
||||
|
@ -134,6 +133,7 @@ func main() {
|
|||
|
||||
for {
|
||||
conn, err := listener.Accept()
|
||||
loragwMap.Store(conn.RemoteAddr().String(),conn)
|
||||
if err != nil {
|
||||
log.Printf("accept fail, err: %v\n", err)
|
||||
continue
|
||||
|
|
98
router.go
98
router.go
|
@ -10,7 +10,6 @@ import (
|
|||
"math"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"bytes"
|
||||
|
@ -39,6 +38,8 @@ func gw_router() {
|
|||
|
||||
v1.GET("/getConf")
|
||||
|
||||
v1.GET("/sendCommand",sendCommand)
|
||||
|
||||
}
|
||||
|
||||
api_port := strconv.Itoa(conf.APIPORT)
|
||||
|
@ -53,13 +54,72 @@ type DparkConf struct {
|
|||
ExtensionOutTime2 int `json:"out2"`
|
||||
}
|
||||
|
||||
func sendCommand(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;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
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(addr)
|
||||
log.Println(command)
|
||||
log.Println("will send commands ",commands)
|
||||
c.JSON(http.StatusOK, gin.H{"status": http.StatusOK, "msg": "success"})
|
||||
}
|
||||
|
||||
var dparkConf DparkConf
|
||||
|
||||
var connTest net.Conn
|
||||
|
||||
|
||||
|
||||
|
||||
//获取数据防抖配置时间
|
||||
func getConf() {
|
||||
resp, err := http.Get("https://smartoilets.cn/socketServer/dpark/getConf")
|
||||
|
@ -137,7 +197,7 @@ func push(c *gin.Context) {
|
|||
|
||||
}
|
||||
|
||||
func dealDatav3(data []byte) string{
|
||||
func dealDatav3(data []byte,loragwip string) string{
|
||||
|
||||
nowtime := time.Now()
|
||||
|
||||
|
@ -210,8 +270,6 @@ func dealDatav3(data []byte) string{
|
|||
|
||||
// log.Println("readyData:",readyData.String())
|
||||
|
||||
// go pushCODE1007(data)
|
||||
|
||||
//默认当前无人占用
|
||||
current := 0
|
||||
|
||||
|
@ -254,6 +312,10 @@ func dealDatav3(data []byte) string{
|
|||
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)
|
||||
|
||||
|
@ -315,6 +377,9 @@ func dealDatav3(data []byte) string{
|
|||
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)
|
||||
|
||||
changeDataV2(newLoraNode)
|
||||
|
@ -330,6 +395,9 @@ func dealDatav3(data []byte) string{
|
|||
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 (datatype==2 && (extensionInTime2<=0 || extensionOutTime2<=0)){
|
||||
newLoraNode.CURRENT_DATA = current
|
||||
|
@ -486,22 +554,6 @@ func dealDatav3(data []byte) string{
|
|||
return ""
|
||||
}
|
||||
|
||||
//发送code1007数据到云端
|
||||
func pushCODE1007(data string) {
|
||||
|
||||
//resp, err := http.PostForm("https://smartoilets.cn/socketServer/static/push",
|
||||
// url.Values{"d": {data}})
|
||||
|
||||
resp, err := http.Post("https://smartoilets.cn/socketServer/statis/push",
|
||||
"application/x-www-form-urlencoded",
|
||||
strings.NewReader("d="+data))
|
||||
if err != nil {
|
||||
log.Print("yunhorndebug.pushCODE1007.err", err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
}
|
||||
|
||||
func changeData(num int, device Device) {
|
||||
log.Println("device:", device)
|
||||
DEVICEDATAS.DATA[demoDevice.VERSION+"_"+strconv.Itoa(num)] = device
|
||||
|
|
17
tcpserver.go
17
tcpserver.go
|
@ -14,6 +14,8 @@ import (
|
|||
|
||||
)
|
||||
|
||||
|
||||
|
||||
func handleConn(conn net.Conn) {
|
||||
|
||||
if connTest==nil{
|
||||
|
@ -86,6 +88,8 @@ func readConn(conn net.Conn, readChan chan<- []byte, stopChan chan<- bool) {
|
|||
// log.Println("yunhorndeug.push.data.tcp.reqLen|data",reqLen,data)
|
||||
log.Println("$$$$$$$$$$$$$$$$$$$$$$$$$",data[:reqLen])
|
||||
now := time.Now()
|
||||
// log.Println("yunhorndeug.push.data.tcp.begin handleConn,cliendAddr:", conn.RemoteAddr())
|
||||
|
||||
for i, b := range data[:reqLen] {
|
||||
|
||||
if reqLen<7{
|
||||
|
@ -113,14 +117,17 @@ func readConn(conn net.Conn, readChan chan<- []byte, stopChan chan<- bool) {
|
|||
//尿布台数据,地址1位 数据2位
|
||||
dataType := data[i+1]
|
||||
|
||||
if dataType!=1 && dataType!=2 && dataType!=3 && dataType!=4{
|
||||
//0是通用类型
|
||||
if dataType!=0 && dataType!=1 && dataType!=2 && dataType!=3 && dataType!=4{
|
||||
continue;
|
||||
}
|
||||
|
||||
values := make([]byte,0)
|
||||
|
||||
|
||||
if dataType == 1 {
|
||||
if dataType ==0{
|
||||
continueCount = 2
|
||||
end = 3
|
||||
}else if dataType == 1 {
|
||||
|
||||
continueCount = 3
|
||||
end = 4
|
||||
|
@ -226,13 +233,15 @@ func readConn(conn net.Conn, readChan chan<- []byte, stopChan chan<- bool) {
|
|||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
sensorMap.Store(buffer.String(),addrs)
|
||||
|
||||
|
||||
buffer = new(bytes.Buffer)
|
||||
|
||||
go write_log_channel(data[i-4:i+end])
|
||||
|
||||
go dealDatav3(data[i-4:i+end])
|
||||
go dealDatav3(data[i-4:i+end],conn.RemoteAddr().String())
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue