From 85c5741b90ae0172346fdc31986a4d93bd1a2bf4 Mon Sep 17 00:00:00 2001 From: PandaX <18610165312@163.com> Date: Wed, 8 Nov 2023 09:21:08 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BC=98=E5=8C=96]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.yml | 3 ++- iothub/client/mqttclient/mqtt_api.go | 6 +++--- pkg/config/mqtt.go | 9 +++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/config.yml b/config.yml index 0c2f241..778cd5d 100644 --- a/config.yml +++ b/config.yml @@ -61,7 +61,8 @@ taos: config: "" mqtt: - broker: http://127.0.0.1:18083/api + broker: tcp://127.0.0.1:1883 + httpBroker: http://127.0.0.1:18083/api qos: 1 username: dbda318b31319d49 password: wwqPbYu9BCsIFgW3m0aICmRrvxUHcIi44AQuG24wQARE diff --git a/iothub/client/mqttclient/mqtt_api.go b/iothub/client/mqttclient/mqtt_api.go index 8a875ec..4bd6c89 100644 --- a/iothub/client/mqttclient/mqtt_api.go +++ b/iothub/client/mqttclient/mqtt_api.go @@ -20,9 +20,9 @@ const SubscribeTopicsInfo string = "subscribe" func GetEmqInfo(infoType string) ([]map[string]interface{}, error) { var url string if infoType == ClientsInfo { - url = fmt.Sprintf("%s/v5/clients?_page=1&_limit=100000", global.Conf.Mqtt.Broker) + url = fmt.Sprintf("%s/v5/clients?_page=1&_limit=100000", global.Conf.Mqtt.HttpBroker) } else if infoType == SubscribeTopicsInfo { - url = fmt.Sprintf("%s/v5/subscriptions?_page=1&_limit=100000", global.Conf.Mqtt.Broker) + url = fmt.Sprintf("%s/v5/subscriptions?_page=1&_limit=100000", global.Conf.Mqtt.HttpBroker) } else { return nil, errors.New("invalid infoType") } @@ -67,7 +67,7 @@ func Publish(topic, clientId string, payload interface{}) error { return errors.New("未获取到MQTT连接") } global.Log.Debugf("send data to clientId: %s, topic:%s, payload: %v", clientId, topic, payload) - url := fmt.Sprintf("%s/v5/publish", global.Conf.Mqtt.Broker) + url := fmt.Sprintf("%s/v5/publish", global.Conf.Mqtt.HttpBroker) pubData := map[string]interface{}{ "topic": topic, "payload": payload, diff --git a/pkg/config/mqtt.go b/pkg/config/mqtt.go index f7835f8..95b6703 100644 --- a/pkg/config/mqtt.go +++ b/pkg/config/mqtt.go @@ -1,8 +1,9 @@ package config type Mqtt struct { - Broker string `mapstructure:"broker" json:"broker" yaml:"broker"` - Qos int `mapstructure:"qos" json:"qos" yaml:"qos"` - Username string `mapstructure:"username" json:"username" yaml:"username"` - Password string `mapstructure:"password" json:"password" yaml:"password"` + Broker string `mapstructure:"broker" json:"broker" yaml:"broker"` + HttpBroker string `mapstructure:"httpBroker" json:"httpBroker" yaml:"httpBroker"` + Qos int `mapstructure:"qos" json:"qos" yaml:"qos"` + Username string `mapstructure:"username" json:"username" yaml:"username"` + Password string `mapstructure:"password" json:"password" yaml:"password"` }