code: public String registerOrSetDevice(final Device device) throws ApiException, IOException {
          try {
              return registerDevice(device);
          } catch (RestException e) {
              if (e.getError() == DeviceService.ERR_DUPLICATE_ID) {
                  setDevice(device);
                  return device.getId();
              }
              throw e;
          }
      }
docs: Registers a device with the provided device ID or sets it if already registered. This call is
  <b>BLOCKING</b> and should not be called on UI threads.
  
  See {@link #registerDevice(Device)} for more details.
  
  @param device The desired id for this device.
  @return The device id provided by the device
  @throws ApiException Thrown if the iobeam client is not initialized or there are problems
  writing the device ID.
  @throws IOException  Thrown if network errors occur while trying to register.