Temperature Celsius / Fahrenheit

Hi,

I’m using a NodeMCU esp8266-12e for my cayenne project and I have attached a DHT22 temperature/humidity sensor to it.

I can read values with the following sketch:

#define CAYENNE_DEBUG         // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space

#include "CayenneDefines.h"
#include "BlynkSimpleEsp8266.h"
#include "CayenneWiFiClient.h"
#include "DHT.h"

#define DHTPIN 14
#define DHTTYPE DHT22

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "xxx";
// Your network name and password.
char ssid[] = "xxx";
char password[] = "xxx";
DHT dht(DHTPIN, DHTTYPE);

void setup()
{
  // initialize digital pin 2 as an output.
  pinMode(2, OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH); // high = off
  Serial.begin(9600);
  delay(200);
  Cayenne.begin(token, ssid, password);
  dht.begin();
}

void loop()
{
  Cayenne.run();
}

CAYENNE_OUT(V0)
{
  float t = dht.readTemperature();
  Serial.print("temp: ");
  Serial.println(t);
  Cayenne.virtualWrite(V0, t); //virtual pin
}

CAYENNE_OUT(V1)
{
  float h = dht.readHumidity();
  Cayenne.virtualWrite(V1, h); //virtual pin
}


// This function will be called every time a Dashboard widget writes a value to Virtual Pin 2.
CAYENNE_IN(V2)
{
  CAYENNE_LOG("Got a value: %s", getValue.asStr());
  int i = getValue.asInt();
  
  if (i == 0)
  {
	digitalWrite(2, LOW);
  }
  else
  {
	digitalWrite(2, HIGH);
  }  
}

It will connect to cayenne and provide temperature on V0 and humidity on V1. On the serial console the temperature is printed (Currently displays 24.4 degrees celsius).

When I add a temperature value using Custom Widget → Value I can choose between celsius and fahrenheit (and Kelvin) between the units. I choose celsius, since my raw value is already in celsius.

But after adding the widget, the value on the dashboard is displayed in Fahrenheit! It says “Celsius” under the value but the value itself is clearly Fahrenheit. When I add a temperature widget with the unit “Fahrenheit”, the dashboard displays the value as celsius (but showing Fahrenheit under it)!

What did I do wrong?

There are a few bugs with temperatures that need to be fixed. Since you are using an “Arduino” you can set up a generic analog input as a virtual pin and send the values to it. This will display the number exactly as you send it. Here is an example Battery Powered ESP8266 Temperature/Humidity Monitor with DHT11

Thanks. That indeed solved the problem. One tiny blemish is now that it shows “float” below the value and there are no units. But I can live with that :slight_smile:

Yep, it’s a work around until it’s officially fixed.