(I’m from Spain, so my english isn’t perfect, sorry)
Hi,
I have been workin in a project with DHT 22+Rain sensor+NodeMCU V3, but i have some problems.
-I don’t know how i can put the temperature in celsius
-I don’t know how i can put the humidity in percentage
-How I can invert the logic of the rain sensor in code?
I have been taking parts of diferents codes and I’m making this.
If somebody have any recomendation for de code, or an implementation of other sensor or actuator, I will thank.
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <DHT.h>
#define v2 2
#define SENSOR 2
#define DHTTYPE DHT22
#define DHTPIN 14
DHT dht(DHTPIN, DHTTYPE, 11);
char ssid[] = "";
char wifiPassword[] = "a4";
// Cayenne authentication info.
char username[] = "b";
char password[] = "422a";
char clientID[] = "d4adce";
unsigned long lastMillis = 0;
void setup() {
Serial.begin(115200);
dht.begin();
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
pinMode(SENSOR, INPUT);
}
long lastMsg = 0;
float temp = 0.0;
float hum = 0.0;
float diff = 1.0;
void loop() {
Cayenne.loop();
}
CAYENNE_OUT_DEFAULT()
{
float newTemp = dht.readTemperature();
temp = newTemp;
Serial.print("New temperature:");
Serial.println(String(temp).c_str());
Cayenne.virtualWrite(0, String(temp).c_str()); // channel 0
float newHum = dht.readHumidity();
hum = newHum;
Serial.print("New humidity:");
Serial.println(String(hum).c_str());
Cayenne.virtualWrite(1, String(hum).c_str()); // channel 1
}
CAYENNE_OUT(v2)
{
// Read data from the sensor and send it to the virtual channel here.
// For example, to send a digital value you can use the following:
int value = digitalRead(SENSOR);
Cayenne.virtualWrite(V2, value, TYPE_DIGITAL_SENSOR, UNIT_DIGITAL);
}