|
比如:传感器感应出的温度28℃,湿度75%在blinker APP上面可以显示温湿度,挺正常的
用小度问出来的温度也正常,但是问出来的湿度读数却是7500%,这是神马情况啊?
下面是我的代码:
#define BLINKER_WIFI
#define BLINKER_DUEROS_SENSOR
#include <Blinker.h>
#include <DHT.h>
char auth[] = "*****";
char ssid[] = "*****";
char pswd[] = "*****";
BlinkerNumber HUMI("num-shidu");
BlinkerNumber TEMP("num-wendu");
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
uint32_t read_time = 0;
float humi_read, temp_read;
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print("millis", BlinkerTime);
}
void heartbeat()
{
HUMI.print(humi_read);
TEMP.print(temp_read);
}
void DuerQuery(int32_t queryCode)
{
BLINKER_LOG("DuerOS Query codes: ", queryCode);
switch (queryCode)
{
case BLINKER_CMD_QUERY_ALL_NUMBER :
BLINKER_LOG("DuerOS Query All");
BlinkerDuerOS.temp(temp_read);
BlinkerDuerOS.humi(humi_read);
BlinkerDuerOS.print();
break;
case BLINKER_CMD_QUERY_TEMP_NUMBER :
BlinkerDuerOS.temp(temp_read);
BlinkerDuerOS.print();
break;
case BLINKER_CMD_QUERY_HUMI_NUMBER :
BlinkerDuerOS.humi(humi_read);
BlinkerDuerOS.print();
break;
default :
BlinkerDuerOS.temp(20);
BlinkerDuerOS.humi(20);
BlinkerDuerOS.print();
break;
}
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(D4, OUTPUT);
digitalWrite(D4, LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Blinker.attachHeartbeat(heartbeat);
BlinkerDuerOS.attachQuery(DuerQuery);
dht.begin();
}
void loop()
{
Blinker.run();
if (read_time == 0 || (millis() - read_time) >= 2000)
{
read_time = millis();
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
BLINKER_LOG("Failed to read from DHT sensor!");
return;
}
float hic = dht.computeHeatIndex(t, h, false);
humi_read = h;
temp_read = t;
BLINKER_LOG("Humidity: ", h, " %");
BLINKER_LOG("Temperature: ", t, " *C");
BLINKER_LOG("Heat index: ", hic, " *C");
}
}
|
|