Skip to main content

Keypad Overview with Sessions

  1. Navigate to HSYCO Manager

  2. Create a new project or open an existing one

  1. Go into the Home page

  1. Click "add"

  1. Add a "Keypad"

  1. Move it to the right and enlarge it by dragging one of the corners

  1. Go back to "edit" mode

8. Change the "Name" attribute to "keypad1". This is the name of the command sent to the server

9. Change the "Digits" to "5". This is the number of digits that the keypad expects

  1. Change the "Label" to "Show Container"

  1. Click "add"

  1. Add a "Container"

  1. Click "edit"

  1. Enlarge the container so that it fits the space left in the page by the keypad

  1. Change the "ID" to "containerdummy"

  1. Change the "Enabled" attribute to "false"

  1. Change the "Opacity" to "0"

  1. Click "add"

  1. Add a "Button"

20. Make sure that the button is inside the container. If not, simply drag the button from the Select panel under the Container to put it inside it

  1. Move the button in the middle of the container by clicking "Align" and then "Center Horizontally" and "Center Vertically"

  2. Change the "Label" to "Dummy Light 1"

  1. Change the "Action" to "datapoint"

  1. Change the "Datapoint" to "dummy.light.1"

  1. Click "Save" to save the project

Tip: Great! Now we can write some code to capture the command sent by the keypad and enable the container if the 5 digit code is correct

  1. Go into the File Manager

  1. Navigate into the "events" folder

  1. Click "New File"

  1. Give it a name ("keypad.txt" for example) and click "New File

**30. Copy the following code and save:

function userCommand(session, userid, name, param) : {
var expectedValue = "12345";
if(name.equalsIgnoreCase("keypad1")){
if(param.equals(expectedValue)){
uiSessionSet(session, "containerdummy", "enabled", "true");
uiSessionSet(session, "containerdummy", "opacity", "1.0");
programTimerSet("keypadtimer-" + session, 15);
}
}
return "";
}

function programTimerEvent(name) : {
if(name.toLowerCase().startsWith("keypadtimer")){
var session = name.toLowerCase().split('-')[1];
uiSessionSet(session, "containerdummy", "enabled", "false");
uiSessionSet(session, "containerdummy", "opacity", "0");
}
}

What this does is, if the name of the command is "keypad1" and if the code wrote in the keypad is equal to the expected value, contained in a variable, then enable the container and set a program timer that after 15 seconds disables the container. All of this uses sessions, so the objects are not globally enabled or disabled but depends on the users and their unique session ID. The session ID is passed in the name of the program timer and is then retrieved by splitting this name. Note that in the programTimerEvent() function, the name of the program timer, passed as an argument, is upper case. To work with it, we simply use the toLowerCase() function that converts all the characters to lower case.**

**31. Go back to the Project Editor, click "Run" and "Default" to launch the application **

  1. As you can see, the container is initially disabled

  1. If we put "12345" in the keypad and press "OK", the container shows up and the button is now visible and clickable

  1. We now have 15 seconds to turn on and off the light

  1. 15 seconds after, the container is disabled and greyed out