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 is available by default in WSO2 IoT Server.
MobX wants to disable the camera on the admin user's devices during working hours and enable the camera on the device after working hours. This is required because the admin has access to confidential data.
Let's get started!
Table of Contents |
---|
Create the event stream
Follow the steps given below to create the org.wso2.iot.triggerStream
stream that is required for the execution plan that generates two events.
Start WSO2 IoT Server:
Start the WSO2 IoT Server broker profile.
Code Block cd <IOTS_HOME>/bin sh broker.sh
Start the WSO2 IoT Server core profile.
Code Block cd <IOTS_HOME>/bin sh iot-server.sh
Next, start the WSO2 IoT Server analytics profile.
Code Block cd <IOTS_HOME>/bin sh analytics.sh
- Access the WSO2 IoT Server's analytics management console.
For access via secured HTTP:
https://<IOTS_HTTPS_HOST>:9445/carbon/
For example:https://localhost:9445/carbon/
For access via HTTP:
For example:http://<IOTS_HTTP_HOST>:9765/carbon/
http://localhost:9765/carbon/
On the Main tab click Streams that is under Events.
Click + Add Events Streams.
Enter the following values:
Event Stream Name org.wso2.iot.triggerStream
Event Stream Version 1.0.0
Payload Data Attributes Add 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
- Attribute Name :
- 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 disable and enable the camera on the devices during the specified time. Follow the steps given below:
- On the Main tab, click Execution Plans.
- Click Add Execution Plan.
Copy the execution plan that is given below and replace the sample content that is in the text box.
Code Block @Plan:name('TimedTriggers') /* define streams/tables and write queries here ... */ define trigger cronLockTriggerStream at '0 0 18 * * ?' ; /* Disable the camera on the device at 18:00 '0 0 18 * * ?' */ define trigger cronUnlockTriggerStream at '0 0 8 * * ?' ; /* Enable the camera on the device at 08:00 '0 0 8 * * ?' */ @Export('org.wso2.iot.triggerStream:1.0.0') define stream dataOut (isLocked bool); /* Send the camera disable operation at 18:00 */ from cronLockTriggerStream select true as isLocked insert into dataOut; /* Send the camera enable operation at 8:00 */ from cronUnlockTriggerStream select false as isLocked insert into dataOut;
- Click Add Execution Plan.
Create the execution plan to retrieve the active devices that belong to the admin user
The above execution plan is not aware of the devices that belong to the admin user. Therefore, you need to write another execution plan to 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 EMM Siddhi Extensions.
Follow the steps given below:
- On the Main tab, click Execution Plans.
- Click Add Execution Plan.
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 about what happens in the execution plan?
Expand title Click 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 want to send to the output stream to match the data types of the exported output stream.
For example, the output stream does not recognizeCAMERA
. Therefore, it is equaled tocode
using the termas
.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.
- Click Add Execution Plan.
Congratulations! You have successfully configured WSO2 IoT Server to enable the camera on the admin user's device after 6 PM and disable it after 8 AM.
Try it out
Follow the steps given below to try out the scenario given above.
Sign in to the WOS2 IoT Server device management console using
admin
as the username andadmin
as the password.Enroll an Android or iOS device.
Info 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, define0 50 12 * * ?
for thecronLockTriggerStream
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.50 PM.
Similarly, 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, define0 0 13 * * ?
for thecronUnlockTriggerStream
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?
- Want to know more about the WSO2 IoT Server Siddhi extensions? See WSO2 EMM Siddhi Extensions.
- Want to try out other tutorials that allow you to monitor devices?