Callback: onDeviceRegisterRequest

Last modified: Jul 5, 2019 @ 06:41

This callback notifies the gateway implementation that a device is added, updated, or removed to/from the gateway.

The device is already registered in the SDK device registry.

  • By default, the device registry is stored as a json file named deviceregistry.json. This file is located in the root of APPIOT_HOME folder.
  • The device registry can use a custom implementation. Before calling start(), set the device registry:

    The device registry contains information about:

  • Device resources, if configured in DDM.
  • Setting categories attached to the device in DDM.

This information is also available in the DeviceReqisterRequest.

The implementation is expected to respond with a DeviceRegisterResponse.

Example of callback inplementation:

public void onDeviceRegisterRequest(String correlationId, String endpoint, DeviceRegisterRequest deviceRegisterRequest) {
  ResponseCode responseCode = null;
  String operation = deviceRegisterRequest.getOperation();
  switch (operation) {
  case Operation.POST:
    // Device registered to gateway
  case Operation.PUT:
    // Device registered to gateway is updated
  case Operation.DELETE:
    // Device removed from gateway
    String message = String.format("Operation not supported. %s", operation);
    logger.log(Level.WARNING, message);
    responseCode = new ResponseCode(message, ResponseCode.BAD_OPTION);

  DeviceRegistration deviceRegistration = gateway.getDeviceRegistry().getRegistrationByEndpoint(endpoint);
  for (SettingCategory settingCategory : deviceRegistration.getSettingCategories()) {
    logger.log(Level.INFO, String.format("### %s ###", settingCategory.getName()));
    for (Setting setting : settingCategory.getSettings()) {
      logger.log(Level.INFO, String.format("%s = %s", setting.getKey(), setting.getValue()));

  try {
    gateway.sendDeviceRegisterResponse(correlationId, endpoint, responseCode);
  } catch (GatewayException e) {
    logger.log(Level.WARNING, e.getMessage(), e);

The following figure shows the message sequence chart for the Device Discovery (steps 1-6) and Device Register (steps 7-10) processes.

The following figure shows the message sequence chart for the Device Connects process. In this case, DDM sends a Device Register Request to the Gateway before the Device connects to the Gateway.