-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathdht_command.h
46 lines (41 loc) · 1.02 KB
/
dht_command.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <DHTlib.h>
dht DHT;
void dht_command() {
char* arg = sCmd.next();
if(arg == NULL) {
argument_error();
return;
}
int dht_type = atoi(arg);
arg = sCmd.next();
if(arg == NULL) {
argument_error();
return;
}
int dht_pin = atoi(arg);
int chk;
// just the dht 11 sensor read function is different
if (dht_type == 11) {
chk = DHT.read11(dht_pin);
} else {
chk = DHT.read(dht_pin);
}
switch (chk) {
case DHTLIB_OK:
Serial.print("ACK ");
Serial.print(DHT.temperature, 1);
Serial.write(' ');
Serial.print(DHT.humidity, 1);
Serial.print("\r\n");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("ERR checksum_error\r\n");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print("ERR timeout_error\r\n");
break;
default:
Serial.print("ERR unknown_error\r\n");
break;
}
}