From 8b4cac6a120070493f06a96a3d5f8a730e8038b4 Mon Sep 17 00:00:00 2001 From: fish Date: Sat, 21 Sep 2019 18:27:33 +0800 Subject: [PATCH] do_send_data.go --- loadconfig.go | 18 ++++++++++++++++-- main.go | 1 + mq.go | 6 ++++-- router.go | 18 ++++++++++++++---- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/loadconfig.go b/loadconfig.go index 6a0a6dd..23c82f3 100644 --- a/loadconfig.go +++ b/loadconfig.go @@ -14,7 +14,6 @@ import ( "k8s.io/apimachinery/pkg/util/yaml" "bytes" - // "k8s.io/apimachinery/pkg/runtime" "io/ioutil" ) @@ -138,6 +137,10 @@ var loraNodeMap sync.Map var db, _ = sql.Open("sqlite3", "./db/gateway.db") +type pluginConfig struct { + PodNodeSelectorPluginConfig map[string]string +} + // 加载配置文件 func init() { @@ -163,7 +166,18 @@ func init() { reader := bytes.NewReader(configData) // ext := runtime.RawExtension{} 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) } diff --git a/main.go b/main.go index ab9cc2b..51eb4b1 100644 --- a/main.go +++ b/main.go @@ -71,6 +71,7 @@ func main() { // err = json.NewDecoder(string(ext.Raw)).Decode(&conf) // check(err) // log.Println(conf.OPENTCPSETVER) + go gw_router() go serial_run() c := cron.New() diff --git a/mq.go b/mq.go index 0c0d8c8..798a5be 100644 --- a/mq.go +++ b/mq.go @@ -61,8 +61,10 @@ func init() { b := strconv.Itoa(rand.Intn(100)) clientId := "unit"+b opts := mqtt.NewClientOptions().AddBroker(conf.MQTT_BROKER).SetClientID(clientId) - opts.SetUsername(conf.MQTT_USERNAME) - opts.SetPassword(conf.MQTT_PASSWORD) + if conf.MQTT_USERNAME!="" && conf.MQTT_PASSWORD !=""{ + opts.SetUsername(conf.MQTT_USERNAME) + opts.SetPassword(conf.MQTT_PASSWORD) + } opts.SetKeepAlive(time.Duration(conf.MQTT_KEEPALIVE) * time.Second) opts.SetDefaultPublishHandler(onMessageReceived) diff --git a/router.go b/router.go index f61187d..6c9cb7f 100644 --- a/router.go +++ b/router.go @@ -35,10 +35,19 @@ func gw_router() { v1.GET("/seat/:id", seat_api) v1.POST("/push", push) - v1.GET("/getConf") - 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] var R_data P1004_6 - R_data.CODE = 1008 + R_data.CODE = 1005 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 datatypeStr := strconv.FormatInt(int64(data[5]&0xff), 16) @@ -262,7 +272,7 @@ func dealDatav3(data []byte,loragwip string) string{ readyData.WriteString("*") readyData.WriteString(tofTmp) } - R_data.TIMESTAMP=time.Now().Unix() + R_data.TIMESTAMP=time.Now().UnixNano() data_bufTmp, _ := json.Marshal(R_data) data_buf := string(data_bufTmp)