The Gateway SDK Device Module

Last modified: Jul 5, 2019 @ 06:44

This SDK module provides a simplified way to integrate with other standards:

  • It provides the DeviceManager for modelling the registered devices and its smart objects and resources.
  • It provides the DeviceAppIoTListener that calls the modelled resources from the DeviceManager.
  • It provides the classes Device, SmartObjectBase for modelling the device and its smart objects.
  • It provides a range of Resource classes representing different data types, like:
    • BooleanResource
    • FloatResource
    • StringResource, etc.
  • It lets the developer focus on implementation of smart objects and resources.

Example of the Gateway SDK Device Module Maven pom file:


Example of device module and internal device implementing the Smart Object:

public class InternalTemperature extends SmartObjectBase implements ResourceValueChangedListener {

    public InternalTemperature(Device device) {
        this(device, AppIoTModelProvider.getObjectModel(OBJECT_ID_TEMPERATURE), OBJECT_ID_TEMPERATURE, 0);
    public InternalTemperature(Device device, ObjectModel objectModel, Integer objectId, Integer instanceId) {
        super(device, objectModel, objectId, instanceId);

        addResource(new SensorValue(this, objectModel.getResourceModel(RESOURCE_ID_SENSOR_VALUE)));
        addResource(new FloatResource(this, objectModel.getResourceModel(RESOURCE_ID_MIN_MEASURED_VALUE), 0, 0f));
        addResource(new FloatResource(this, objectModel.getResourceModel(RESOURCE_ID_MAX_MEASURED_VALUE), 0, 0f));
        addResource(new StringResource(this, objectModel.getResourceModel(RESOURCE_ID_UNITS), UNIT));

        ResetResource resetResource = new ResetResource(this, objectModel.getResourceModel(RESOURCE_ID_RESET_MIN_MAX_MEASURED_VALUES));

    public void onResourceValueChanged(Resource resource, Object value) {
        if(resource.getResourceId() == RESOURCE_ID_SENSOR_VALUE) {
            float measurement = (float) value;
            FloatResource min = (FloatResource) getResource(RESOURCE_ID_MIN_MEASURED_VALUE);
            FloatResource max = (FloatResource) getResource(RESOURCE_ID_MAX_MEASURED_VALUE);
            min.setValue(min.getValue() > measurement ? measurement : min.getValue());  
            max.setValue(max.getValue() < measurement ? measurement : max.getValue());

Example of device module and internal device implementing the resource:

public class SensorValue extends FloatResource implements Runnable {

    private ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
    private int counter = 0;

    public SensorValue(SmartObjectBase smartObject, ResourceModel resourceModel) {
        super(smartObject, resourceModel);            
        this.counter = ((int)(Math.random() * 100.0D));

    protected void onObserveRequest() throws ObserveRequestException {
      if(scheduler.isTerminated()) {
        scheduler = Executors.newScheduledThreadPool(1);
        scheduler.scheduleAtFixedRate(this, 1, 1, TimeUnit.SECONDS);
    protected void onCancelObserveRequest() throws ObserveRequestException {

    public void run() {
        int offset = 50;
        float measurement = (float) (offset - offset * Math.cos(this.counter / 100.0 * 3.141592653589793D));
        this.counter += 10;

Example of device module and internal device:

DeviceManager deviceManager = new DeviceManager();

// Internal device for representing the gateway itself.
Device internalDevice = new Device();
SmartObjectBase internalTemperature = new InternalTemperature(internalDevice);

appIoTListener = new DeviceAppIoTListener(deviceManager);
appIoTGateway = new AppIoTGateway(appIoTListener);


The following diagram explains the Device Module operations and structure: