-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62ed391
commit d33c449
Showing
6 changed files
with
111 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package iot | ||
|
||
//设备或网关请求的通用消息体 | ||
type Request struct { | ||
ObjectDeviceId string `json:"object_device_id"` | ||
Services []RequestEventService `json:"services"` | ||
} | ||
type RequestEventService struct { | ||
ServiceId string `json:"service_id"` | ||
EventType string `json:"event_type"` | ||
EventTime string `json:"event_time"` | ||
Paras interface{} `json:"paras"` // 不同类型的请求paras使用的结构体不同 | ||
} | ||
|
||
// 1 网关更新子设备状态 | ||
|
||
type SubDevicesStatus struct { | ||
DeviceStatuses []DeviceStatus `json:"device_statuses"` | ||
} | ||
|
||
type DeviceStatus struct { | ||
DeviceId string `json:"device_id"` | ||
Status string `json:"status"` // 子设备状态。 OFFLINE:设备离线 ONLINE:设备上线 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
iot "github.com/ctlove0523/huaweicloud-iot-device-sdk-go" | ||
) | ||
|
||
func main() { | ||
device := iot.CreateIotDevice("5fdb75cccbfe2f02ce81d4bf_go-mqtt", "123456789", "tcp://iot-mqtts.cn-north-4.myhuaweicloud.com:1883") | ||
device.Init() | ||
|
||
subDevice1 := iot.DeviceStatus{ | ||
DeviceId: "5fdb75cccbfe2f02ce81d4bf_sub-device-1", | ||
Status: "ONLINE", | ||
} | ||
subDevice2 := iot.DeviceStatus{ | ||
DeviceId: "5fdb75cccbfe2f02ce81d4bf_sub-device-2", | ||
Status: "ONLINE", | ||
} | ||
|
||
subDevice3 := iot.DeviceStatus{ | ||
DeviceId: "5fdb75cccbfe2f02ce81d4bf_sub-device-3", | ||
Status: "ONLINE", | ||
} | ||
|
||
devicesStatus := []iot.DeviceStatus{subDevice1, subDevice2, subDevice3} | ||
|
||
ok := device.UpdateSubDeviceState(iot.SubDevicesStatus{ | ||
DeviceStatuses: devicesStatus, | ||
}) | ||
if ok { | ||
fmt.Println("gateway update sub devices status success") | ||
} else { | ||
fmt.Println("gateway update sub devices status failed") | ||
} | ||
} |