sync device
This commit is contained in:
parent
c3db4bbd64
commit
19d8a79cf1
|
@ -380,7 +380,7 @@ func (device *baseIotDevice) subscribeDefaultTopics() {
|
||||||
panic(0)
|
panic(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 订阅平台下发的文件上传和下载URL topic
|
// 订阅平台下发到设备的事件
|
||||||
topic = FormatTopic(PlatformEventToDeviceTopic, device.Id)
|
topic = FormatTopic(PlatformEventToDeviceTopic, device.Id)
|
||||||
if token := device.Client.Subscribe(topic, device.qos, device.handlePlatformToDeviceData());
|
if token := device.Client.Subscribe(topic, device.qos, device.handlePlatformToDeviceData());
|
||||||
token.Wait() && token.Error() != nil {
|
token.Wait() && token.Error() != nil {
|
||||||
|
@ -448,6 +448,7 @@ func (device *baseIotDevice) handlePlatformToDeviceData() func(client mqtt.Clien
|
||||||
|
|
||||||
case "log_config":
|
case "log_config":
|
||||||
// 平台下发日志收集通知
|
// 平台下发日志收集通知
|
||||||
|
fmt.Println("platform send log collect command")
|
||||||
logConfig := &LogCollectionConfig{}
|
logConfig := &LogCollectionConfig{}
|
||||||
if json.Unmarshal([]byte(Interface2JsonString(entry.Paras)), logConfig) != nil {
|
if json.Unmarshal([]byte(Interface2JsonString(entry.Paras)), logConfig) != nil {
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -1,14 +1,40 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
iot "github.com/ctlove0523/huaweicloud-iot-device-sdk-go"
|
iot "github.com/ctlove0523/huaweicloud-iot-device-sdk-go"
|
||||||
"github.com/ctlove0523/huaweicloud-iot-device-sdk-go/samples"
|
"github.com/ctlove0523/huaweicloud-iot-device-sdk-go/samples"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
device := samples.CreateDevice()
|
device := samples.CreateDevice()
|
||||||
|
device.AddMessageHandler(func(message iot.Message) bool {
|
||||||
|
fmt.Println(message)
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
device.SetSubDevicesAddHandler(func(devices iot.SubDeviceInfo) {
|
||||||
|
fmt.Println(device)
|
||||||
|
})
|
||||||
|
device.SetSubDevicesDeleteHandler(func(devices iot.SubDeviceInfo) {
|
||||||
|
fmt.Println(device)
|
||||||
|
})
|
||||||
device.SetDeviceStatusLogCollector(func(endTime string) []iot.DeviceLogEntry {
|
device.SetDeviceStatusLogCollector(func(endTime string) []iot.DeviceLogEntry {
|
||||||
return []iot.DeviceLogEntry{}
|
fmt.Println("begin to collect log")
|
||||||
|
entries := []iot.DeviceLogEntry{}
|
||||||
|
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
entry := iot.DeviceLogEntry{
|
||||||
|
Type: "DEVICE_MESSAGE",
|
||||||
|
Timestamp: iot.GetEventTimeStamp(),
|
||||||
|
Content: "message hello " + strconv.Itoa(i),
|
||||||
|
}
|
||||||
|
entries = append(entries, entry)
|
||||||
|
}
|
||||||
|
return entries
|
||||||
})
|
})
|
||||||
device.Init()
|
device.Init()
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Minute)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue