Skip to content

Devices

Connect keeps a registry of every clock that calls in. For each clock it records:

  • Whether the clock is allowed.
  • The key the clock must present.
  • Its labels.
  • When and from where it was last seen.
  • What its package reported about it, in info. That is firmware, model and user counts.

Use the registry to decide which clocks you serve and to see how each one is doing.

A device is identified per endpoint by its device id. Its package reads that id from a serial number, a MAC address, a cloud id or a topic segment. The same id on two endpoints is two devices.

StatusMeaning
allowedServed. Every allowed device is a member of its endpoint’s sync group.
pendingKnown, and refused until you allow it.
blockedRefused.
Terminal window
hourctl devices # every device
hourctl devices --status pending # those waiting to be allowed
hourctl devices --endpoint office
hourctl device allow office <DEVICE>
hourctl device block office <DEVICE>
hourctl device forget office <DEVICE>

Blocking a device sends a device.blocked event. If the clock uses MQTT, also revoke its broker credential. See blocking a clock.

hourctl device forget removes the device, its cursors and its commands. If the device calls again, it is a new device.

A change to a device’s status or key reaches every instance within moments. See config versions.

You can register a device before it first calls in. It is allowed unless you give another --status. The --key option sets the key it must present.

Terminal window
hourctl device register office <DEVICE>
hourctl device register office <DEVICE> --status pending --key <KEY>

Over the API, send POST /api/tenants/{tenant}/devices with {"endpoint": "office", "device": "<DEVICE>", "status": "allowed", "key": "<KEY>"}. The status and key fields are optional.

It answers 201. It answers 400 in three cases:

  • The endpoint is unknown.
  • The id is not acceptable.
  • The device is already known.

Each endpoint has a new_devices setting. It decides what happens to a device that nobody registered.

A device takes its time zone from its endpoint (one zone per endpoint). Register clocks in different zones on separate endpoints.

new_devicesWhat happens
hold (default)The device registers itself as pending.
allowThe device registers itself as allowed.
refuseThe device is turned away and nothing is kept. Only devices you register get in.
Terminal window
hourctl endpoint set office --new-devices hold
Unknown device calls in Turned away 403, nothing kept Pending device.new; waits for you Allowed device.joined; served Registered ahead hourctl device register Blocked refused, kept refuse hold allow you allow it you block it block, allow
The endpoint's new_devices setting decides what becomes of a device nobody registered. A forgotten device is unknown again the next time it calls.

A device that registers itself is announced with a device.new event. The event carries device_id, status and remote_ip.

A device has joined its tenant and group the first time it is allowed. That happens when you register it as allowed, when you allow it after it waited, or when an endpoint set to allow lets it in. A device.joined event says so, once. The endpoint’s policy package then runs its joined hook. A hook could, for example, set the time or clear bench punches.

A device that you allow again after blocking it has not joined again.

An endpoint set to allow trusts the network its devices come from. Use hold or refuse where unknown devices can reach the listener.

LimitValue
Pending devices per endpointlimits.max_pending_devices, default 100. Use 0 for no limit. A new device beyond it is answered 429 until some are allowed, blocked, forgotten or expire.
ExpiryA pending device not heard from for 24 hours, or for retention_days if that is shorter, is forgotten. A device you registered as pending that has never called in is kept.
Terminal window
hourctl settings set max_pending_devices=50
  1. List the devices waiting to be allowed:

    Terminal window
    hourctl devices --status pending
  2. Check where it calls from and what it reported:

    Terminal window
    hourctl device show office <DEVICE>
  3. Allow it, or block it:

    Terminal window
    hourctl device allow office <DEVICE>
CaseAnswer
The package could not identify the device400
Unknown device, endpoint set to refuse403
Too many devices waiting, or the tenant at its device limit (strangers)429
Device pending or blocked403
Device did not present its key401
Too many devices pending at the endpoint429
The tenant’s devices together over its rate limit503 with Retry-After: 1
The database could not take the message (down, or failing over)503 database unavailable, try again, with Retry-After: 5
Its endpoint or tenant is stopped or suspended503 stopped or suspended, with Retry-After: 30

You can give a device a key that it must present with every message. The package decides where the key travels. It can travel in the query string (ZKTeco clocks send it as ComKey), in a header or in the message body. It can also be the key that a signature over the message is made with.

Setting a key queues the commands that give it to the device. That works if the package has a way to send a key. The old key, or none, stays valid until the device presents the new one. So the device is not locked out while its key changes.

If the package cannot send a key, set it on the device by hand.

keyMeaning
noneNo key. The device is taken at its word, whatever it presents.
pendingA new key is on its way. The old key, or none, is still accepted until the device presents the new one. That new key then becomes its key.
activeThe key is enforced. A device that presents another key, or none, is refused with 401. Then key_refused_at is set and key_presented is unregistered or none.

