Skip to content
Open
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
8 changes: 5 additions & 3 deletions dht22/dht22.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions dht22/doc.go
Original file line number Diff line number Diff line change
@@ -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
Loading