Search in sources :

Example 1 with ListDeviceStatesResponse

use of com.google.api.services.cloudiot.v1.model.ListDeviceStatesResponse in project java-docs-samples by GoogleCloudPlatform.

the class DeviceRegistryExample method getDeviceStates.

// [END iot_get_device]
// [START iot_get_device_state]
/**
 * Retrieves device metadata from a registry. *
 */
public static List<DeviceState> getDeviceStates(String deviceId, String projectId, String cloudRegion, String registryName) throws GeneralSecurityException, IOException {
    GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
    final CloudIot service = new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init).setApplicationName(APP_NAME).build();
    final String devicePath = String.format("projects/%s/locations/%s/registries/%s/devices/%s", projectId, cloudRegion, registryName, deviceId);
    System.out.println("Retrieving device states " + devicePath);
    ListDeviceStatesResponse resp = service.projects().locations().registries().devices().states().list(devicePath).execute();
    return resp.getDeviceStates();
}
Also used : CloudIot(com.google.api.services.cloudiot.v1.CloudIot) JsonFactory(com.google.api.client.json.JsonFactory) GoogleCredential(com.google.api.client.googleapis.auth.oauth2.GoogleCredential) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer) ListDeviceStatesResponse(com.google.api.services.cloudiot.v1.model.ListDeviceStatesResponse)

Aggregations

GoogleCredential (com.google.api.client.googleapis.auth.oauth2.GoogleCredential)1 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)1 JsonFactory (com.google.api.client.json.JsonFactory)1 CloudIot (com.google.api.services.cloudiot.v1.CloudIot)1 ListDeviceStatesResponse (com.google.api.services.cloudiot.v1.model.ListDeviceStatesResponse)1