Callback: onDeviceDiscoveryRequest

Last modified: Jul 5, 2019 @ 06:41

This callback notifies the gateway implementation that DDM wants to know which devices are available to the gateway. This is part of the registration process, where devices are discovered.

The implementation looks up devices. This could be done through scanning with radio, querying a web interface, etc.

The implementation is expected to respond with a DeviceDiscoveryResponse for every device discovered.

If multiple gateways discover the same device, DDM reads the reported signal strength and orders the available gateways with the best signal strength first.

The following example implementation

@Override
public void onDeviceDiscoveryRequest(String correlationId, DeviceDiscoveryRequest deviceDiscoveryRequest) {

  String endpoint = "abcdef"; // A unique identifier of the device. E.g. MAC Address for a bluetooth device
  int signalStrength = -54; // A number indicating the quality of the connection between the gateway and the
  // device. This is used by DDM to list gateways where best connectivity is first.
  long observeTime = System.currentTimeMillis(); // UNIX timestamp in milliseconds UTC

  DeviceDiscoveryResponse deviceDiscoveryResponse = new DeviceDiscoveryResponse();
  deviceDiscoveryResponse.setLastObserved(observeTime);
  deviceDiscoveryResponse.setSignalStrength(signalStrength);

  try {
     getGateway().sendDeviceDiscoveryResponse(correlationId, endpoint, deviceDiscoveryResponse);
  } catch (GatewayException e) {
    logger.log(Level.WARNING, "Failed to send response to DDM", e);
  }
}

results in the following Register Device dialog. Note that the list of gateways that have reported that the device abcdef is available is ordered by signal strength.

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