examples/iot-nirvana/client/src/main/java/com/google/cloud/demo/iot/nirvana/client/IotDeviceMgr.java
/**
   * Register a device in a IoT Core registry
   *
   * @param iotDevice Device to register
   * @param iotCoreRegistryPath IoT Core registry in which to register the device
   * @param rsaCertificateFilePath Path to the file containing the device certificate
   * @throws ClientException
   */
Register a device in a IoT Core registry
@param iotDevice Device to register
@param iotCoreRegistryPath IoT Core registry in which to register the device
@param rsaCertificateFilePath Path to the file containing the device certificate
@throws ClientException
Register a device in a IoT Core registry @param iotDevice Device to register @param iotCoreRegistryPath IoT Core registry in which to register the device @param rsaCertificateFilePath Path to the file containing the device certificate @throws ClientException
private void registerDevice(
      IotDevice iotDevice, String iotCoreRegistryPath, String rsaCertificateFilePath)
      throws ClientException {
    try {
      LogUtils.logDebug(
          LOGGER,
          DEVICE_MGR_LOGGING_RESOURCE,
          getGcpProjectId(),
          "Registering Cloud IoT device...");
      DeviceCredential credentials = loadCredentials(rsaCertificateFilePath);
      Device device = new Device();
      device.setId(iotDevice.getDeviceId());
      device.setCredentials(Arrays.asList(credentials));
      CloudIot cloudIotService = createCloudIotService();
      Device registeredDevice =
          cloudIotService
              .projects()
              .locations()
              .registries()
              .devices()
              .create(iotCoreRegistryPath, device)
              .execute();
      LogUtils.logDebug(
          LOGGER,
          DEVICE_MGR_LOGGING_RESOURCE,
          getGcpProjectId(),
          String.format("Cloud IoT device registered.\n%s", registeredDevice.toPrettyString()));
    } catch (IOException e) {
      String message = String.format("Failed to register device. Cause: %s", e.getMessage());
      LogUtils.logError(LOGGER, DEVICE_MGR_LOGGING_RESOURCE, getGcpProjectId(), message);
      throw new ClientException(message, e);
    }
  }
private void registerDevice ( IotDevice iotDevice , String iotCoreRegistryPath , String rsaCertificateFilePath ) throws ClientException { try { LogUtils . logDebug ( LOGGER , DEVICE_MGR_LOGGING_RESOURCE , getGcpProjectId ( ) , "Registering Cloud IoT device..." ) ; DeviceCredential credentials = loadCredentials ( rsaCertificateFilePath ) ; Device device = new Device ( ) ; device . setId ( iotDevice . getDeviceId ( ) ) ; device . setCredentials ( Arrays . asList ( credentials ) ) ; CloudIot cloudIotService = createCloudIotService ( ) ; Device registeredDevice = cloudIotService . projects ( ) . locations ( ) . registries ( ) . devices ( ) . create ( iotCoreRegistryPath , device ) . execute ( ) ; LogUtils . logDebug ( LOGGER , DEVICE_MGR_LOGGING_RESOURCE , getGcpProjectId ( ) , String . format ( "Cloud IoT device registered.\n%s" , registeredDevice . toPrettyString ( ) ) ) ; } catch ( IOException e ) { String message = String . format ( "Failed to register device. Cause: %s" , e . getMessage ( ) ) ; LogUtils . logError ( LOGGER , DEVICE_MGR_LOGGING_RESOURCE , getGcpProjectId ( ) , message ) ; throw new ClientException ( message , e ) ; } }
Register a device in a IoT Core registry
 @param iotDevice Device to register
 @param iotCoreRegistryPath IoT Core registry in which to register the device
 @param rsaCertificateFilePath Path to the file containing the device certificate
 @throws ClientException
Register a device in a IoT Core registry @param iotDevice Device to register @param iotCoreRegistryPath IoT Core registry in which to register the device @param rsaCertificateFilePath Path to the file containing the device certificate @throws ClientException