Arduino Uno + W5100 + DHT22 temperature units

I’m using Arduino Uno + W5100 + DHT22

Next code sends data to Cayenne

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?

On Android app it shows temperature in Celcius

Try:

Cayenne.celsiusWrite(VIRT_TEMP, t);

Instead of :

Cayenne.virtualWrite(VIRT_TEMP, t);

Same result

I have the same error, I ended up keeping it on fahrenheit in app, and calculated the value to celsius.

only a half solution.

Cayenne.virtualWrite(V0, (t -32) / 1.8);

Try my suggestion above:

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.

Hello,

Could you by any chance share the full code i am trying to do the same but i’m unable to get the data to cayenne…

Thanks

#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;
  }
}
1 Like

Wow thanks for the very fast answer !

@vahac were you able to get the widget displaying as you desired on your dashboard?

Custom Widgets - Value

I’ll take that as a yes – I’m going to move this issue to ‘resolved’.

thanks also from my side!
finally a solution that works!!!

1 Like

I put custom widget and value but i am still getting temp in fahrenheit what did you do to get in celsius ?

nothing
this is a bug

Arduino: 1.6.5 (Windows 8.1), Board: “Arduino/Genuino Uno”

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”

Used: C:\Program Files (x86)\Arduino\libraries\DHT_sensor_library

Not used: C:\Users\VINOD SUKHADEVE\Documents\Arduino\libraries\SimpleDHT

Multiple libraries were found for “CayenneSerial.h”

Used: C:\Users\VINOD SUKHADEVE\Documents\Arduino\libraries\Cayenne

Not used: C:\Program Files (x86)\Arduino\libraries\Cayenne

Error compiling.

This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.

You have made no mistake there is a fault in the Cayenne API/Widgets they all do this!