Skip to content

Lockdown using the Flex API

Jeremy Brown edited this page Jul 26, 2024 · 2 revisions

Intro

You can trigger a lockdown in a couple of different ways. The first would be to iterate through a list of doors and manually controlling the door mode.

The other way would be to have a direct command configured in DNA Fusion. Using direct commands is faster and allows the DNA Fusion operator to manage the doors to control as opposed to having you provide UI elements to do the same thing. The other benefit is that direct commands provide better support for non-Mercury doors.

Disclaimer

However, when using the door modes API, if the door is configured to follow a time schedule, then the door could unlock when you want it to stay locked. The lock mode also prevents any valid card access during that time. If you have school officials or police that want to go through that door, they wouldn't be able to.

I recommend calling the door override mode and setting the door more to Card and/or Pin Required. That way, the door is secure, but the good guys could still gain access. The only way for a door to exit override mode is if you configure a duration or if you make the request to cancel the override mode.

Override Mode

The Door Override Mode can be used to override a door mode for a given amount of time. The selected mode is used during the specified time; once the temporary time expires, the door will revert back to its normal mode.

The Door Override Mode has three possible parameters:

  • Indefinite - Overrides the door’s normal mode and sets the reader to the specified mode permanently. The override must be cancelled for the door to resume its normal state.
  • Minutes - Sets the door mode on the selected door for the indicated amount of time. The number of minutes can be up to 16383 (over 11 days). The door will return to normal after the time has expired.
  • Seconds - Sets the door mode on the selected door for the indicated amount of time. The number of seconds can be up to 100 seconds. The door will return to normal after the time has expired.
  • Time of Day - Allows the operator to change the door mode until a specified ending time (in hours/ minutes). When using the Time of Day option, the mode will not necessarily end at the exact hour/minute you specify. Instead, it will last for a fixed number of whole minutes that is closest to the time specified. For example, if a door override mode was scheduled to end at 1:00:00 p.m., and it was 12:30:30 p.m. when the override was executed, the mode would end at 1:00:30 p.m.

Flex API

C# Sample

C# Excerpt from FusionX

    private int _minutes = 1;

    private DateTime TimeOfDay { get; set; } = DateTime.Today.AtNoon();

    private DoorMode _mode = DoorMode.Unlocked;

    private OverrideMode _overrideMode;

    private enum OverrideMode
    {
        Minutes,
        TimeOfDay,
        Indefinite,
        Seconds
    }

    private int GetTimeInterval()
    {
        var duration = 0;
        switch(_overrideMode)
        {
            case OverrideMode.Indefinite:
                duration = 0;
                break;
            case OverrideMode.Minutes:
                duration = _minutes;
                break;
            case OverrideMode.TimeOfDay :
                var span = TimeOfDay - DateTime.Today.AtMidnight();
                duration = (int) span.TotalMinutes;
                break;
            case OverrideMode.Seconds:
                duration = 1;
                break;
        };

        return (int)_overrideMode << 14 | duration;
    }

    private async Task SetOverrideMode()
    {
        if (!UserInfo[UserRights.AllowCtrlAcmMode])
            return;

        var url = $"/api/v2/hardware/door/{Data.UniqueKey}/overridemode";
        var response = await HttpClient.PostJSendAsync(url, new OverrideModeOptions { DoorMode = _mode, Duration = GetTimeInterval()});

        if (response.IsSuccess())
            Mixins.DisplayToast("Door mode changed successfully", null, SweetAlertIcon.Success);
        else
            Mixins.DisplayToast("Oops...", $"Something went wrong\r\n {response.Message}", SweetAlertIcon.Warning);
    }

    private async Task CancelOverrideMode()
    {
        if (!UserInfo[UserRights.AllowCtrlAcmMode])
            return;

        var url = $"/api/v2/hardware/door/{Data.UniqueKey}/overridemode";
        var response = await HttpClient.PostJSendAsync(url, new OverrideModeOptions { DoorMode = DoorMode.Disable, Duration = 0 });
        if (response.IsSuccess())
            Mixins.DisplayToast("Door override canceled successfully", null, SweetAlertIcon.Success);
        else
            Mixins.DisplayToast("Oops...", $"Something went wrong!\r\n {response.Message}", SweetAlertIcon.Warning);
    }

    public class OverrideModeOptions
    {
        public DoorMode DoorMode { get; set; }
        public int Duration { get; set; }
    }

    public enum DoorMode
    {
        Disable = 1,
        Unlocked = 2,
        Locked = 3,
        FacilityCodeOnly = 4,
        CardOnly = 5,
        PinOnly = 6,
        CardAndPinRequired = 7,
        CardOrPinRequired = 8
    }

Direct Commands

Direct commands can be used to link various commands together so that multiple items can be controlled at once.

  1. Select Hardware / Direct Commands / Manage from the Main Menu.
  2. Right-click on a category and select Add Command.

image

  1. Provide a name for the new Direct Command.

image

  1. Provide a Title, select “Set Temporary Override Mode,” the Door to control, and the Operation Mode.

image

  1. Repeat steps 4 and 5 to add all the doors you wish to control.
  2. Repeat 2-5 to add a “Cancel Override Mode” direct command for each door.

image

Flex API

To execute a direct command, you must first know the GUID-based unique key of the direct command.

C# Sample

Curl Example

Curl example to retrieve direct commands (bearer token is required and not included in this example)

curl -X GET "{URL}/api/v2/hardware/directcommands" -H "accept: application/json"

Response

{
  "status": "success",
  "data": [
    {
      "uniqueKey": "e5c0168c-c981-45dc-8e3a-6600023affae",
      "name": "OO Demo Room SSP-LX Lockdown",
      "category": "Default",
      "requirePassword": "none"
    }
  ]
}

Once you have the Unique Key, you can execute the direct command.

Curl example to execute a direct command (bearer token is required and not included in this example)

curl -X POST "{URL}/api/v2/hardware/directcommand/{uniqueKey}/execute" -H "accept: application/json"

Response

{
  "status": "success",
  "data": true
}

More Information

You can find more information on the swagger document and code samples provided here:

Clone this wiki locally