簡體   English   中英

如何從 AWS IoT 服務中獲取用戶的特定“事物”,而不是系統中的所有事物

[英]How to get user's spesific "Things" from AWS IoT service and not all the Things in the system

我開發了一個android應用程序,我只想獲取與特定登錄用戶相關的事物,目前我得到了系統中的所有事物,我想避免從 AWS 檢索所有事物。

val awsIotClient = AWSIotClient(AWSMobileClient.getInstance())
awsIotClient.setRegion(Region.getRegion(Regions.US_EAST_2))
val userListThings = awsIotClient.listThings(ListThingsRequest())

這是我用來獲取所有東西的代碼,有什么建議嗎?

您首先需要一種將用戶與她的設備相關聯的方法。 一個簡單的選項是添加owner Thing Attribute 屬性是我們可以在事物上設置的鍵值對。

一旦我們定義了事物的所有者,我們就可以使用listThings的可選attributeNameattributeValue輸入來按所有者過濾事物:

# python, but the android API has the same method signature
iot.list_things(attributeName="owner", attributeValue="me")
{'things': [{'thingName': 'temp1',
   'thingArn': 'arn:aws:iot:us-east-1:xxxxxxxxxxxx:thing/temp1',
   'attributes': {'owner': 'me'},
   'version': 1}]}

請注意,這種方法只是過濾事物。 它不限制訪問。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM