-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #11, refine protocol, stat success rate
- Loading branch information
Showing
11 changed files
with
121 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <SimpleDHT.h> | ||
|
||
// for DHT11, | ||
// VCC: 5V or 3V | ||
// GND: GND | ||
// DATA: 2 | ||
int pinDHT11 = 2; | ||
SimpleDHT11 dht11; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
} | ||
|
||
void loop() { | ||
// start working... | ||
Serial.println("================================="); | ||
Serial.println("Sample DHT11 with error count"); | ||
|
||
int cnt = 0; | ||
int err_cnt = 0; | ||
for (;;) { | ||
cnt++; | ||
|
||
byte temperature = 0; | ||
byte humidity = 0; | ||
int err = SimpleDHTErrSuccess; | ||
if ((err = dht11.read(pinDHT11, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { | ||
Serial.print("Read DHT11 failed, err="); Serial.println(err);err_cnt++; | ||
} | ||
|
||
Serial.print("DHT11, "); | ||
Serial.print((int)temperature); Serial.print(" *C, "); | ||
Serial.print((int)humidity); Serial.print(" H"); | ||
Serial.print(", total: "); Serial.print(cnt); | ||
Serial.print(", err: "); Serial.print(err_cnt); | ||
Serial.print(", success rate: "); Serial.print((cnt - err_cnt) * 100.0 / (float)cnt); Serial.println("%"); | ||
|
||
delay(1500); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <SimpleDHT.h> | ||
|
||
// for DHT22, | ||
// VCC: 5V or 3V | ||
// GND: GND | ||
// DATA: 2 | ||
int pinDHT22 = 2; | ||
SimpleDHT22 dht22; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
} | ||
|
||
void loop() { | ||
// start working... | ||
Serial.println("================================="); | ||
Serial.println("Sample DHT22 with error count"); | ||
|
||
int cnt = 0; | ||
int err_cnt = 0; | ||
for (;;) { | ||
cnt++; | ||
|
||
float temperature = 0; | ||
float humidity = 0; | ||
int err = SimpleDHTErrSuccess; | ||
if ((err = dht22.read2(pinDHT22, &temperature, &humidity, NULL)) != SimpleDHTErrSuccess) { | ||
Serial.print("Read DHT22 failed, err="); Serial.println(err);err_cnt++; | ||
} | ||
|
||
Serial.print((float)temperature); Serial.print(" *C, "); | ||
Serial.print((float)humidity); Serial.print(" RH%"); | ||
Serial.print(", total: "); Serial.print(cnt); | ||
Serial.print(", err: "); Serial.print(err_cnt); | ||
Serial.print(", success rate: "); Serial.print((cnt - err_cnt) * 100.0 / (float)cnt); Serial.println("%"); | ||
|
||
delay(2500); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters