do_send_data.go
This commit is contained in:
parent
af77f96ea8
commit
8b4cac6a12
|
@ -14,7 +14,6 @@ import (
|
||||||
"k8s.io/apimachinery/pkg/util/yaml"
|
"k8s.io/apimachinery/pkg/util/yaml"
|
||||||
|
|
||||||
"bytes"
|
"bytes"
|
||||||
// "k8s.io/apimachinery/pkg/runtime"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
@ -138,6 +137,10 @@ var loraNodeMap sync.Map
|
||||||
var db, _ = sql.Open("sqlite3", "./db/gateway.db")
|
var db, _ = sql.Open("sqlite3", "./db/gateway.db")
|
||||||
|
|
||||||
|
|
||||||
|
type pluginConfig struct {
|
||||||
|
PodNodeSelectorPluginConfig map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
// 加载配置文件
|
// 加载配置文件
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
|
@ -163,7 +166,18 @@ func init() {
|
||||||
reader := bytes.NewReader(configData)
|
reader := bytes.NewReader(configData)
|
||||||
// ext := runtime.RawExtension{}
|
// ext := runtime.RawExtension{}
|
||||||
d := yaml.NewYAMLOrJSONDecoder(reader, 4096)
|
d := yaml.NewYAMLOrJSONDecoder(reader, 4096)
|
||||||
if err := d.Decode(&conf); err != nil {
|
|
||||||
|
// defaultConfig := &pluginConfig{}
|
||||||
|
|
||||||
|
// if err := d.Decode(&defaultConfig); err != nil {
|
||||||
|
// check(err)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// log.Println("======================yaml.data:",defaultConfig)
|
||||||
|
// return;
|
||||||
|
|
||||||
|
if err = d.Decode(&conf); err != nil {
|
||||||
|
// log.Println("conf parse error")
|
||||||
check(err)
|
check(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
main.go
1
main.go
|
@ -71,6 +71,7 @@ func main() {
|
||||||
// err = json.NewDecoder(string(ext.Raw)).Decode(&conf)
|
// err = json.NewDecoder(string(ext.Raw)).Decode(&conf)
|
||||||
// check(err)
|
// check(err)
|
||||||
// log.Println(conf.OPENTCPSETVER)
|
// log.Println(conf.OPENTCPSETVER)
|
||||||
|
|
||||||
go gw_router()
|
go gw_router()
|
||||||
go serial_run()
|
go serial_run()
|
||||||
c := cron.New()
|
c := cron.New()
|
||||||
|
|
2
mq.go
2
mq.go
|
@ -61,8 +61,10 @@ func init() {
|
||||||
b := strconv.Itoa(rand.Intn(100))
|
b := strconv.Itoa(rand.Intn(100))
|
||||||
clientId := "unit"+b
|
clientId := "unit"+b
|
||||||
opts := mqtt.NewClientOptions().AddBroker(conf.MQTT_BROKER).SetClientID(clientId)
|
opts := mqtt.NewClientOptions().AddBroker(conf.MQTT_BROKER).SetClientID(clientId)
|
||||||
|
if conf.MQTT_USERNAME!="" && conf.MQTT_PASSWORD !=""{
|
||||||
opts.SetUsername(conf.MQTT_USERNAME)
|
opts.SetUsername(conf.MQTT_USERNAME)
|
||||||
opts.SetPassword(conf.MQTT_PASSWORD)
|
opts.SetPassword(conf.MQTT_PASSWORD)
|
||||||
|
}
|
||||||
|
|
||||||
opts.SetKeepAlive(time.Duration(conf.MQTT_KEEPALIVE) * time.Second)
|
opts.SetKeepAlive(time.Duration(conf.MQTT_KEEPALIVE) * time.Second)
|
||||||
opts.SetDefaultPublishHandler(onMessageReceived)
|
opts.SetDefaultPublishHandler(onMessageReceived)
|
||||||
|
|
18
router.go
18
router.go
|
@ -35,10 +35,19 @@ func gw_router() {
|
||||||
v1.GET("/seat/:id", seat_api)
|
v1.GET("/seat/:id", seat_api)
|
||||||
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/*")
|
||||||
|
|
||||||
|
opsV1 := router.Group("/ops/v1")
|
||||||
|
{
|
||||||
|
opsV1.GET("/index", func(c *gin.Context) {
|
||||||
|
c.HTML(http.StatusOK, "index.html", gin.H{
|
||||||
|
"title": "hello Go",
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,13 +237,14 @@ func dealDatav3(data []byte,loragwip string) string{
|
||||||
cs2001 := data[6]
|
cs2001 := data[6]
|
||||||
|
|
||||||
var R_data P1004_6
|
var R_data P1004_6
|
||||||
R_data.CODE = 1008
|
R_data.CODE = 1005
|
||||||
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
|
||||||
|
|
||||||
datatypeStr := strconv.FormatInt(int64(data[5]&0xff), 16)
|
datatypeStr := strconv.FormatInt(int64(data[5]&0xff), 16)
|
||||||
|
|
||||||
|
@ -262,7 +272,7 @@ func dealDatav3(data []byte,loragwip string) string{
|
||||||
readyData.WriteString("*")
|
readyData.WriteString("*")
|
||||||
readyData.WriteString(tofTmp)
|
readyData.WriteString(tofTmp)
|
||||||
}
|
}
|
||||||
R_data.TIMESTAMP=time.Now().Unix()
|
R_data.TIMESTAMP=time.Now().UnixNano()
|
||||||
|
|
||||||
data_bufTmp, _ := json.Marshal(R_data)
|
data_bufTmp, _ := json.Marshal(R_data)
|
||||||
data_buf := string(data_bufTmp)
|
data_buf := string(data_bufTmp)
|
||||||
|
|
Loading…
Reference in New Issue