add dht22 and RHT03 support
This commit is contained in:
parent
8f85f7fb0a
commit
45ede69308
3 changed files with 27 additions and 22 deletions
|
@ -72,7 +72,7 @@
|
|||
#endif
|
||||
#if REST_RES_DHT11
|
||||
#include "dev/dht11.h"
|
||||
uint8_t dht11_temp=0, dht11_hum=0;
|
||||
uint16_t dht11_temp=0, dht11_hum=0;
|
||||
#endif
|
||||
|
||||
#if defined (PLATFORM_HAS_BUTTON)
|
||||
|
@ -141,7 +141,7 @@ info_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_
|
|||
|
||||
/* Some data that has the length up to REST_MAX_CHUNK_SIZE. For more, see the chunk resource. */
|
||||
// jSON Format
|
||||
index += sprintf(message + index,"{\n \"version\" : \"V0.3\",\n");
|
||||
index += sprintf(message + index,"{\n \"version\" : \"V0.4\",\n");
|
||||
index += sprintf(message + index," \"name\" : \"6lowpan-climate\"\n");
|
||||
index += sprintf(message + index,"}\n");
|
||||
|
||||
|
@ -691,8 +691,7 @@ hw_init()
|
|||
ds1820_temp();
|
||||
#endif
|
||||
#if REST_RES_DHT11
|
||||
dht11_temp=DHT_Read_Data(DHT_Temp);
|
||||
dht11_hum=DHT_Read_Data(DHT_RH);
|
||||
DHT_Read_Data(&dht11_temp, &dht11_hum);
|
||||
#endif
|
||||
}
|
||||
#define MESURE_INTERVAL (20 * CLOCK_SECOND)
|
||||
|
@ -802,8 +801,7 @@ PROCESS_THREAD(rest_server_example, ev, data)
|
|||
PRINTF("Periodic\n");
|
||||
etimer_reset(&ds_periodic_timer);
|
||||
#if REST_RES_DHT11
|
||||
dht11_temp=DHT_Read_Data(DHT_Temp);
|
||||
dht11_hum=DHT_Read_Data(DHT_RH);
|
||||
DHT_Read_Data(&dht11_temp, &dht11_hum);
|
||||
#endif
|
||||
#if REST_RES_DS1820
|
||||
if(ds1820_convert()){
|
||||
|
|
|
@ -29,7 +29,10 @@
|
|||
#define udelay(u) clock_delay_usec(u)
|
||||
#define mdelay(u) clock_delay_msec(u)
|
||||
|
||||
uint8_t DHT_Read_Data(uint8_t select){
|
||||
// define for DHT11 else for DHT22, RHT03
|
||||
#define DHT11 1
|
||||
|
||||
uint8_t DHT_Read_Data(uint16_t *temperature, uint16_t *humidity){
|
||||
|
||||
//data[5] is 8byte table where data come from DHT are stored
|
||||
//laststate holds laststate value
|
||||
|
@ -48,13 +51,17 @@ uint8_t DHT_Read_Data(uint8_t select){
|
|||
//Set pin Output
|
||||
//Pin High
|
||||
DHT_DRIVE();
|
||||
mdelay(250); //Wait for 250mS
|
||||
// mdelay(250); //Wait for 250mS
|
||||
mdelay(100); //Wait for 100mS
|
||||
|
||||
//Send Request Signal
|
||||
//Pin Low
|
||||
OUTP_0();
|
||||
mdelay(20); //20ms Low
|
||||
|
||||
OUTP_0(); //20ms Low
|
||||
#if DHT11
|
||||
mdelay(20);
|
||||
#else
|
||||
udelay(500);
|
||||
#endif
|
||||
//Pin High
|
||||
OUTP_1();
|
||||
udelay(40); //40us High
|
||||
|
@ -106,12 +113,17 @@ uint8_t DHT_Read_Data(uint8_t select){
|
|||
|
||||
//Check if data received are correct by checking the CheckSum
|
||||
if (data[0] + data[1] + data[2] + data[3] == data[4]) {
|
||||
if (select==DHT_Temp) { //Return the value has been choosen
|
||||
return(data[2]);
|
||||
}else if(select==DHT_RH){
|
||||
return(data[0]);
|
||||
}
|
||||
#ifdef DHT11
|
||||
*humidity = data[0];
|
||||
*temperature = data[2];
|
||||
#else
|
||||
*humidity = (uint16_t)data[0]<<8 | data[1];
|
||||
*temperature = (uint16_t)data[2]<<8 | data[3];
|
||||
#endif
|
||||
return 0;
|
||||
}else{
|
||||
*humidity = 2;
|
||||
*temperature = 2;
|
||||
// uart_puts("\r\nCheck Sum Error");
|
||||
}
|
||||
|
||||
|
|
|
@ -63,10 +63,5 @@
|
|||
//and 2 transitions which indicates End Of Frame. In total 84
|
||||
#define MAXTIMINGS 84
|
||||
|
||||
//Select between Temp and Humidity Read
|
||||
#define DHT_Temp 0
|
||||
#define DHT_RH 1
|
||||
|
||||
//This is the main function which requests and reads the packet
|
||||
uint8_t DHT_Read_Data(uint8_t select);
|
||||
|
||||
uint8_t DHT_Read_Data(uint16_t *temperature, uint16_t *humidity);
|
||||
|
|
Loading…
Reference in a new issue