Versions Compared

Key

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

...

  1. Write the API to switch the bulb on. Once WSO2 IoTS receives the command it will call the API you have written to switch the bulb on.

    Info

    For more more information, see Writing Device APIs.

  2. Define the operation type for the API in the <DEVICE_TYPE>SeviceImpl.java file. WSO2 IoTS supports the following 4 operation types.

    • POLICY
    • COMMAND
    • CONFIG
    • PROFILE

    Example: The RaspberryPiServiceImpl.java file has configured the bulb switching on and off API as a COMMAND operation.

    Code Block
    Operation commandOp = new CommandOperation();
    commandOp.setCode("bulb");
    commandOp.setType(Operation.Type.COMMAND);
    commandOp.setEnabled(true);
    commandOp.setPayLoad(actualMessage);
  3. The command then get's stored in the database for monitoring purposes and gets sent to push notifications. 

    Note

    Don't he push notification providers in WSO2 IoT Server meet your requirement? You can create your own push notification. For more information, see Adding a New Push Notification Provider.

    • The push notification method is implemented in the device plugin deviceManagerService.java file.
      Example: RaspberrypiManagerService.java

      Code Block
      private PushNotificationConfig populatePushNotificationConfig() {
       DeviceManagementConfiguration deviceManagementConfiguration = RaspberrypiManagementDataHolder.getInstance()
        .getDeviceTypeConfigService().getConfiguration(RaspberrypiConstants.DEVICE_TYPE,
         RaspberrypiConstants.DEVICE_TYPE_PROVIDER_DOMAIN);
       org.wso2.carbon.device.mgt.iot.devicetype.config.PushNotificationConfig sourceConfig =
        deviceManagementConfiguration.getPushNotificationConfig();
       Map < String, String > staticProps = new HashMap < > ();
       for (org.wso2.carbon.device.mgt.iot.devicetype.config.PushNotificationConfig.Property property: sourceConfig.getProperties()) {
        staticProps.put(property.getName(), property.getValue());
       }
       return new PushNotificationConfig(sourceConfig.getPushNotificationProvider(), staticProps);
      }

      Info

      You can define the control type and other statistics for the push notification to take place.

    • Configure and save the file containing the statisticsProps configurations anywhere you prefer. 
      Example: The statisticProps for the virtual fire alarm are defined in the <IoTS_HOME>/repository/conf/etc/device-mgt-plugins/raspberrypi-config.xml file.

      Code Block
      <PushNotificationConfiguration>
         <!--MQTT Config-->
         <PushNotificationProvider>MQTT</PushNotificationProvider>
         <Properties>
            <Property Name="mqtt.adapter.name">raspberrypi.mqtt.adapter</Property>
            <Property Name="url">tcp://localhost:1883</Property>
            <Property Name="username">admin</Property>
            <Property Name="dcrUrl">https://localhost:9443/dynamic-client-web/register</Property>
            <Property Name="qos">0</Property>
            <Property Name="scopes" />
            <Property Name="clearSession">true</Property>
         </Properties>
      </PushNotificationConfiguration>
      Note

      Make sure to define the dcURL for the transport.

  4. The command is then sent to the device.
    Follow the steps given below to find out if the device received the command: 

    1. Sign in to the WSO2 IoTS device management console.

      Expand
      titleClick here for more information.
      Panel
      borderColor#6A98FA
      bgColor#ffffff
      borderWidth1

      Insert excerpt
      Quick Start Guide
      Quick Start Guide
      nopaneltrue

    2. Click the device you sent the command. 
      Example: Click virtual fire alarm. 
    3. Click Operation logs, to view the status of the command you sent.

      Info

      The operation status can be any of the following values:

      • IN-PROGRESS - The operation is processing on the IoTS server side and has not yet been delivered to the device.
      • PENDING - The operation is delivered to the device but the response from the device is pending.
      • COMPLETED - The operation is delivered to the device and the server has received a response back from the device.
      • ERROR - An error has occurred while carrying out the operation.