Calibration - adzurek/nofo_samples GitHub Wiki
Here you can find the examples of how to:
How to calibrate lock:
Lock calibration consits of a few steps that need to be done in a right order:
- Initialize calibration process.
To do that you have to call the /my/lock/calibrationstep
endpoint like in the example below. You'll need to provide the deviceId (this can be fetched from lock details endpoint).
var body = new
{
DeviceId = deviceId
};
var response = await _apiClient.PostAsJsonAsync("/api/v1.12/my/lock/calibrationinit", body);
if (!response.IsSuccessStatusCode)
{
Console.WriteLine(response.StatusCode);
return;
}
var result = (await response.Content.ReadAsAsync<ApiResponse<CalibrationInitReturn>>()).Result;
var operationId = result.OperationId;
Console.WriteLine($"OperationId: {operationId}");
The operationId is returned. This is required in the rest of the calibration endpoints to assosiate requests with the initialized operation.
Before continuing, you have to wait for the CalibrationStepResult
notification that will be sent on your device registered in notification hub, containing the Step
property equal to 0.
- Set first step of the calibration.
Once the calibration process is initialized, we have to set the lock to the locked position and let the service know about that. Assuming that the lock is fully locked now, we need to call /my/lock/calibrationstep
endpoint with Step
property set to 1. Below is the sample code, which will do that. (OperationId
is the one that was returned in the first step.)
var body = new
{
DeviceId = deviceId,
Step = 1,
OperationId = operationId
};
var response = await _apiClient.PostAsJsonAsync("my/lock/calibrationstep", body);
if (!response.IsSuccessStatusCode)
{
Console.WriteLine(response.StatusCode);
return;
}
You'll get the CalibrationStepResult
notification with Step
equal to 1 when the step is finished.
- Set second step of the calibration
Once you get the notification, you're ready to go with the second position. You should change the lock position to be fully open and send this information to the service. To do that you should call exactly the same endpoint as in point 2, but this time change the value of Step
to 2.
When everything goes well you'll get another CalibrationStepResult
notification with Step
equal to 2 meaning that the basic initialization process is completed.
Now, depending on whether the pull spring option is enabled, you can calibrate it or stop at this step.
How to calibrate pull spring:
Assuming the pull spring is enabled, you should calibrate it. This is done the same way as the lock calibration. The only difference are the endpoints:
/my/lock/pullspringcalibrationinit
- to initialize pull spring calibration/my/lock/pullspringcalibrationstep
- to set the step of the pull spring calibration
How to cancel calibration
Lock calibration as well as pull spring calibration can be cancelled at any step. To do that you just have to call the proper endpoint:
/my/lock/calibrationcancel
- to cancel lock calibration/my/lock/pullspringcalibrationcancel
- to cancel pull spring calibration In both cases, you'll need the value of operationId that is returned in the initialization step. Below is an example of the code to cancel lock calibration.
var body = new
{
DeviceId = deviceId,
OperationId = operationId
};
var response = await _apiClient.PostAsJsonAsync("my/lock/calibrationcancel", body);
if (!response.IsSuccessStatusCode)
{
Console.WriteLine(response.StatusCode);
return;
}
Console.WriteLine("Calibration cancel request has been sent.");
When the calibration gets cancelled you'll get the CalibrationCancelResult
notification.