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?
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.
Before you begin
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:
Implement an interface for Raspberry Pi. For more information, see the implementation of
DeviceManagerServicefor Raspberry Pi.
DeviceManagementServiceinterface is shwon below.Click here to know more about the methods used to create the interface.
DeviceManagerinterface. For more information, see the implementation of
DeviceManagerfor Raspberry Pi.
Why is this step required?
Implement the interface
DeviceManagerfor Raspberry Pi via the
org.wso2.carbon.device.mgt.common.DeviceManagerin order to implement the
getDeviceManager()method that is shown in step 1. The
DeviceManagerinterface will be used for enrolling, disenrolling, activating and deactivating a device.
Create a Database Access Object (DAO) on the created
DeviceManagerinterface to manage data source connections.
Register as an OSGI service.
RaspberrypiManagerServiceis the implementation of the interface showed in step 1.
Start the IoT Server.
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
DeviceManagerimplementation in the
DeviceManagerimplementation implements the interface
- 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).
- Haven't written APIs yet for your device? See Writing Device APIs.
- Have you tried adding a UI for your device type? See Writing UI Extensions.
- Does your device type require a device agent? If yes, see Writing Device Agents.
- Write the analytics extensions for your device type. For more information, see Writing Analytics.