key_presented says what the device’s latest message carried:

key_presentedMeaning
registeredIts key, or the new one on its way to it.
unregisteredA key Connect does not hold for the device.
noneNo key.
CommandAPI (PATCH /api/tenants/{tenant}/devices/{endpoint}/{device})Effect
hourctl device key office <DEVICE> <KEY>{"key": "<KEY>"}Set a key: 1 to 128 characters, no control characters.
hourctl device key office <DEVICE> --clear{"key": null}Remove the key. The device is taken at its word again.
hourctl device key office <DEVICE> --adopt{"adopt_key": true}Make the key the device is presenting its key. If the device presented a key while it was held, this uses the first one it presented then. No command is sent. It fails if the device has presented no key.
hourctl device key office <DEVICE> --adopt-presented{"adopt_presented_key": true}Make the key the device is presenting now its key. This works even when it was held with another key (key_conflict_at).

Use --adopt in two cases:

  • A device arrives with a key already set.
  • A device was refused for presenting a key Connect does not hold.

Suppose an endpoint has new_devices = "hold". A device held there keeps the first key it presents while it waits (key_held: true). The --adopt option makes that key its key.

If a later message presents another key, that is a conflict. It shows as key_conflict_at. Check the clock first. Then --adopt-presented takes the key it presents now.

Setting, adopting or clearing the key clears both. See a held device’s key.

Only hourctl device show shows the keys themselves (registered, pending, presented). The API route is GET /api/tenants/{tenant}/devices/{endpoint}/{device}. The keys are sealed in the database with HOURADVANTAGE_SECRET_KEY. See secrets at rest. A key changed on one instance is accepted on every other at once.

A device has labels of its own. They lie over its endpoint’s labels, and the device’s value wins.

Labels do two jobs. They decide which people a sync group places on the device (placement). They also decide which devices a job targets.

LimitValue
Labels per device64
Key1 to 63 letters, digits, -, _, . or /
Value1 to 255 characters. It is made of plain words (letters, digits, -, _, .) joined by / into a path: west/nevada/plant-7

Both pick devices with a selector over these labels: area = warehouse, region ^= west/nevada and kind != kiosk.

Set and remove labels like this:

Terminal window
# set area, remove building
hourctl device label office <DEVICE> area=warehouse building=

Over the API, send PATCH /api/tenants/{tenant}/devices/{endpoint}/{device} with {"labels": {"area": "warehouse", "building": null}}. A value sets a label. A null removes it. Labels you do not name stay.

hourctl apply and hourctl export carry device labels as [[device_labels]]:

[[device_labels]]
endpoint = "office"
device = "<DEVICE>"
labels = { area = "warehouse" }
Terminal window
hourctl device show office <DEVICE> # status, keys, labels, info, hold, health, available commands and actions
hourctl device actions office <DEVICE> # its actions and commands, every parameter typed
hourctl device options office <DEVICE> # the settings it has, for set_settings
RouteReturns
GET /api/tenants/{tenant}/devices?endpoint=&status=&select=&limit=&after=A page of devices in (endpoint, device) order, each with its own labels. select keeps the devices a selector picks by their labels (hourctl devices --select "region ^= west/nevada"). limit is 1000 unless given, at most 10 000. For the next page, pass <endpoint>/<device> of the last device as after. A shorter page is the last.
GET /api/tenants/{tenant}/devices/{endpoint}/{device}The device, its keys, its hold, and the commands and actions its package offers.
GET /api/tenants/{tenant}/devices/{endpoint}/{device}/catalogWhat the device takes of its package: actions and commands with typed parameters, and the settings it has (for set_settings).
GET /api/tenants/{tenant}/devices/{endpoint}/{device}/commandsIts latest 500 commands, oldest first.
DELETE /api/tenants/{tenant}/devices/{endpoint}/{device}Forgets it (204; 404 if unknown).

Everything you send to a device is an action. Use POST /api/tenants/{tenant}/devices/{endpoint}/{device}/actions or hourctl action. An action can be one of three things:

  • A standard action.
  • One of the package’s own actions.
  • One of its commands, which is an action of one step.

A device takes what its package offers. That is judged from what the device reported. To reach many devices at once, run a job.

Terminal window
hourctl action office <DEVICE> upsert_user user_id=7 name="Ann Lee" --key req-123
hourctl action office <DEVICE> reboot --lane bulk
hourctl actions office <DEVICE>
hourctl action show office <DEVICE> 42
hourctl action cancel office <DEVICE> 42
hourctl action cancel office <DEVICE> 42 --give-up
OptionEffect
--key <REQUEST_KEY>Your own id for the request. If you send it again, the action queued the first time is returned.
--lane bulkQueue the steps behind everything else. The default lane is interactive.

