diff --git a/dht22/dht22.go b/dht22/dht22.go index 0cec9ac..ecc11a5 100644 --- a/dht22/dht22.go +++ b/dht22/dht22.go @@ -104,9 +104,11 @@ func (d *Dev) Read() (physic.Env, error) { } // Verify checksum - checksum := data[0] + data[1] + data[2] + data[3] - if data[4] != checksum { - return physic.Env{}, errors.New("dht22: checksum error") + if len(data) >= 5{ + checksum := data[0] + data[1] + data[2] + data[3] + if data[4] != checksum { + return physic.Env{}, errors.New("dht22: checksum error") + } } // Parse data (big-endian) diff --git a/dht22/doc.go b/dht22/doc.go new file mode 100644 index 0000000..65b9135 --- /dev/null +++ b/dht22/doc.go @@ -0,0 +1,15 @@ +// Copyright 2016 The Periph Authors. All rights reserved. +// Use of this source code is governed under the Apache License, Version 2.0 +// that can be found in the LICENSE file. + +//package dht22 is a driver for dht22/am2302 temperature and humidity sensor +// +//to start use function: "New" +// +//to read data from use function: "Read" +//or u can read data continiusly from chanale whate create by function: "SenseContinuous" +// +//datasheet: +//https://cdn-shop.adafruit.com/datasheets/Digital+humidity+and+temperature+sensor+AM2302.pdf + +package dht22 \ No newline at end of file