Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/oceanbench/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import (
)

const (
version = "v0.32.3"
version = "v0.32.4"
localSite = "localhost"
localDevice = "localdevice"
localEmail = "localuser@localhost"
Expand Down
33 changes: 31 additions & 2 deletions cmd/oceanbench/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func calibrateDevicesHandler(w http.ResponseWriter, r *http.Request) {
return
}
ctx := context.Background()
_, err := getProfile(w, r)
p, err := getProfile(w, r)
if err != nil {
if err != gauth.TokenNotFound {
log.Printf("authentication error: %v", err)
Expand Down Expand Up @@ -506,13 +506,42 @@ func calibrateDevicesHandler(w http.ResponseWriter, r *http.Request) {
continue
}

// If the scalar value is zero, the division calculation will result in a
// divide by zero calculation. Return a message to the user, and do not
// calibrate this sensor.
const nearZeroValue = 0.05
if scalar.Value <= nearZeroValue {
msgs = append(msgs, "cannot calibrate sensor reading 0")
continue
}

// Calculate the new scale value.
sensor.Args = strconv.FormatFloat(actual/scalar.Value, 'f', -1, 64)
scaleFactor := actual / scalar.Value
sensor.Args = strconv.FormatFloat(scaleFactor, 'f', -1, 64)
log.Printf("calibrated sensor value for %s: %s", sensor.Name, sensor.Args)

// Save the sensor with the new scale factor.
model.PutSensorV2(ctx, settingsStore, &sensor)

if sensor.Name != model.NameBatterySensor {
continue
}

// Calibrate the alarm voltage and alarm recovery voltage variables.
skey, _ := profileData(p)
if va > 0 {
err := model.PutVariable(ctx, settingsStore, skey, model.NameAlarmVoltage, fmt.Sprintf("%d", int(va/scaleFactor)))
if err != nil {
msgs = append(msgs, fmt.Sprintf("unable to set alarm voltage: %v", err))
}
}
if vr > 0 {
err := model.PutVariable(ctx, settingsStore, skey, model.NameAlarmRecoveryVoltage, fmt.Sprintf("%d", int(vr/scaleFactor)))
if err != nil {
msgs = append(msgs, fmt.Sprintf("unable to set alarm recovery voltage: %v", err))
}
}

}

msg := strings.Join(msgs, ",")
Expand Down
5 changes: 3 additions & 2 deletions cmd/oceanbench/t/set/device.html
Original file line number Diff line number Diff line change
Expand Up @@ -247,20 +247,21 @@ <h2>Calibrate</h2>
<div class="row d-flex gx-1">
<label class="col-sm-2 col-md-3 col-1 text-end pt-2">Alarm Voltage:</label>
<div class="col-sm-10 col-md-6 col-12">
<input class="form-control" type="input" name="va" />
<input class="form-control" type="input" name="va" value="24.5" />
</div>
</div>
<div class="row d-flex gx-1">
<label class="col-sm-2 col-md-3 col-1 text-end pt-2">Alarm Recovery Voltage:</label>
<div class="col-sm-10 col-md-6 col-12">
<input class="form-control" type="input" name="vr" />
<input class="form-control" type="input" name="vr" value="25" />
</div>
</div>
<div class="row d-flex gx-1 align-items-center">
<div class="col-3 text-end pt-2"></div>
<input type="submit" class="btn btn-primary w-50" value="Calibrate Now" />
</div>
</form>
<small>NOTE: Sensors will only be calibrated whilst reading non-zero values</small>
</div>
</div>
{{if .Msg}}
Expand Down
3 changes: 3 additions & 0 deletions docs/oceanbench/device-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ That will open the follow popover menu.
![Calibration Popover](../images/device-calibrate-popover.png)
Measure the actual values for the measured voltage fields. In most cases, it will be acceptable to only measure the battery voltage (input screw terminals to the PCB), and use this as the calibration value for all voltages. If that is acceptable, leave the lock icon in the locked state. If each voltage needs to be calibrated independently, click on the padlock icon and leave it in the unlocked state. This will use the entered value to calibrate each voltage separately.

> [!NOTE]
> When calibrating a controller, calibration will only occur for non-zero sensor readings. To calibrate all sensors, ensure that all power variables are turned on, such that Power 1, 2, and 3 are all reading a non-zero voltage.

Enter the voltage value that the controller should enter a low voltage alarm, and the voltage which it should recover.

For any field that is left empty, this value will not be calibrated.
Expand Down
Loading