com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_link3' is unknown.

Writing Device Plugins via Java Code

When writing a device type using the Java Code approach you need to write the device plugin, APIs, transports, UI, and analytics components from scratch. This section describes how to write the device plugin.

Why do we need a device plugin?

 Click here for more information.

A device plugin is an OSGi bundle that gets wired with the WSO2 Connected Device Management Framework (CDMF). When wrting a device type using the Java code approach the device requires a specific device plugin.  A specific device plugin is required due to the following reasons:

  • Enables its the device manufacturer or the device type creators to have control over the device.
  • A device can have its own unique set of attributes. Therefore it is necessary to maintain a separate data store to keep track of the data. This can be achieved by maintaining a separate data store for each device in the plugin layer.

To understand the device plugin implementation let's take a look at the Raspberry Pi device implementation. Follow the steps given below to create a new device plugin:

  1. Implement an interface for Raspberry Pi. For more information, see the implementation of DeviceManagerService for Raspberry Pi.

    Why is this step required?

    WSO2 IoT Server can have many device types. These device types will be registered on WSO2 CDMF when the OSGI runtime starts. For the new device type to be registered with the CDMF, it needs to have an interface that the OSGI identifies at its runtime. The DeviceManagementService interface is implemented for this reason. Therefore, it is important that you implement the DeviceManagementService interface extended from org.wso2.carbon.device.mgt.common.spi
    .
    DeviceManagementService. You are able to implement methods unique to a device by overriding the methods defined in the interface.

    The DeviceManagementService interface is shwon below.

    public interface DeviceManagementService {
        void init() throws DeviceManagementException;
        String getType();
        OperationMonitoringTaskConfig getOperationMonitoringConfig();
        DeviceManager getDeviceManager();
        ApplicationManager getApplicationManager();
        ProvisioningConfig getProvisioningConfig();
        PushNotificationConfig getPushNotificationConfig();
        PolicyMonitoringManager getPolicyMonitoringManager();
    }
     Click here to know more about the methods used to create the interface.
    • getType()
      Retrieves the name of the device-type.

    • init()
      The custom initialization implementations need to be included here.

    • getOperationMonitoringConfig()  
      Returns an object, which is an implementation of the org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig interface.
    • getDeviceManager()
      Returns an object, which is an implementation of the interface org.wso2.carbon.device.mgt.common.DeviceManager.

    • getApplicationManager()
      Returns an object, which is an implementation of the org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager interface. 

    • getProvisioningConfig()
      Returns the provisioning details, which includes the name of the tenant domain the device-type needs to be registered to and indicates whether the device-type is to be shared with all the tenants.
      true represents that the device-type should be visible to all tenants and false represents that it is not visible to other tenants.

    • getPolicyMonitoringManager()  
      Returns an object, which is an implementation of the org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager interface.
  2. Implement the DeviceManager interface. For more information, see the implementation of DeviceManager for Raspberry Pi.

    Why is this step required?

    Implement the interface DeviceManager for Raspberry Pi via the org.wso2.carbon.device.mgt.common.DeviceManager in order to implement the getDeviceManager()method that is shown in step 1. The DeviceManager interface will be used for enrolling, disenrolling, activating and deactivating a device. 

  3. Create a Database Access Object (DAO) on the created DeviceManager interface to manage data source connections.

  4. Register as an OSGI service.
    Example:

    ServiceRegistration raspberrypiServiceRegRef = bundleContext.registerService(DeviceManagementService.class.getName(), new RaspberrypiManagerService(), null);

    RaspberrypiManagerService is the implementation of the interface showed in step 1.

  5. Start the IoT Server.

    cd <IoTS_HOME>
    ./wso2server.sh

How it works

The following section describes how a Raspberry Pi is enrolled using a created device plugin:

  • The device enrollment calls will be passed through the DeviceManager implementation in the DeviceManagerService.

  • The DeviceManager implementation implements the interface org.wso2.carbon.device.mgt.common.DeviceManager.
  • The implemented interface manages the data of the Raspberry Pi, such as information related to enrollment, status, ownership, claimable, license and tenant configuration. 
  • The implementation needs to be included in an OSGI bundle. Once the bundle is activated, the device will be registered on the Connected Device Management Framework (CDMF).

What's next?

com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.