繁体   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