選取您的 Cookie 偏好設定

我們使用提供自身網站和服務所需的基本 Cookie 和類似工具。我們使用效能 Cookie 收集匿名統計資料,以便了解客戶如何使用我們的網站並進行改進。基本 Cookie 無法停用,但可以按一下「自訂」或「拒絕」以拒絕效能 Cookie。

如果您同意,AWS 與經核准的第三方也會使用 Cookie 提供實用的網站功能、記住您的偏好設定,並顯示相關內容,包括相關廣告。若要接受或拒絕所有非必要 Cookie,請按一下「接受」或「拒絕」。若要進行更詳細的選擇,請按一下「自訂」。

DescribeThing 搭配 AWS SDK或 使用 CLI

焦點模式
DescribeThing 搭配 AWS SDK或 使用 CLI - AWS IoT Core

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

下列程式碼範例示範如何使用 DescribeThing

C++
SDK 適用於 C++
注意

還有更多功能 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

//! Describe an AWS IoT thing. /*! \param thingName: The name for the thing. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::describeThing(const Aws::String &thingName, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::DescribeThingRequest request; request.SetThingName(thingName); Aws::IoT::Model::DescribeThingOutcome outcome = iotClient.DescribeThing(request); if (outcome.IsSuccess()) { const Aws::IoT::Model::DescribeThingResult &result = outcome.GetResult(); std::cout << "Retrieved thing '" << result.GetThingName() << "'" << std::endl; std::cout << "thingArn: " << result.GetThingArn() << std::endl; std::cout << result.GetAttributes().size() << " attribute(s) retrieved" << std::endl; for (const auto &attribute: result.GetAttributes()) { std::cout << " attribute: " << attribute.first << "=" << attribute.second << std::endl; } } else { std::cerr << "Error describing thing " << thingName << ": " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
  • 如需API詳細資訊,請參閱 AWS SDK for C++ API 參考DescribeThing中的 。

CLI
AWS CLI

顯示物件的詳細資訊

下列describe-thing範例顯示您 AWS 帳戶 AWS IoT 登錄檔中定義的物件 (裝置) 的相關資訊。

aws iot describe-thing --thing-name "MyLightBulb"

輸出:

{ "defaultClientId": "MyLightBulb", "thingName": "MyLightBulb", "thingId": "40da2e73-c6af-406e-b415-15acae538797", "thingArn": "arn:aws:iot:us-west-2:123456789012:thing/MyLightBulb", "thingTypeName": "LightBulb", "attributes": { "model": "123", "wattage": "75" }, "version": 1 }

如需詳細資訊,請參閱 AWS IoT 開發人員指南中的如何使用登錄檔管理物件

  • 如需API詳細資訊,請參閱 AWS CLI 命令參考DescribeThing中的 。

Java
SDK 適用於 Java 2.x
注意

還有更多功能 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

/** * Describes an IoT Thing asynchronously. * * @param thingName The name of the IoT Thing. * * This method initiates an asynchronous request to describe an IoT Thing. * If the request is successful, it prints the Thing details. * If an exception occurs, it prints the error message. */ private void describeThing(String thingName) { DescribeThingRequest thingRequest = DescribeThingRequest.builder() .thingName(thingName) .build(); CompletableFuture<DescribeThingResponse> future = getAsyncClient().describeThing(thingRequest); future.whenComplete((describeResponse, ex) -> { if (describeResponse != null) { System.out.println("Thing Details:"); System.out.println("Thing Name: " + describeResponse.thingName()); System.out.println("Thing ARN: " + describeResponse.thingArn()); } else { Throwable cause = ex != null ? ex.getCause() : null; if (cause instanceof IotException) { System.err.println(((IotException) cause).awsErrorDetails().errorMessage()); } else if (cause != null) { System.err.println("Unexpected error: " + cause.getMessage()); } else { System.err.println("Failed to describe Thing."); } } }); future.join(); }
  • 如需API詳細資訊,請參閱 AWS SDK for Java 2.x API 參考DescribeThing中的 。

Kotlin
SDK 適用於 Kotlin
注意

還有更多功能 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

suspend fun describeThing(thingNameVal: String) { val thingRequest = DescribeThingRequest { thingName = thingNameVal } // Print Thing details. IotClient { region = "us-east-1" }.use { iotClient -> val describeResponse = iotClient.describeThing(thingRequest) println("Thing details:") println("Thing name: ${describeResponse.thingName}") println("Thing ARN: ${describeResponse.thingArn}") } }
  • 如需API詳細資訊,請參閱 DescribeThing 中的 AWS SDK Kotlin API參考

SDK 適用於 C++
注意

還有更多功能 GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

//! Describe an AWS IoT thing. /*! \param thingName: The name for the thing. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::describeThing(const Aws::String &thingName, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::DescribeThingRequest request; request.SetThingName(thingName); Aws::IoT::Model::DescribeThingOutcome outcome = iotClient.DescribeThing(request); if (outcome.IsSuccess()) { const Aws::IoT::Model::DescribeThingResult &result = outcome.GetResult(); std::cout << "Retrieved thing '" << result.GetThingName() << "'" << std::endl; std::cout << "thingArn: " << result.GetThingArn() << std::endl; std::cout << result.GetAttributes().size() << " attribute(s) retrieved" << std::endl; for (const auto &attribute: result.GetAttributes()) { std::cout << " attribute: " << attribute.first << "=" << attribute.second << std::endl; } } else { std::cerr << "Error describing thing " << thingName << ": " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
  • 如需API詳細資訊,請參閱 AWS SDK for C++ API 參考DescribeThing中的 。

如需開發人員指南和程式碼範例的完整清單 AWS SDK,請參閱 AWS IoT 搭配 使用 AWS SDK。本主題也包含入門的相關資訊,以及先前SDK版本的詳細資訊。

隱私權網站條款Cookie 偏好設定
© 2025, Amazon Web Services, Inc.或其附屬公司。保留所有權利。