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



这是我们在 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的第一个呼叫,但在第一个连接中它只返回:

Client anyclientID18351 sending CONNECT
Error: The connection was lost.

创建thing_Id后如何检索?

这是代码:

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

如果您知道事物的名称,则可以在CLI中使用描述事物命令。

aws iot describe-thing --thing-name ENTER_THING_NAME_HERE

响应:

{
"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
}

最新更新