Dhex Lock app icon

Local API

Control Dhex Lock from your own systems on the same network: home automation, scripts or a dashboard.

API reference

Getting started

The API is on from the start and can be turned off under Remote control (API) in the admin menu. That screen shows the device's address, the port (2323 unless you choose another) and the access key, which is created automatically. The API only answers while kiosk mode is active.

Security

Send the key in one of three ways:

Authorization: Bearer <key>
X-Api-Key: <key>
...?token=<key>

Endpoints

Commands that change something need POST (PUT for the configuration). Parameters can be sent in the query string, as a form or as a JSON body. Answers are JSON: successful commands return {"ok":true} and errors return {"ok":false,"error":"..."} with a matching status code.

MethodPathParametersDoes
GET/api/statusDevice state, see below
POST/api/screen/offTurns the screen off
POST/api/screen/onTurns the screen on and brings the kiosk to the front
POST/api/web/loadurlLoads a page in web mode
POST/api/web/reloadReloads the page
POST/api/web/homeGoes to the start URL
POST/api/modemode = web, app or mediaChanges content mode
POST/api/brightnesspercent = 1–100 or systemSets the brightness
POST/api/volumepercent = 0–100Sets the volume
GET/api/camera/photocamera = front or back (optional)Takes a photo, answers with image/jpeg
GET/api/motionState of motion detection
GET/api/configThe whole configuration as JSON
PUT/api/configbody: configuration as JSONReplaces the configuration
POST/api/rebootRestarts the device

Status codes: 200 success, 400 wrong or missing parameter, 401 wrong key, 404 unknown path, 405 wrong method, 409 not possible in the current mode (for example a web command when web mode is not active), 413 request too large, 503 camera not available.

Examples

KEY=your-key
HOST=http://192.168.1.50:2323

curl -H "Authorization: Bearer $KEY" $HOST/api/status
curl -H "Authorization: Bearer $KEY" -X POST $HOST/api/screen/off
curl -H "Authorization: Bearer $KEY" -X POST "$HOST/api/web/load?url=https://example.com/menu"
curl -H "Authorization: Bearer $KEY" -X POST "$HOST/api/brightness?percent=40"
curl -H "Authorization: Bearer $KEY" -o photo.jpg "$HOST/api/camera/photo?camera=front"
curl -H "Authorization: Bearer $KEY" $HOST/api/config > config.json
curl -H "Authorization: Bearer $KEY" -X PUT --data-binary @config.json $HOST/api/config

Status

{
  "appVersion": "1.0.0",
  "appVersionCode": 1,
  "deviceOwner": true,
  "kioskActive": true,
  "mode": "web",
  "screenOn": true,
  "scheduledScreenOn": true,
  "brightnessPercent": -1,
  "volumePercent": -1,
  "web": { "url": "https://example.com/" },
  "battery": { "percent": 100, "charging": true, "temperatureC": 25.0 },
  "network": { "connected": true, "ip": "192.168.1.50" },
  "motion": { "enabled": true, "secondsSinceMotion": 3 },
  "device": { "manufacturer": "Samsung", "model": "SM-X200", "android": "14", "sdk": 34 },
  "freeStorageMb": 3561,
  "uptimeSeconds": 112,
  "timeMs": 1794326916492
}

Good to know

Motion detection

Turned on under Screensaver and motion in the admin menu. There you also find Test motion detection, which shows live when the camera detects motion and works without kiosk mode. The first time, the app asks for permission to use the camera (as Device Owner it is granted automatically). The camera compares pictures about four times per second. When it detects motion, the screensaver is woken and the inactivity timers are reset, and the screen is turned on if Turn the screen on at motion is on and the screen schedule allows it. Pictures are analysed on the device and are never saved or sent. A picture only leaves the device through /api/camera/photo.

API-beskrivning

Kom igÄng

API:et Àr pÄ frÄn början och kan stÀngas av under FjÀrrstyrning (API) i admin-menyn. SkÀrmen dÀr visar enhetens adress, porten (2323 om inget annat vÀljs) och Ätkomstnyckeln, som skapas automatiskt. API:et svarar bara medan kiosklÀget Àr aktivt.

SĂ€kerhet

Nyckeln skickas pÄ nÄgot av tre sÀtt:

Authorization: Bearer <nyckel>
X-Api-Key: <nyckel>
...?token=<nyckel>

Anrop

Kommandon som Àndrar nÄgot krÀver POST (PUT för konfigurationen). Parametrar kan skickas i frÄgestrÀngen, som formulÀr eller som JSON-kropp. Svaren Àr JSON: lyckade kommandon ger {"ok":true} och fel ger {"ok":false,"error":"..."} med passande statuskod.

MetodSökvÀgParametrarGör
GET/api/statusEnhetens lÀge (exempel i den engelska delen)
POST/api/screen/offSlÀcker skÀrmen
POST/api/screen/onTÀnder skÀrmen och lyfter fram kiosken
POST/api/web/loadurlLaddar en sida i webblÀget
POST/api/web/reloadLaddar om sidan
POST/api/web/homeGÄr till start-URL
POST/api/modemode = web, app eller mediaByter innehÄllslÀge
POST/api/brightnesspercent = 1–100 eller systemSĂ€tter ljusstyrkan
POST/api/volumepercent = 0–100SĂ€tter volymen
GET/api/camera/photocamera = front eller back (valfri)Tar en bild, svarar med image/jpeg
GET/api/motionRörelsedetekteringens lÀge
GET/api/configHela konfigurationen som JSON
PUT/api/configkropp: konfiguration som JSONErsÀtter konfigurationen
POST/api/rebootStartar om enheten

Statuskoder: 200 lyckat, 400 fel eller saknad parameter, 401 fel nyckel, 404 okÀnd sökvÀg, 405 fel metod, 409 gÄr inte i nuvarande lÀge (t.ex. webbkommando nÀr webblÀget inte Àr aktivt), 413 för stor förfrÄgan, 503 kameran gÄr inte att anvÀnda.

Exempel och statussvarets format stÄr i den engelska delen; de Àr desamma.

Att tÀnka pÄ

Rörelsedetektering

SlÄs pÄ under SkÀrmslÀckare och rörelse i admin-menyn. DÀr finns ocksÄ Testa rörelsedetekteringen, som visar direkt nÀr kameran upptÀcker rörelse och fungerar utan kiosklÀge. Första gÄngen frÄgar appen om lov att anvÀnda kameran (som Device Owner beviljas det automatiskt). Kameran jÀmför bilder ungefÀr fyra gÄnger per sekund. Vid rörelse vÀcks skÀrmslÀckaren och inaktivitetstiderna nollstÀlls, och skÀrmen tÀnds om TÀnd skÀrmen vid rörelse Àr pÄ och skÀrmschemat tillÄter det. Bilderna analyseras pÄ enheten och sparas eller skickas aldrig. En bild lÀmnar enheten bara genom /api/camera/photo.