#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT21
DHT dht(DHTPIN, DHTTYPE);
char temp[]=",";
String comdata;
int time;
bool flag=false;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(100);
dht.begin();
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()>0)
{
comdata="";
while(Serial.available()>0)
{
comdata+=char(Serial.read());
delay(2);
}
}
if(comdata.length()>0)
{
time=comdata.toInt();
flag=true;
}
else
{
time=999;
}
if(time=999)
{
if(flag=false)
{
Serial.print("99.9,99.9");
delay(time);
flag=true;
}
else
{
delay(time);
}
}
else
{
float h=dht.readHumidity();
float t=dht.readTemperature();
float f=dht.readTemperature(true);
if(isnan(h)||isnan(t)||isnan(f))
{
Serial.println("Failed to read from DHT sensor!");
return;
}
float hi=dht.computeHeatIndex(f,h);
char a[10]="";
char b[10]="";
dtostrf(h,2,1,a);
delay(10);
dtostrf(t,2,1,b);
strcat(a,",");
strcat(a,b);
Serial.print(a);
delay(time-10);
}
}