This documentation is for WSO2 IoT Server 3.2.0. View the documentation for the latest release.
Page Comparison - Sending Operations to Devices Based on Time (v.12 vs v.13) - IoT Server 3.2.0 - WSO2 Documentation

Versions Compared

Key

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

This document is work in progress and can only be viewed by those at WSO2!

In this tutorial, you are configuring WSO2 IoT Server to disable the camera on the Android devices that belong to the admin user after 8 AM and enable the camera on the device after 6 PM. The admin user  The admin user is available by default in WSO2 IoT Server. 

MobX wants to disable the camera on the admin user's camera devices during working hours and enable the camera on the device at 6 PMafter working hours. This is required because the admin has access to confidential data.

Let's get started!

Table of Contents

...

Follow the steps given below to create the org.wso2.iot.triggerStream stream that is required for the excution execution plan that generates two events.

  1. Start WSO2 IoT Server:

    1. Start the WSO2 IoT Server broker profile.

      Code Block
      cd <IOTS_HOME>/bin
      sh broker.sh
    2. Start the WSO2 IoT Server core profile.

      Code Block
      cd <IOTS_HOME>/bin
      sh iot-server.sh
    3. Next, start the WSO2 IoT Server analytics profile.

      Code Block
      cd <IOTS_HOME>/bin
      sh analytics.sh
  2. Access the WSO2 IoT Server's analytics management console.
    1. For access via secured HTTP: https://<IOTS_HTTPS_HOST>:9445/carbon/ 
      For example: https://localhost:9445/carbon/

    2. For access via HTTP:  http://<IOTS_HTTP_HOST>:9765/carbon/ 

      For example: http://localhost:9765/carbon/
  3. On the Main tab click Streams that is under Events.

  4. Click + Add Events Streams.

  5. Enter the following values:

    Event Stream Name

    org.wso2.iot.triggerStream

    Event Stream Version

    1.0.0

    Payload Data AttributesAdd a payload data attribute by entering the details given below and clicking Add.
    • Attribute Name : isLocked
    • Attribute Type: Select bool from the drop-down list

  6. Click Add Event Stream.

Create the execution plan to generate two events for 8 AM and 6 PM

You need to create an execution plan to send the disable and disable and enable the camera on the devices during the specified time. Follow the steps given below:

...

The above execution plan is not aware of the devices that belongs belong to the admin user. Therefore, you need to write another execution plan to admin get the admin users devices so that the execution plan you created above can be executed on the filtered devices. This can be done using the WSO2 IoT Server Siddhi Extensions.

...

  1. On the Main tab, click Execution Plans.
  2. Click Add Execution Plan.
  3. Copy the execution plan that is given below and replace the sample content that is in the text box.

    Code Block
    @Plan:name('TimedTasks_operations')
     
    @Import('org.wso2.iot.triggerStream:1.0.0')
    define stream dataIn (isLocked bool);
      
    @Export('org.wso2.iot.operation:1.0.0')
    define stream dataOut (meta_deviceIdentifiers string, meta_deviceType string, code string, type string, isEnabled bool, payLoad string);
      
    /* Filter the amin users devices to enable and disable the camera */
    from dataIn[device:hasDevicesOfUser("shavi", "android", "ACTIVE")]
    select device:getDevicesOfUser("shavi", "android", "ACTIVE") as meta_deviceIdentifiers, "android" as meta_deviceType, "CAMERA" as code, "COMMAND" as type, not isLocked as isEnabled, "{}" as payLoad
    insert into dataOut;
    Info

    Want to know more on about what happens in the execution plan?

    Expand
    titleClick here for more information.
    • First, you need to define the import the stream where you get the data from , and export the stream to which the data is inserted.

      Code Block
      @Import('org.wso2.iot.triggerStream:1.0.0')
      define stream dataIn (isLocked bool);
      
      @Export('org.wso2.iot.operation:1.0.0')
      define stream dataOut (meta_deviceIdentifiers string, meta_deviceType string, code string, type string, isEnabled bool, payLoad string);
    • Next, you need to filter out the devices that belong to the admin user. This is done using the device:hasDevicesOfUser extension.
    • Then you convert the data you got want to send to the output stream to match the data types of the exported output stream. In this example, it is stream dataOut.
      For example, the output stream does not recognize CAMERA. Therefore, it is equalled equaled to code using the term as.

      Code Block
      "CAMERA" as code
    • After converting the data to the format that the output stream identifies, you need to insert the data to the output stream.
  4. Click Add Execution Plan.

...

  1. Sign in to the WOS2 IoT Server device management console using admin as the username and admin as the password.

  2. Enroll an Android or iOS device.

    Info
    • For more information on how to enroll an Android device, see Android.
    • For more information on how to enroll an iOS device, see iOS.
  3. Change the time on the TimedTriggers execution plan to match your current time. If you want the camera to be disabled at 12.50 PM, define 0 50 12 * * ? for the cronLockTriggerStream property.
    Example:

    Code Block
    define trigger cronLockTriggerStream at '0 50 12 * * ?' ; /* Disable the camera on the device at 12:50 '0 50 12 * * ?' */

    Now, you see that the camera can't be accessed at 12.45PM50 PM.

  4. Similarly,

     Change

    change the time on the TimedTriggers execution plan to match your current time. If you want to enable the camera on the device at 1 PM

    the

    , define 0 0 13 * * ? for the cronUnlockTriggerStream property.
    Example:

    Code Block
    define trigger cronUnlockTriggerStream at '0 0 13 * * ?' ; /* Enable the camera on the device at 13:00 '0 0 13 * * ?' */

    Now, you see that you can access the camera after 1 PM.

What's next?