#define CAYENNE_DEBUG // Uncomment to show debug messages #define CAYENNE_PRINT Serial // Comment this out to disable prints and save space #include #include "DHT.h" int amarillo = 0; int blanco = 0; unsigned long time4 = 0; // WiFi network info. char ssid[] = ""; char wifiPassword[] = ""; // Cayenne authentication info. This should be obtained from the Cayenne Dashboard. char username[] = "-"; char password[] = ""; char clientID[] = "e"; // Set ESP8266 Serial object. In this example we use the Serial1 hardware serial which is available on boards like the Arduino Mega. #define EspSerial Serial #define DHTPIN 7 #define DHTTYPE DHT11 ESP8266 wifi(&EspSerial); DHT dht(DHTPIN, DHTTYPE); void setup() { pinMode(12, OUTPUT); pinMode(13, OUTPUT); Serial.begin(9600); delay(10); dht.begin(); // Set ESP8266 baud rate EspSerial.begin(9600); delay(10); Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword); } void loop() { Cayenne.loop(); if (millis() - time4 > 25000) // sends data every xx sec { float h = dht.readHumidity(); float t = dht.readTemperature(); Cayenne.luxWrite(2, analogRead(1)); Cayenne.virtualWrite(4, h, TYPE_RELATIVE_HUMIDITY, UNIT_PERCENT); Cayenne.virtualWrite(3, t, TYPE_TEMPERATURE, UNIT_CELSIUS); Cayenne.virtualWrite(0, millis() / 1000); time4 = millis(); // resets timer } } CAYENNE_IN(12) { amarillo = getValue.asInt(); CAYENNE_LOG("Channel %d, pin %d, value %d", 12, 12, amarillo); digitalWrite(12, amarillo); } CAYENNE_IN(13) { blanco = getValue.asInt(); CAYENNE_LOG("Channel %d, pin %d, value %d", 13, 13, blanco); digitalWrite(13, blanco); }