diff --git a/aht20/aht20.go b/aht20/aht20.go index ddd8b50..8bab0d9 100644 --- a/aht20/aht20.go +++ b/aht20/aht20.go @@ -105,9 +105,10 @@ func (d *Dev) Sense(e *physic.Env) error { } // validate data - dataCrc := calculateCRC8(data[0:6]) - if d.opts.ValidateData && dataCrc != data[6] { - return &DataCorruptionError{Received: data[6], Calculated: dataCrc} + if d.opts.ValidateData { + if dataCrc := calculateCRC8(data[:6]); dataCrc != data[6] { + return &DataCorruptionError{Received: data[6], Calculated: dataCrc} + } } // check if measurement is ready