void loop()
{
Cayenne.run();
getDhtValues();
}
void getDhtValues() {
unsigned long now = millis();
if (now - prev_DHT_refresh > interval_DHT_refresh) {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Check if any reads failed
if (!isnan(h) && !isnan(t)) {
Cayenne.virtualWrite(VIRT_HUM, h);
Cayenne.virtualWrite(VIRT_TEMP, t);
}
prev_DHT_refresh = now;
}
}
everything work good except that Cayenne shows temperature in Fahrenheit not Celcius as I setup in temperature widget and Arduino code.
Where I made a mistake?
Why Cayenne shows temp in Fahrenheit?
It’s 6 in one half dozen in the other. Either you send to Cayenne what type of data it is or in the dashboard you select your starting data type and what you want to convert to. Personally I think it makes the most sense to put it in your code what you are sending then the dashboard knows what it was without configuring it.
#include "DHT.h"
//#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneEthernet.h>
#define DHTPIN 8 // what digital pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
#define VIRT_TEMP V1
#define VIRT_HUM V2
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "token";
DHT dht(DHTPIN, DHTTYPE);
unsigned long prev_DHT_refresh, interval_DHT_refresh = 1000;
void setup()
{
Serial.begin(9600);
Cayenne.begin(token);
dht.begin();
}
void loop()
{
Cayenne.run();
getDhtValues();
}
void getDhtValues() {
unsigned long now = millis();
if (now - prev_DHT_refresh > interval_DHT_refresh) {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Check if any reads failed
if (!isnan(h) && !isnan(t)) {
Cayenne.virtualWrite(VIRT_HUM, h);
Cayenne.celsiusWrite(VIRT_TEMP, t);
}
prev_DHT_refresh = now;
}
}
In file included from C:\Program Files (x86)\Arduino\libraries\DHT_sensor_library\DHT_U.cpp:22:0:
C:\Program Files (x86)\Arduino\libraries\DHT_sensor_library\DHT_U.h:25:29: fatal error: Adafruit_Sensor.h: No such file or directory #include <Adafruit_Sensor.h>
^
compilation terminated.
Multiple libraries were found for “DHT.h”