A device is handed its commands when it next asks for them. On a pushed transport, it is handed them as they are queued. Its answers arrive as command.result and action.result events.

How long a device takes decides nothing. A command handed to a device stays in its hand until something says it is lost. While it stays, it is offered, counted, and has an age.

Three things can say a command is lost:

  • Its package names it missed. The engine keeps what was handed out and what was answered, and draws no conclusion from their order. The package does, as it handles a message, with M.missed(req, in_hand, answered) (package reference). A clock that answers in order is written as “a later write was answered, so the earlier writes with no answer are missed”. A device whose request says it restarted is written as “what it held is missed”. It is asked of every message that carries results, and of the requests of the routes the manifest lists, while commands are in the device’s hand.
  • You give up on it. hourctl action cancel office <DEVICE> 42 --give-up cancels what has not gone out. It gives up on the steps in the device’s hand. Use it for a clock that is not coming back.

The device’s record says what its commands add up to in commands. Get it from GET /api/tenants/{tenant}/devices/{endpoint}/{device}. It has three counts:

  • waiting: queued, not yet offered.
  • in_hand: offered in a reply, with no answer, and nothing has ended them.
  • unanswered: ended unanswered and still kept. A late answer takes one out of the count.

A device that has held a command for a long time without answering shows it in in_hand.

Some lost commands can be handed out again safely. Their package says so with resend = "writes". Such a command goes back in the queue once, with the same id.

If it is lost again, or if handing it out again is not safe, it is unanswered. Then three things happen:

  • A command.unanswered event is sent.
  • The log gets a warning, “command unanswered: it was lost”, naming the device and the command.
  • The command’s action fails there.

An answer that comes later still completes the command and gives a command.result. The log then gets one info line. It reads “late command result: the command was reported unanswered, and the device answered after all”. It names the command and says whether it succeeded.

A sink that names no events is sent action.result only. command.result and command.unanswered go to a sink that names them. See the default set.

A package may make a step of an action a gate. A gate is a step that must pass before anything more goes to the device. If a gate fails or goes unanswered, it holds the device.

While a device is held, nothing more is handed to it, on any lane. Sync is included. This lasts until you release it. What the device sends is taken in as usual.

A held device shows held in hourctl devices and hourctl device show. It has held_at, reason, action_id and step. A device.held event is also sent. See gates and holds.

  1. See why it is held:

    Terminal window
    hourctl device show office <DEVICE>
  2. Fix the cause on the device, then release it. What waits for it goes out again, in order:

    Terminal window
    hourctl device release office <DEVICE> --reason "user re-added by hand"

    Or cancel everything still waiting for it instead (each action’s reason says why):

    Terminal window
    hourctl device release office <DEVICE> --drop-queued

Over the API, send POST /api/tenants/{tenant}/devices/{endpoint}/{device}/release with {"drop_queued": false, "reason": "..."}. Both fields are optional.

The answer has the hold taken off and the ids of the actions and commands cancelled. It is 404 if the device is unknown. It is 409 if the device is not held. A device.released event says who released it and what was dropped.

The device list and hourctl device show show when and from where each device was last seen. The data comes from every running instance. The list waits for each instance until it answers or its session with the database ends. It does not give up after a time. An instance that ended without answering is named, with the reason, in the X-Instances-Unanswered response header. What the database holds is shown for what only that instance knew.

To save writes, the time is saved to the database every few minutes, not on every message. It is saved at once when the device’s address changes.

A device is back when it is let in after more than its endpoint’s back_after_minutes since it was last seen. A device.back event says so, once. The endpoint’s policy then runs its back hook with how long the device was away.

Nothing watches for absences. A return is seen only when the device calls. The saved time can lag by up to 5 minutes. So set back_after_minutes well above that.

Nothing watches for absences. The device list cannot be filtered or sorted by last_seen. It lists in endpoint and device order, with the time each was last seen.

To find the clocks that have gone quiet, list the allowed ones as JSON. Then keep those last seen before a cutoff, or never. last_seen is null for a device registered ahead that has not called.

Terminal window
hourctl device list --status allowed --json \
| jq -r --arg cutoff "$(date -u -d '-1 day' +%FT%TZ)" \
'.[] | select(.last_seen == null or .last_seen < $cutoff) | "\(.endpoint)/\(.device) \(.last_seen)"'

On macOS, use date -v-1d -u +%FT%TZ. The time is saved every few minutes, so use a cutoff of an hour or more.

Run it on a schedule and alert on any output. Over the API, the same list is GET /api/tenants/{tenant}/devices, a page at a time (after, limit).

Each device record carries health. It shows how the device’s messages have gone.

