Las traducciones son generadas a través de traducción automática. En caso de conflicto entre la traducción y la version original de inglés, prevalecerá la version en inglés.
Úselo UpdateThing con un AWS SDK o CLI
Los siguientes ejemplos de código muestran cómo utilizar UpdateThing.
- .NET
-
- SDK para .NET(v4)
-
nota
Hay más información GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de 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; } }-
Para obtener más información sobre la API, consulta UpdateThingla Referencia AWS SDK para .NET de la API.
-
- C++
-
- SDK para C++
-
nota
Hay más información al respecto GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de 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(); }-
Para obtener más información sobre la API, consulta UpdateThingla Referencia AWS SDK para C++ de la API.
-
- CLI
-
- AWS CLI
-
Para asociar un objeto con un tipo de objeto
El siguiente
update-thingejemplo asocia una cosa del registro de AWS IoT a un tipo de cosa. Al realizar la asociación, se proporcionan valores para los atributos definidos por el tipo de objeto.aws iot update-thing \ --thing-name"MyOtherLightBulb"\ --thing-type-name"LightBulb"\ --attribute-payload "{"attributes": {"wattage":"75", "model":"123"}}"Este comando no proporciona ningún resultado. Para ver el resultado, use el comando
describe-thing.Para obtener más información, consulte Thing Types en la Guía para desarrolladores de AWS IoT.
-
Para obtener más información sobre la API, consulte UpdateThing
la Referencia de AWS CLI comandos.
-
- Kotlin
-
- SDK para Kotlin
-
nota
Hay más información al respecto GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de 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.") } }-
Para obtener más información sobre la API, consulta UpdateThing
la referencia sobre el AWS SDK para la API de Kotlin.
-
Para ver una lista completa de guías para desarrolladores del AWS SDK y ejemplos de código, consultaSe utiliza AWS IoT con un SDK AWS. En este tema también se incluye información sobre cómo comenzar a utilizar el SDK y detalles sobre sus versiones anteriores.