From 78ee43d54d8a09fc5b618481fa5ff5edc68ce0a8 Mon Sep 17 00:00:00 2001 From: ctlove0523 <478309639@qq.com> Date: Sat, 26 Dec 2020 21:55:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iot_device.go | 4 ++++ samples/connect/connect_demo.go | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 samples/connect/connect_demo.go diff --git a/iot_device.go b/iot_device.go index 7353d27..fabc83c 100644 --- a/iot_device.go +++ b/iot_device.go @@ -36,6 +36,7 @@ type Gateway interface { type Device interface { Gateway Init() bool + DisConnect() IsConnected() bool SendMessage(message Message) bool ReportProperties(properties ServiceProperty) bool @@ -64,6 +65,9 @@ type iotDevice struct { fileUrls map[string]string } +func (device *iotDevice) DisConnect() () { + device.client.Disconnect(0) +} func (device *iotDevice) SyncAllVersionSubDevices() { dataEntry := DataEntry{ ServiceId: "$sub_device_manager", diff --git a/samples/connect/connect_demo.go b/samples/connect/connect_demo.go new file mode 100644 index 0000000..edb34df --- /dev/null +++ b/samples/connect/connect_demo.go @@ -0,0 +1,39 @@ +package main + +import ( + iot "github.com/ctlove0523/huaweicloud-iot-device-sdk-go" + "strconv" + "time" +) + +const password = "123456789" +const server = "tcp://iot-mqtts.cn-north-4.myhuaweicloud.com:1883" +const produceId = "5fdb75cccbfe2f02ce81d4bf" + + +func main() { + content := iot.Message{ + Content: struct { + msg string + }{ + msg: "MIIbswYJKoZIhvcNAQcCoIIbpDCCG6ACAQExDTALBglghkgBZQMEAgEwghnFBgkqhkiG9w0BBwGgghm2BIIZsnsidG9rZW4iOnsiZXhwaXJlc19hdCI6IjIwMjAtMTItMjdUMTI6MjY6MzguNDU5MDAwWiIsIm1ldGhvZHMiOlsicGFzc3dvcmQiXSwiY2F0YWxvZyI6W10sInJvbGVzIjpbeyJuYW1lI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0yNlQxMjoyNjozOC40NTkwMDBaIiwidXNlciI6eyJkb21haW4iOnsibmFtZSI6ImN0bG92ZTA1MjMiLCJpZCI6IjI2NDFhNjBlNzQ5YzRmMmJhMWNhNTNjNDhhYTIxNTllIn0sIm5hbWUiOiJjdGxvdmUwNTIzIiwicGFzc3dvcmRfZXhwaXJlc19hdCI6IiIsImlkIjoiMjVlMWY3NGZiZjYxNGVkN2I2ODZlZTI3YzBhNWVhN2YifX19MYIBwTCCAb0CAQEwgZcwgYkxCzAJBgNVBAYTAkNOMRIwEAYDVQQIDAlHdWFuZ0RvbmcxETAPBgNVBAcMCFNoZW5aaGVuMS4wLAYDVQQKDCVIdWF3ZWkgU29mdHdhcmUgVGVjaG5vbG9naWVzIENvLiwgTHRkMQ4wDAYDVQQLDAVDbG91ZDETMBEGA1UEAwwKY2EuaWFtLnBraQIJANyzK10QYWoQMAsGCWCGSAFlAwQCATANBgkqhkiG9w0BAQEFAASCAQCBlhhMWCj0H0onxSfxQTyz0OXd0M9zbwMIoV10RWeR6A-bBocIt9tA7sV4JmW1KUKMyc2xm6P2J9xWSVhOpB0-pk+69aEz6wAFZtAsKY4IzhAmKBoy0j+29h-oXgm1kZZxn2pNyAaBUDTzdGGChfU-qohQY99gASdDerT5awO1SPC22b6hBnQ5DSdr+IUfj8dmKwSkJusJsaEufmBeUmASgFJPpKWIkX2VTCMa9iwuTkr+K+t8VMGqzYIgRnnEeHdwZw8E83ZlaPaZxHYJDf6DGGtjZs8gkBsG0HQ+3KTfS-FRlHpP5pPOY6JX1LAtKj5YdwXksO3f7GwyVmXqrN+Y", + }, + } + for i := 1; i <= 110; i++ { + go SendMessage(strconv.Itoa(i), content) + } + + time.Sleep(time.Hour) +} + +func SendMessage(id string, message iot.Message) { + device := iot.CreateIotDevice(produceId+"_test-"+id, password, server) + device.Init() + + for i := 0; i < 100; i++ { + device.SendMessage(message) + } + + time.Sleep(time.Hour) + +}