AWSSDK または CLI UpdateThingで を使用する - AWS IoT Core

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

AWSSDK または CLI UpdateThingで を使用する

次のサンプルコードは、UpdateThing を使用する方法を説明しています。

.NET
SDK for .NET(v4)
注記

GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

/// <summary> /// Updates an IoT Thing with attributes. /// </summary> /// <param name="thingName">The name of the Thing to update.</param> /// <param name="attributes">Dictionary of attributes to add.</param> /// <returns>True if successful, false otherwise.</returns> public async Task<bool> UpdateThingAsync(string thingName, Dictionary<string, string> attributes) { try { var request = new UpdateThingRequest { ThingName = thingName, AttributePayload = new AttributePayload { Attributes = attributes, Merge = true } }; await _amazonIoT.UpdateThingAsync(request); _logger.LogInformation($"Updated Thing {thingName} with attributes"); return true; } catch (Amazon.IoT.Model.ResourceNotFoundException ex) { _logger.LogError($"Cannot update Thing - resource not found: {ex.Message}"); return false; } catch (Exception ex) { _logger.LogError($"Couldn't update Thing attributes. Here's why: {ex.Message}"); return false; } }
  • API の詳細については、AWS SDK for .NET API リファレンスの「UpdateThing」を参照してください。

C++
SDK for C++
注記

GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

//! Update an AWS IoT thing with attributes. /*! \param thingName: The name for the thing. \param attributeMap: A map of key/value attributes/ \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::IoT::updateThing(const Aws::String &thingName, const std::map<Aws::String, Aws::String> &attributeMap, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::IoT::IoTClient iotClient(clientConfiguration); Aws::IoT::Model::UpdateThingRequest request; request.SetThingName(thingName); Aws::IoT::Model::AttributePayload attributePayload; for (const auto &attribute: attributeMap) { attributePayload.AddAttributes(attribute.first, attribute.second); } request.SetAttributePayload(attributePayload); Aws::IoT::Model::UpdateThingOutcome outcome = iotClient.UpdateThing(request); if (outcome.IsSuccess()) { std::cout << "Successfully updated thing " << thingName << std::endl; } else { std::cerr << "Failed to update thing " << thingName << ":" << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
  • API の詳細については、「AWS SDK for C++ API リファレンス」の「UpdateThing」を参照してください。

CLI
AWS CLI

モノのタイプにモノを関連付けるには

次のupdate-thing例では、AWSIoT レジストリ内のモノをモノのタイプに関連付けます。関連付けを行うときは、モノのタイプで定義された属性の値を指定します。

aws iot update-thing \ --thing-name "MyOtherLightBulb" \ --thing-type-name "LightBulb" \ --attribute-payload "{"attributes": {"wattage":"75", "model":"123"}}"

このコマンドでは、出力が生成されません。describe-thing コマンドを使用して結果を表示します。

詳細については、「AWS IoT デベロッパーガイド」「モノのタイプ」を参照してください。

  • API の詳細については、「AWS CLI コマンドリファレンス」の「UpdateThing」を参照してください。

Kotlin
SDK for Kotlin
注記

GitHub には、その他のリソースもあります。用例一覧を検索し、AWS コード例リポジトリでの設定と実行の方法を確認してください。

suspend fun updateThing(thingNameVal: String?) { val newLocation = "Office" val newFirmwareVersion = "v2.0" val attMap: MutableMap<String, String> = HashMap() attMap["location"] = newLocation attMap["firmwareVersion"] = newFirmwareVersion val attributePayloadVal = AttributePayload { attributes = attMap } val updateThingRequest = UpdateThingRequest { thingName = thingNameVal attributePayload = attributePayloadVal } IotClient.fromEnvironment { region = "us-east-1" }.use { iotClient -> // Update the IoT thing attributes. iotClient.updateThing(updateThingRequest) println("$thingNameVal attributes updated successfully.") } }
  • API の詳細については、「AWS SDK for Kotlin API リファレンス」の「UpdateThing」を参照してください。

AWSSDK 開発者ガイドとコード例の完全なリストについては、「」を参照してくださいAWSSDK AWS IoTでの の使用。このトピックには、使用開始方法に関する情報と、以前の SDK バージョンの詳細も含まれています。