简体   繁体   English

如何从 AWS IoT 服务中获取用户的特定“事物”,而不是系统中的所有事物

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

I develop an android app and I want to get only Things that related to spesific logged-in user currently I get all the Things in the system and I want to avoid the retrieve all the Things from AWS.我开发了一个android应用程序,我只想获取与特定登录用户相关的事物,目前我得到了系统中的所有事物,我想避免从 AWS 检索所有事物。

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

this is the code i use to get all the Things , any suggestion?这是我用来获取所有东西的代码,有什么建议吗?

You first need a way to associate a user with her devices.您首先需要一种将用户与她的设备相关联的方法。 A simple option is to add an owner Thing Attribute .一个简单的选项是添加owner Thing Attribute Attributes are key-value pairs we can set on Things.属性是我们可以在事物上设置的键值对。

Once we define the Thing owners, we can filter Things by owner with the optional attributeName and attributeValue inputs to listThings :一旦我们定义了事物的所有者,我们就可以使用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}]}

Note that this approach is just filtering the Things.请注意,这种方法只是过滤事物。 It does not restrict access.它不限制访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM