# Guard patrols and checkpoint tours

> How to run guard patrols in Vigil. Beacons mark the checkpoints, an agent requests each patrol on a schedule, and every scan is proof with a time and a name.

Source: https://vigilsecure.net/docs/examples/guard-patrols/

**The scenario.** A client wants proof that a guard walks the property every three hours
through the night: every gate, every door, the generator room and the perimeter corners.
You want to know about a missed round while it can still be fixed, not when the client
complains.

## How Vigil represents it

| The real world                  | In Vigil                                                                                    |
| ------------------------------- | ------------------------------------------------------------------------------------------- |
| The property                    | A [site](https://vigilsecure.net/docs/concepts/sites.md)                                                             |
| Each checkpoint on the round    | A [beacon](https://vigilsecure.net/docs/concepts/beacons.md) deployed to that site                                   |
| The guard on duty               | The [user](https://vigilsecure.net/docs/concepts/users.md) signed in on the site's [device](https://vigilsecure.net/docs/concepts/devices.md) |
| "Walk the round now"            | A patrol request message, sent by an [agent](https://vigilsecure.net/docs/concepts/agents.md)                        |
| The guard reaching a checkpoint | A beacon scan message                                                                       |
| The round, done or missed       | The patrol request's progress: scanned beacons out of the total, inside its time window     |
| "Every three hours"             | The agent's schedule                                                                        |
| The proof for the client        | An [artifact](https://vigilsecure.net/docs/concepts/artifacts.md) built from the scans                               |

## Set it up

### 1. Add the site and its beacons

Add the site from the [Overview](https://vigilsecure.net/docs/concepts/overview.md) map, then add a beacon at each
checkpoint. Use a **QR code** beacon where you can fix a label, and a **geofence** beacon
for open ground. Give each beacon the name a guard would use: `North gate`, `Generator
room`, `Parking level 2`.

### 2. Put a device on the site

[Link a device](https://vigilsecure.net/docs/concepts/devices.md#link-a-device) and leave it at the site. The guard
on shift signs in on it with their ID number.

### 3. Give an agent the job

[Create an agent](https://vigilsecure.net/docs/concepts/agents.md#create-an-agent) and write the patrol into its
instructions:

```text
You run the patrols at Rosebank Mall.

Every three hours from 18:00 to 06:00, ask the guard signed in at Rosebank Mall to
patrol all of the site's beacons, and give them 30 minutes.

Five minutes after each window closes, check the patrol. If beacons are missing, tell
the guard which ones, and tell Thandi Nkosi in her chat.

If nobody is signed in at the site, request a sign-in on the site's device first.
```

The agent needs to read sites, beacons and devices, see device locations, send device
commands and start chats. The admin role covers this, or create a
[custom role](https://vigilsecure.net/docs/concepts/roles.md#custom-roles) with only those permissions.

Then message the agent once to start it: "Set up your schedules from your instructions."
Schedules are created by the agent itself, so nothing happens until you ask. Check the
agent's **Schedules** tab to see them.

## What happens on a shift

1. **21:00.** The agent's schedule falls due. It finds the Rosebank beacons, sees that Sipho
   is signed in on the site's device, and posts a patrol request in its chat with him:
   seven beacons, to be done by 21:30.
2. Sipho's device sounds. The chat shows a **Patrol** card: **0 of 7 scanned · Ends 21:30**.
3. He walks the round. At each checkpoint he chooses **Scan** and reads the QR code, or
   checks in at the geofence. Each scan ticks off its beacon.
4. **21:24.** The card reads **All 7 scanned**. The agent thanks him. While a patrol is on
   track the agent stays quiet, so the guard is not interrupted.
5. **00:00.** The next request goes out. This time two beacons are still open when the
   window closes at 00:30.
6. **00:35.** The agent's check falls due. It tells Sipho which beacons were missed and
   messages Thandi.

An agent is woken by a scan or by its schedule, not by a window closing. That is why the
instructions ask for a check after each window. Without one, a missed patrol is reported
at the agent's next run.

If Sipho walks through an area with no signal, his scans are kept on the device with their
real times and sent when he is back in coverage. A scan made inside the window still counts.

## What counts as done

A scan fills its place on the patrol when all of these hold:

- The beacon is on the patrol and has not been scanned for it yet.
- The scan was made inside the patrol's time window.
- The patrol request is the latest one in that chat.

Any other scan, such as a second scan of the same beacon or one made after the window
closed, stays in the chat as an ordinary scan and does not count towards the patrol.

To have a single checkpoint checked, the agent sends a patrol with one beacon. On the device
it reads **Scan a beacon**.

## Report on it

Ask an agent for the record:

> Publish a report of this week's patrols at Rosebank Mall for the client. One row per
> patrol: start time, guard, beacons scanned out of the total, and how long it took. List
> every missed beacon at the end.

The agent publishes it as an artifact, which you can
[share with the client by link](https://vigilsecure.net/docs/concepts/artifacts.md#share-an-artifact-with-a-client).

## Variations

- **Different rounds.** Name the beacons: "the perimeter beacons at 22:00 and 04:00, all
  beacons at 01:00".
- **Ad hoc.** In a chat with the agent: "Ask whoever is at Rosebank to check the generator
  room now."
- **Several sites.** One agent can run the patrols for every site. Say so in its
  instructions.
- **No new agent.** Ask the Operations agent in a chat to run the patrols. Its instructions
  cannot be edited, but it keeps schedules like any other agent.

## Related

- [Guard check-ins](https://vigilsecure.net/docs/examples/guard-check-ins.md)
- [Automated client reports](https://vigilsecure.net/docs/examples/client-reports.md)
