//#include "CayenneDefines.h" //#include "CayenneWiFi.h" //#include "CayenneWiFiClient.h" //#include #include "DHT.h" #include #include #include #include #include #define CAYANNE_DEBUG #define CAYANNE_PRINT Serial #define DHTPIN 2 #define DHTTYPE DHT11 // DHT 22 (AM2302), AM2321 #define VIRTUAL_PIN V2 #define VIRTUAL_PIN V3 #define RELAY_DIGITAL_PIN 3 // Analog pin the thermistor is connected to. const int thermistorPin = 0; // Resistance of the resistor. Currently set to 10k but this can be set to the measured resistance of your // resistor for greater accuracy. const float resistance = 10000; Thermistor thermistor(thermistorPin, resistance); // Cayenne authentication token. This should be obtained from the Cayenne Dashboard. // Change the value of token, ssid, and pwd to yours char token[] = "2hexhduvtt"; //char ssid[] = "xxxxxx"; ///char pwd[] = "xxxxx"; DHT dht(DHTPIN, DHTTYPE); void setup() { // put your setup code here, to run once: Serial.begin(9600); Cayenne.begin(token); dht.begin(); pinMode(RELAY_DIGITAL_PIN, OUTPUT); } void loop() { Cayenne.run(); } //Sensor DHT11 CAYENNE_OUT(V0) { float t = dht.readTemperature(); Cayenne.virtualWrite(V0, t); //virtual pin } CAYENNE_OUT(V1) { float h = dht.readHumidity(); Cayenne.virtualWrite(V1, h); //virtual pin } // This function is called when the Cayenne widget requests data for the Virtual Pin. CAYENNE_OUT(VIRTUAL_PIN) { // This command writes the temperature in Celsius to the Virtual Pin. Cayenne.celsiusWrite(VIRTUAL_PIN, thermistor.getCelsius()); // To send the temperature in Fahrenheit or Kelvin use the corresponding code below. //Cayenne.fahrenheitWrite(VIRTUAL_PIN, thermistor.getFahrenheit()); //Cayenne.kelvinWrite(VIRTUAL_PIN, thermistor.getKelvin()); } //Controle do relay luz de entrada CAYENNE_IN(VIRTUAL_PIN) { // get value sent from dashboard int currentValue = getValue.asInt(); // 0 to 1 // assuming you wire your relay as normally open if (currentValue == 0) { digitalWrite(RELAY_DIGITAL_PIN, HIGH); } else { digitalWrite(RELAY_DIGITAL_PIN, LOW); } }