Writing Device Plugins via the Template
Before you begin
Clone the WSO2 Carbon Device Management Plugins repository. It will be referred to asÂ
<CARBON_DEVICE_MGT_PLUGINS>
 throughout this document.git clone https://github.com/wso2/carbon-device-mgt-plugins.git
Build the repo you just cloned.
cd <CARBON_DEVICE_MGT_PLUGINS> mvn clean install
All device types generally have common elements, such as specific attributes, feature management methods, and transport sender mechanisms. WSO2 IoTS identified these common areas and created a template that includes all these details. Using this template you can create your own device plugin. Let's take a quick look at how the device plugin is created from the template:
- Configure the
device-type-template.xml
file to meet your device type's requirement. - If your device type requires specific attributes, create a database and the required table to add these attribute details.
- Add the configured device type template to the
<CARBON_DEVICE_MGT_PLUGINS>/features/device-types-feature/<DEVICE>-feature-plugin/<ARTIFACT_ID>/src/main/resources/devicetypes
directory. - Once you are done with writing the plugin, UI, APIs and Analytics for the device, you need to buildÂ
<CARBON_DEVICE_MGT_PLUGINS>
. Clone WSO2 IoT Server if you have not done previously and build it.
git clone https://github.com/wso2/product-iots.git cd <PRODUCT_IOTS> mvn clean installÂ
- An OSGI bundle for the device type is created in WSO2 CDMF after reading the
device.xml
file.Â
Now you are done with creating the device plugin. It's a very easy with WSO2 IoTS. Let's look at an already implemented scenario to understand this concept.
Sample - writing device plugins
for this guide let's take a look at the already implemented Android plugin device type:
Take a look at the configured device type XML file, before you begin
To get a clear understanding of how you need to configure your device type, let's go through the properties of the XML file:
Property | Description |
---|---|
| Define the name of the device type. The name of the device you are creating will be mapped with the APIs, UIs and other elements when creating the device plugin. <DeviceTypeConfiguration name="android"> |
| Every device type will need to store device specific data. Therefore, define the table ID of the database to which you are storing the data in this property. <DeviceDetails table-id="AD_DEVICE"/> |
| Add the license agreement details under this property. If you are allowing third party users to use the device type you are creating, then this will be very useful to make sure they agree with the terms you mention. <License> <Language>en_US</Language> <Version>1.0.0</Version> <Text>This is license text</Text> </License> |
ProvisioningConfig | Your device type can be accessed by many tenants or only the super tenant that is created in WSO2 IoTS by default. Tenant management for a device type is configured within this property.
|
 DataSource | The device you create can have attributes specific to the device and you will need to save the data in WSO2 IoTS. This property lets you define the database and the respective table in the database where you will be saving the device specific details. Note The The attribute details were the column names of the table you created in the In the android plugin sample, we add the data to the <DataSource> <jndiConfig> <name>jdbc/MobileAndroidDM_DS</name> </jndiConfig> <tableConfig> <Table name="AD_DEVICE"> <PrimaryKey>DEVICE_ID</PrimaryKey> <Attributes> <Attribute>GCM_TOKEN</Attribute> <Attribute>DEVICE_INFO</Attribute> <Attribute>IMEI</Attribute> <Attribute>IMSI</Attribute> <Attribute>OS_VERSION</Attribute> <Attribute>DEVICE_MODEL</Attribute> <Attribute>VENDOR</Attribute> <Attribute>LATITUDE</Attribute> <Attribute>LONGITUDE</Attribute> <Attribute>SERIAL</Attribute> <Attribute>MAC_ADDRESS</Attribute> <Attribute>DEVICE_NAME</Attribute> <Attribute>OS_BUILD_DATE</Attribute> </Attributes> </Table> </tableConfig> </DataSource> |
Features | Your device type will carry out various operations. For example, an Android device needs to be locked and unlocked, the device location needs to be fetched and much more. Therefore, the feature management aspect of the device is handled by this property. You can list out all the features you wish for your device to have using the sub-properties listed below:
|
PushNotificationProvider | This property defines the transport over which the device and the server communicates. If the file based property is configured, WSO2 IoTS will read this file and communicate with the device based on the configured transport sender mechanism. If this property is not configured in the device type XML file, WSO2 IoTS will get the required details from platform configurations and you will need to configure the registry accordingly. Defining this property is useful when configuring the device type to communicate over many transport senders. <PushNotificationProvider type="MQTT"> <FileBasedProperties>true</FileBasedProperties> <!--if file based properties is set to false then the configuration will be picked from platform configuration--> <ConfigProperties> <Property Name="mqtt.adapter.name">android.mqtt.adapter</Property> <Property Name="username">admin</Property> <Property Name="password">admin</Property> <Property Name="qos">0</Property> <Property Name="clearSession">true</Property> </ConfigProperties> </PushNotificationProvider> |
TaskConfiguration | This property defines the operation types that needs to be trigger from the server. <TaskConfiguration> <Enable>true</Enable> <Frequency>60000</Frequency> //Name needs to be decided <!--Period--> <Operations> <Operation> <Name>DEVICE_INFO</Name> <RecurrentTimes>1</RecurrentTimes> //Name needs to be decided <!--PeriodFactor--> </Operation> <Operation> <Name>APPLICATION_LIST</Name> <RecurrentTimes>5</RecurrentTimes> </Operation> <Operation> <Name>DEVICE_LOCATION</Name> <RecurrentTimes>1</RecurrentTimes> </Operation> </Operations> </TaskConfiguration> |
PolicyMonitoring | This property defines whether the device types requires policy compliance monitoring. <PolicyMonitoring enabled="true"/> |
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 required a device agent? If yes, see Writing Device Agents.
- Write the analytics extensions for your device type. For more information, see Writing Analytics.