I had some difficulty finding simple examples of how to use the Reolink API and ended up digging through some python implementations to figure out how it works.
The official documentation is available at https://bit.ly/3rWxG6e but it is a bit lacking, and the API is somewhat weird, which makes it difficult. You should still look at it though, as it lets you know what commands are available through the API.
The main weirdness is that even if you are sending one command at a time, the payload has to be an array of objects and the response is always an array of objects. Also, you have to pass the command both as a URL parameter and in the payload.
Included here are a small(ish) bash script (also requires jq) for running API commands against Reolink cameras or NVRs.
How to set differents detection zone for the PTZ Cameras (AI and NON-AI)
Like the method for the privacy masks in the post bellow, here the commands (depends on cameras types) to generate multiple detection zones on the preset you choose.
Here the method, with @jasonk script, how you can apply a new detection zone after moving to a preset (without losing the others detection zones) :
Example : I have 2 presets (id1: -preset garage-, id2 : -preset entrance-)
FOR CAMERAS NON AI (like E1 Zoom)
For the first one which your have defined a detection zone (in my example id:1 -garage-), launch the command bellow and save the result in a file called, for example, json_detectionzone_id1 :
./rl-api GetMdAlarm '{"channel":0}' | jq '.[]|={channel,scope}' -c > json_detectionzone_id1
Switch to the second preset -id:2- and redefined a new detection zone (here the entrance), apply it, and and also launch the command to saved the result in a second file called json_detectionzone_id2:
./rl-api GetMdAlarm '{"channel":0}' | jq '.[]|={channel,scope}' -c > json_detectionzone_id2
After that, when you trigger PTZ Preset by id with the command (taken for @pixeldoc2000) and in my case the id:2 entrance-
./rl-api PtzCtrl '{"channel":0, "op":"ToPos", "id":2, "speed":32}
launch, after that previous command, the command dedicated to apply the detectionzone file for id:2 :
./rl-api SetMdAlarm $(cat json_detectionzone_id2)
NB : all the files json_detectionzone_idX are located in the same repository of the rl-api.sh executable.
FOR CAMERAS AI (without PetDetection) : based on the same example
For the first one which your have defined a detection zone (in my example id:1 -garage-), launch the command bellow and save the result in a file called, for example, json_detectionzoneAI_id1 :
./rl-api GetAiAlarm '{"channel":0,"ai_type":"people"}' | jq '{channel:.[].channel,md:.[].scope,people:.[].scope,vehicle:.[].scope}' -c > json_detectionzoneAI_id1
Switch to the second preset -id:2- and redefined a new detection zone (here the entrance), apply it, and and also launch the command to saved the result in a second file called json_detectionzoneAI_id2:
./rl-api GetAiAlarm '{"channel":0,"ai_type":"people"}' | jq '{channel:.[].channel,md:.[].scope,people:.[].scope,vehicle:.[].scope}' -c > json_detectionzoneAI_id2
After that, when you trigger PTZ Preset by id with the command (taken for @pixeldoc2000) and in my case the id:2 entrance-
./rl-api PtzCtrl '{"channel":0, "op":"ToPos", "id":2, "speed":32}
launch, after that previous command, the command dedicated to apply the json_detectionzoneAI file for id:2 :
./rl-api SetAlarmArea $(cat json_detectionzoneAI_id2)
NB : all the files json_detectionzoneAI_idX are located in the same repository of the rl-api.sh executable.
FOR CAMERAS AI (with PetDetection) : based on the same example
For the first one which your have defined a detection zone (in my example id:1 -garage-), launch the command bellow and save the result in a file called, for example, json_detectionzoneAI_pet_id1 :
./rl-api GetAiAlarm '{"channel":0,"ai_type":"people"}' | jq '{channel:.[].channel,md:.[].scope,people:.[].scope,vehicle:.[].scope,dog_cat:.[].scope}' -c > json_detectionzoneAI_pet_id1
Switch to the second preset -id:2- and redefined a new detection zone, apply it, and and also launch the command to saved the result in a second file called json_detectionzoneAI_pet_id2:
./rl-api GetAiAlarm '{"channel":0,"ai_type":"people"}' | jq '{channel:.[].channel,md:.[].scope,people:.[].scope,vehicle:.[].scope,dog_cat:.[].scope}' -c > json_detectionzoneAI_pet_id2
After that, when you trigger PTZ Preset by id with the command (taken for @pixeldoc2000) and in my case the id:2 -entrance-
./rl-api PtzCtrl '{"channel":0, "op":"ToPos", "id":2, "speed":32}
launch, after that previous command, the command dedicated to apply the json_detectionzoneAI_pet file for id:2 :
./rl-api SetAlarmArea $(cat json_detectionzoneAI_pet_id2)
NB : all the files json_detectionzoneAI_pet_idX are located in the same repository of the rl-api.sh executable.