简体   繁体   English

多个 AWS 物联网设备

[英]Multiple AWS IoT Devices

I am creating an application where I need to connect multiple devices to AWS IoT, but I noticed that only the last device that was connected remains connected.我正在创建一个需要将多个设备连接到 AWS IoT 的应用程序,但我注意到只有最后连接的设备保持连接状态。 I saw that I was using the same certificates for all devices and after I created a certificate for each one the problem was solved, but it turns out that it will be multiple devices and it will be unproductive to keep registering device by device.我看到我对所有设备都使用相同的证书,并且在为每个设备创建证书后问题就解决了,但事实证明这将是多个设备,并且逐个设备继续注册是没有效率的。 I would like to know if there is a solution for multiple devices to remain connected to the aws iot simultaneously without having to register the certificates one by one.我想知道是否有一种解决方案可以让多个设备同时保持与 aws iot 的连接,而不必一个一个地注册证书。

This mainly comes from: https://iot-device-management.workshop.aws/en/provisioning-options/bulk-provisioning.html .这个主要来自: https://iot-device-management.workshop.aws/en/provisioning-options/bulk-provisioning.html

There are other options (just in time etc...) on the link above.上面的链接还有其他选项(及时等...)。

Create a bulk thing registration task To create a bulk registration task a role is required that grants permission to access the input file.创建批量事物注册任务要创建批量注册任务,需要一个角色来授予访问输入文件的权限。 This role has been already created by CloudFormation and the name of the role has been copied during the setup of the workshop to the shell variable $ARN_IOT_PROVISIONING_ROLE.此角色已由 CloudFormation 创建,并且角色名称已在研讨会设置期间复制到 shell 变量 $ARN_IOT_PROVISIONING_ROLE。

aws iot start-thing-registration-task \
  --template-body file://~/templateBody.json \
  --input-file-bucket $S3_BUCKET \
  --input-file-key bulk.json --role-arn $ARN_IOT_PROVISIONING_ROLE

When successful the command returns a taskId.成功时,命令返回一个 taskId。 The output looks similar to: output 看起来类似于:

{
    "taskId": "aaaf0a94-b5a9-4bd6-a1f5-cf188322a111"}

Provisioning templates https://docs.aws.amazon.com/iot/latest/developerguide/provision-template.html供应模板https://docs.aws.amazon.com/iot/latest/developerguide/provision-template.html

A provisioning template is a JSON document that uses parameters to describe the resources your device must use to interact with AWS IoT.预置模板是一个 JSON 文档,它使用参数来描述您的设备必须用于与 AWS IoT 交互的资源。 A template contains two sections: Parameters and Resources.模板包含两个部分:参数和资源。 There are two types of provisioning templates in AWS IoT. AWS IoT 中有两种类型的预置模板。 One is used for just-in-time provisioning (JITP) and bulk registration and the second is used for fleet provisioning.一个用于即时供应 (JITP) 和批量注册,第二个用于车队供应。

Script to create a provisioning template用于创建配置模板的脚本

https://github.com/aws-samples/aws-iot-device-management-workshop/blob/master/bin/mk-bulk.sh https://github.com/aws-samples/aws-iot-device-management-workshop/blob/master/bin/mk-bulk.sh

Create bucket创建桶

aws s3api create-bucket\
    --bucket bulk-iot-test\
    --region ap-northeast-1

Upload bulk.json (if using cloudshell) and copy to S3上传 bulk.json(如果使用 cloudshell)并复制到 S3

Upload bulk.json via the UI通过 UI 批量上传 json

aws s3 cp bulk.json s3://bulk-iot-test
aws s3 ls s3://bulk-iot-test

Create the role to register the things创建角色注册事物

From CloudFormation template… This is incomplete and needs further refination.来自 CloudFormation 模板……这是不完整的,需要进一步完善。

"DMWSIoTServiceRole": {
   "Type": "AWS::IAM::Role",
   "Properties": {
      "AssumeRolePolicyDocument": {
         "Statement": [ {
            "Effect": "Allow",
            "Principal": {
               "Service": [ "iot.amazonaws.com" ]
            },
            "Action": [ "sts:AssumeRole" ]
         } ]
      },
      "ManagedPolicyArns": [
        "arn:aws:iam::aws:policy/service-role/AWSIoTThingsRegistration",
        "arn:aws:iam::aws:policy/service-role/AWSIoTLogging",
        "arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess"
      ],
      "Path": "/"
    }
},

Start the thing registration task启动事物注册任务

aws iot start-thing-registration-task \
    --template-body file://~/templateBody.json \
    --input-file-bucket bulk-iot-test \
    --input-file-key bulk.json --role-arn "arn:aws:sts::ACCOUNTID:assumed-role/ROLE/USER@DOMAIN.com"

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

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