Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Utilizzo ListThings con un AWS SDK o una CLI
Gli esempi di codice seguenti mostrano come utilizzare ListThings.
- .NET
-
- SDK per .NET(v4)
-
Nota
C'è altro da fare. GitHub Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS
. /// <summary> /// Lists IoT Things with pagination support. /// </summary> /// <returns>List of Things, or empty list if listing failed.</returns> public async Task<List<ThingAttribute>> ListThingsAsync() { try { // Use pages of 10. var request = new ListThingsRequest() { MaxResults = 10 }; var response = await _amazonIoT.ListThingsAsync(request); // Since there is not a built-in paginator, use the NextMarker to paginate. bool hasMoreResults = true; var things = new List<ThingAttribute>(); while (hasMoreResults) { things.AddRange(response.Things); // If NextMarker is not null, there are more results. Get the next page of results. if (!String.IsNullOrEmpty(response.NextMarker)) { request.Marker = response.NextMarker; response = await _amazonIoT.ListThingsAsync(request); } else hasMoreResults = false; } _logger.LogInformation($"Retrieved {things.Count} Things"); return things; } catch (Amazon.IoT.Model.ThrottlingException ex) { _logger.LogWarning($"Request throttled, please try again later: {ex.Message}"); return new List<ThingAttribute>(); } catch (Exception ex) { _logger.LogError($"Couldn't list Things. Here's why: {ex.Message}"); return new List<ThingAttribute>(); } }-
Per i dettagli sull'API, ListThingsconsulta AWS SDK per .NETAPI Reference.
-
- CLI
-
- AWS CLI
-
Esempio 1: come elencare tutti gli oggetti presenti nel registro
L'
list-thingsesempio seguente elenca gli oggetti (dispositivi) definiti nel registro AWS IoT per il tuo AWS account.aws iot list-thingsOutput:
{ "things": [ { "thingName": "ThirdBulb", "thingTypeName": "LightBulb", "thingArn": "arn:aws:iot:us-west-2:123456789012:thing/ThirdBulb", "attributes": { "model": "123", "wattage": "75" }, "version": 2 }, { "thingName": "MyOtherLightBulb", "thingTypeName": "LightBulb", "thingArn": "arn:aws:iot:us-west-2:123456789012:thing/MyOtherLightBulb", "attributes": { "model": "123", "wattage": "75" }, "version": 3 }, { "thingName": "MyLightBulb", "thingTypeName": "LightBulb", "thingArn": "arn:aws:iot:us-west-2:123456789012:thing/MyLightBulb", "attributes": { "model": "123", "wattage": "75" }, "version": 1 }, { "thingName": "SampleIoTThing", "thingArn": "arn:aws:iot:us-west-2:123456789012:thing/SampleIoTThing", "attributes": {}, "version": 1 } ] }Esempio 2: come elencare gli oggetti definiti con un attributo specifico
L’esempio
list-thingsseguente visualizza un elenco degli oggetti contenenti un attributo denominatowattage.aws iot list-things \ --attribute-namewattageOutput:
{ "things": [ { "thingName": "MyLightBulb", "thingTypeName": "LightBulb", "thingArn": "arn:aws:iot:us-west-2:123456789012:thing/MyLightBulb", "attributes": { "model": "123", "wattage": "75" }, "version": 1 }, { "thingName": "MyOtherLightBulb", "thingTypeName": "LightBulb", "thingArn": "arn:aws:iot:us-west-2:123456789012:thing/MyOtherLightBulb", "attributes": { "model": "123", "wattage": "75" }, "version": 3 } ] }Per ulteriori informazioni, consulta Come gestire gli oggetti con il registro nella Guida per gli sviluppatori di AWS IoT.
-
Per i dettagli sull'API, consulta ListThingsAWS CLI
Command Reference.
-
- Rust
-
- SDK per Rust
-
Nota
C'è altro da fare. GitHub Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS
. async fn show_things(client: &Client) -> Result<(), Error> { let resp = client.list_things().send().await?; println!("Things:"); for thing in resp.things.unwrap() { println!( " Name: {}", thing.thing_name.as_deref().unwrap_or_default() ); println!( " Type: {}", thing.thing_type_name.as_deref().unwrap_or_default() ); println!( " ARN: {}", thing.thing_arn.as_deref().unwrap_or_default() ); println!(); } println!(); Ok(()) }-
Per i dettagli sulle API, consulta il riferimento ListThings
all'API AWS SDK for Rust.
-
Per un elenco completo delle guide per sviluppatori AWS SDK e degli esempi di codice, consulta. Utilizzo AWS IoT con un SDK AWS Questo argomento include anche informazioni su come iniziare e dettagli sulle versioni precedenti dell’SDK.