This documentation is for WSO2 IoT Server 3.1.0. View the documentation for the latest release.
Page Comparison - Device Communicating with the Server (v.6 vs v.7) - IoT Server 3.1.0 - WSO2 Documentation

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Transform the data you receive, such as encoding the data, before sending it to WSO2 DAS. 

    Info

    In the case of the RaspberryPi device type, it uses the default content transformer that sends the data as it is to WSO2 DAS.

    1. If you wish to transform the content, you need to implement the contentTransformer interface.
      Example:

      Code Block
      public class MQTTContentTransformer implements ContentTransformer {}
    2. Customize the content transformer to match your requirement.
  2. Validate content.

    Info
    titleWhy validate?

    Once the MQTT transport extension/input adapter receives the data sent by the device, you will need to verify if it's a spoofer or if it's the device user that is sending the data. After this fact is verified you can configure WSO2 IoT Server to send the content to WSO2 DAS.

    In the RaspberryPi device type, the API path that is used to send the data is verified by checking if the device ID in it matches the ID of the device registered with WSO2 IoT Server. You can validate the content using the MQTT, HTTP, and XMPP content validators.

    1. Extend the content transformer interface, and customize it to suit our requirement.
      Example: MQTTContentValidator.java

      Code Block
      public class MQTTContentValidator implements ContentValidator {}
    2. Customize the content validator to match the device ID and verify the user and the device.
      Example: MQTTContentValidator.java

      Code Block
      public class MQTTContentValidator implements ContentValidator {
       private static final String JSON_ARRAY_START_CHAR = "[";
       private static final Log log = LogFactory.getLog(MQTTContentValidator.class);
       @Override
       public ContentInfo validate(Object msgPayload, Map < String, String > contentValidationParams,
        Map < String, String > dynamicParams) {
        String topic = dynamicParams.get(MQTTEventAdapterConstants.TOPIC);
        String topics[] = topic.split("/");
        String deviceIdJsonPath = contentValidationParams.get(MQTTEventAdapterConstants.DEVICE_ID_JSON_PATH);
        String deviceIdInTopicHierarchyLevel = contentValidationParams.get(
         MQTTEventAdapterConstants.DEVICE_ID_TOPIC_HIERARCHY_INDEX);
        int deviceIdInTopicHierarchyLevelIndex = 0;
        if (deviceIdInTopicHierarchyLevel != null && !deviceIdInTopicHierarchyLevel.isEmpty()) {
         deviceIdInTopicHierarchyLevelIndex = Integer.parseInt(deviceIdInTopicHierarchyLevel);
        }
        String deviceIdFromTopic = topics[deviceIdInTopicHierarchyLevelIndex];
        boolean status;
        String message = (String) msgPayload;
        if (message.startsWith(JSON_ARRAY_START_CHAR)) {
         status = processMultipleEvents(message, deviceIdFromTopic, deviceIdJsonPath);
        } else {
         status = processSingleEvent(message, deviceIdFromTopic, deviceIdJsonPath);
        }
        return new ContentInfo(status, msgPayload);
       }
  3. Configuring the Analytic Receiver by adding the following configurations.

    Info
    titleWhy configure the receiver?

    Once you have configured WSO2 IoT Server to transform and validate content, you need to direct the receiver that receives these data to the correct classpaths so as to transform and validate the content accordingly. This needs to be configured in the respective <DEVICE_TYPE>-receiver-<TENANT-DOMAIN>.xml.
    Example: raspberrypi_receiver-carbon.super.xml

    • Super Tenant configurations 

      Expand
      titleClick here for more information.
      Panel
      borderColor#11375B
      bgColor#ffffff
      borderWidth1
      1. Add the classpath to where you configured the content transformer.

        Info

        If you are using the default method provided by WSO2 IoT Server, you need to define the value as default. In the default method, the data received will be sent directly to WSO2 DAS without any transformation.

        Example: 

        Code Block
        <property name="contentTransformer">default</property>
      2. Add the classpath to where you configured the content validation.

        Info

        If you are using the default method provided by WSO2 IoT Server, you need to define the value as default. In the default method, the data received will be sent directly to WSO2 DAS without any validation.

        Example:

        Code Block
        <property name="contentValidator">org.wso2.carbon.device.mgt.iot.input.adapter.mqtt.util.MQTTContentValidator</property>
    • Tenant configurations
      Want to configure the analytics receiver for your tenant without using the super tenant configurations? Follow the steps given below:

      Expand
      titleClick here for more information.
      Panel
      borderColor#11375B
      bgColor#ffffff
      borderWidth1
      1. Open the respective <DEVICE_TYPE>-receiver-<TENANT-DOMAIN>.xml file..xml file that is in the carbon-device-mgt-plugins/features/device-types-feature/<DEVICE_TYPE>-plugin-feature/org.wso2.carbon.device.mgt.iot.<DEVICETYPE>.backend.feature/src/main/resources/receiver directory.
        Example: raspberrypi-receiver.xml
      2. Add the classpath to where you configured the content transformer.

        Info

        If you are using the default method provided by WSO2 IoT Server, you need to define the value as default. In the default method, the data received will be sent directly to WSO2 DAS without any transformation.

        Example: 

        Code Block
        <property name="contentTransformer">default</property>
      3. Add the classpath to where you configured the content validation.

        Info

        If you are using the default method provided by WSO2 IoT Server, you need to define the value as default. In the default method, the data received will be sent directly to WSO2 DAS without any validation.

        Example:

        Code Block
        <property name="contentValidator">org.wso2.carbon.device.mgt.iot.input.adapter.mqtt.util.MQTTContentValidator</property>
      4. Restart the WSO2 IoT Server's broker, core, and analytics profiles.

        Code Block
        cd <IOTS_HOME>/bin
        
        
        -----Start the broker profile------
        ./broker.sh or broker.bat
        
        
        -----Start the core profile---------
        ./iot-server.sh or iot-server.bat
        
        
        ----Start the analytics profile-----
        ./analytics.sh or analytics.bat
      5. Sign in to the device management console using your tenant credentials.
        If you are not sure of how to create a tenant, see adding a new tenant.
      6. Click the menu icon > CONFIGURATION MANAGEMENT > PLATFORM CONFIGURATIONS.
      7. Click on your device specific configuration (e.g., Raspberry Pi Configuration) and click Deploy

        Geo Analytics Artifacts.

        Analytics Artifacts.

        Info

        Navigate to the analytics console: https://<IOTS_HOST>:<IOTS_PORT>/carbon, click Receivers that is on the Main tab, and you will see that a new stream has for raspberrypi other than the receiver stream for the raspberrypi_receiver-carbon.super.

        Example:
        Image Added


      Info

      Optionally, if you want to configure the Analytic Receiver after deploying the artifacts, follow the steps given below:

      1. Navigate to the analytics console: https://<IOTS_HOST>:<IOTS_PORT>/carbon

        Info

        The default IoT Server host is localhost and the default analytics port on IoT Server is 9445.

      2. Click Receivers that is on the Main tab, and click on the event publisher your want to configure.
      3. Click Edit and edit the details of the receiver.
        Example:

        PropertyDescription
        Event Receiver Name

        This is the unique name of your event receiver. The name is similar to what you have defined in your <DEVICE_TYPE>-receiver-<TENANT-DOMAIN>.xml file.
        Example: raspberrypi_receiver-carbon.super.xml

        Code Block
        eventReceiver name="raspberrypi_receiver-carbon.super"
        Input-Event Adapter Type

        An input event adapter (transport) configuration via which the event receiver receives events.

        Note

        You can define the content transformer and validator properties only if you select oauth-mqtt or XMPP.

        Topic

        The name of the topic that the receiver needs to subscribe to.
        This is similar to what's defined in the raspberrypi_receiver-carbon.super.xml file.

        Code Block
        <property name="topic">carbon.super/raspberrypi/+/temperature</property>
        contentValidation

        Type of the content Validation or 'default' to set default type, required to implement (if required)

        contentTransformerType of the content transformer or 'default' to set default type, required to implement (if required)
      4. Click Update.