首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BASH中的自动化-在AWS-IoT中创建事物。如何在创建thingId后检索它?

BASH中的自动化-在AWS-IoT中创建事物。如何在创建thingId后检索它?
EN

Stack Overflow用户
提问于 2020-01-19 14:22:13
回答 1查看 51关注 0票数 1

这是我们在AWS中使用BASH脚本创建一个东西的时候。它工作得很好,但我想检索thing_ID并将其存储在一个变量中。

下面是创建这个东西的bash代码。这是蚊子mosquitto_pub --cafile root.cert --cert deviceCertAndCACert.crt --key deviceCert.key -h xxxxx.iot.us-east-2.amazonaws.com -p 8883 -q 1 -t foo/bar -I anyclientID --tls-version tlsv1.2 -m "Hello" -d的第一次调用,但在第一个连接中它只返回:

代码语言:javascript
复制
Client anyclientID18351 sending CONNECT
Error: The connection was lost.

如何在创建thing_Id后检索它?

代码如下:

代码语言:javascript
复制
openssl genrsa -out deviceCert.key 2048
openssl req -new -key deviceCert.key -out deviceCert.csr -subj "/C=CA/ST=ON/L=NY/O=SC/OU=DG/CN=EX"
openssl x509 -req -in deviceCert.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out deviceCert.crt -days 365 -sha256
cat deviceCert.crt rootCA.pem > deviceCertAndCACert.crt
wget https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem
mv VeriSign-Class\ 3-Public-Primary-Certification-Authority-G5.pem root.cert
mosquitto_pub --cafile root.cert --cert deviceCertAndCACert.crt --key deviceCert.key -h xxxxx.iot.us-east-2.amazonaws.com -p 8883 -q 1 -t foo/bar -I anyclientID --tls-version tlsv1.2 -m "Hello" -d
mosquitto_pub --cafile root.cert --cert deviceCertAndCACert.crt --key deviceCert.key -h xxxxx.iot.us-east-2.amazonaws.com -p 8883 -q 1 -t foo/bar -I anyclientID --tls-version tlsv1.2 -m "Thing $i is Working" -d
EN

回答 1

Stack Overflow用户

发布于 2020-01-23 22:27:15

如果您知道对象的名称,则可以在命令行界面中使用describe-thing命令。

aws iot describe-thing --thing-name ENTER_THING_NAME_HERE

响应:

代码语言:javascript
复制
{
    "defaultClientId": "anyclientID",
    "thingName": "THING_NAME",
    "thingId": "40da2e73-c6af-406e-b415-15acae538797",
    "thingArn": "arn:aws:iot:us-east-2:123456789012:thing/THING_NAME",
    "thingTypeName": "LightBulb",
    "attributes": {
        "model": "123",
        "wattage": "75"
    },
    "version": 1
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59807681

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档