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?
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
DeviceManagerService
for Raspberry Pi.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(); }
Implement the
DeviceManager
interface. For more information, see the implementation ofDeviceManager
for Raspberry Pi.Why is this step required?
Implement the interface
DeviceManager
for Raspberry Pi via theorg.wso2.carbon.device.mgt.common.DeviceManager
in order to implement thegetDeviceManager()
method that is shown in step 1. TheDeviceManager
interface will be used for enrolling, disenrolling, activating and deactivating a device.Create a Database Access Object (DAO) on the created
DeviceManager
interface to manage data source connections.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.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 theDeviceManagerService
.- The
DeviceManager
implementation implements the interfaceorg.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?
- 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.