FieldMeaning
messagesMessages that got past its key. They were either taken in or refused for the device’s status.
errorsOf those, the ones that failed. A message fails when the package raised an error or ran out of time or memory, no route matched, or what the message changed could not be stored.
last_error{"at", "route", "reason"} of the latest failure. route is left out when no route matched. reason is at most 500 characters.

The counts add up across instances behind a load balancer. hourctl devices shows messages and errors. hourctl device show shows every field. For counts per endpoint, see the metrics houradvantage_requests_total (metrics).

A clock whose time is set ahead dates its punches in the future. The gateway does four things:

  • It marks the punches clock_ahead.
  • It keeps them out of the person’s punch state.
  • It puts clock_ahead (since, by_seconds) in the device’s info.
  • It tells of it once with a device.clock_ahead event.

See the status.

A ZK clock also keeps back its real punches after you put it right. This happens unless the stamp it is given is pulled back. Hour Advantage pulls it back. Hour Advantage tells you with a device.log event of kind stamp_rewound, after a CHECK at the clock’s next time sync. See the stamp.

Within one time sync after the clock’s time is right, it does two things. It re-sends what it held back, and it repeats among what it held back. The status clears when the next punch made at the right time arrives.

A device that stays clock_ahead with no punches arriving needs its clock looked at.

A clock whose time is held back dates its punches in the past. For example, a clock that keeps standard time through daylight saving is an hour behind. Every punch is an hour before it reaches Connect.

The punches look ordinary. So Connect says so as a fact and leaves them as the clock reported them. It never corrects a punch’s time.

A device is told as behind when all of these hold:

  • Its uploads are all late by more than 5 minutes. This is the tolerance of a clock set ahead.
  • The amounts of lateness are within 5 minutes of one another.
  • They have been late for longer than that amount. An hour late means for more than an hour.

Two cases are never told as behind:

  • A clock that was off and sends what it held. It sends one burst, and the lags are spread over the time it was off.
  • A clock whose uploads are late by amounts that drift apart.

Only punches whose offset Connect gave from the endpoint’s zone are looked at. A device that states its own offset in every timestamp is never behind this way. BrightLink’s devices do this.

Detection takes about as long as the lag after the clock goes wrong. For the daylight-saving hour, that is an hour. It is the same whichever gateway instance each upload reaches.

The device’s info carries clock_behind. It holds since, and by_seconds as first seen.

One device.clock_behind event is also told, once. It says what showed the problem:

  • The least and greatest lag.
  • How long the uploads had been late.
  • How many punches.
  • daylight_saving_hour, when the zone is in daylight time and the lag is the hour it saves.

While the status stands, the punches of a message that is not on time carry clock_behind_seconds. A message whose punches are on time clears the status. A later fault is told again.

Set the clock’s time and its daylight-saving setting, or take the setting off if the gateway is the one to keep time. See ZK.

Then watch the status clear with the next punch made at the right time.

The punches already stored stay as the clock reported them. In Time and Attendance, you correct them as you correct any punch.

A device has no rate of its own. Its messages are handled one step at a time, in the order they came. They wait their turn with the other devices’ messages, because devices take turns. So a device that sends without pause costs the others only its own turns.

What a device can have in hand depends on its protocol:

  • Over HTTP, it is one open connection for each message.
  • Over MQTT, it is the broker’s in-flight window. Connect acknowledges a message only once it has answered it (MQTT).

To cap a whole tenant’s devices, set its messages_per_second limit. Messages over the limit are answered 503 with Retry-After: 1, and nothing is lost.

Each failed device message is recorded, without the content of the message or the reply. Failures are kept for retention_days.

FieldMeaning
idIts id, for paging.
atWhen it failed.
endpoint, deviceWhose message it was.
routeThe package route that took it, when one matched.
requestMethod and path (no query, no body).
kindSee below.
statusWhat the device was answered.
errorThe error, at most 500 characters.
sourceWhere in the package it failed (main.lua:42), when the error says.
instanceThe instance that handled the message.
kindMeaning
lua_errorThe package raised an error.
timeoutThe package used up its work limit. A call may do 50,000,000 script steps: function calls, returns and loop iterations. The limit counts work, not time. So a call stops at the same place however busy the instance is.
memory_limitThe package ran past its memory limit.
no_routeThe device was identified, and no route of its package matched.
server_errorAnything else answered 5xx. Either what the message changed could not be stored, or the server failed.

In a burst of failures too large to record, the ones not recorded are counted in houradvantage_device_failures_dropped_total.

Terminal window
hourctl failures # newest first, 100 at most
hourctl failures --device <DEVICE> --since 2h
hourctl failures --endpoint office --limit 500

GET /api/tenants/{tenant}/failures?endpoint=&device=&since=&before=&limit= lists them newest first. limit is 100 unless given, at most 1000. since is RFC 3339. For the next page, pass the answer’s next as before. A page that comes back empty, or with next null, is the last.