/* Cayenne WiFi Example This sketch connects to the Cayenne server using an Arduino WiFi shield and runs the main communication loop. The Cayenne Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager. Steps: 1. Set the token variable to match the Arduino token from the Dashboard. 2. Set the network name and password. 3. Compile and upload this sketch. For Cayenne Dashboard widgets using digital or analog pins this sketch will automatically send data on those pins to the Cayenne server. If the widgets use Virtual Pins, data should be sent to those pins using virtualWrites. Examples for sending and receiving Virtual Pin data are under the Basics folder. */ #define CAYENNE_DEBUG // Uncomment to show debug messages #define CAYENNE_PRINT Serial // Comment this out to disable prints and save space #define DHTTYPE DHT11 #define DHTPIN 14 //#define VIRTUAL_PIN V1 #include "CayenneDefines.h" #include "BlynkSimpleEsp8266.h" #include "CayenneWiFiClient.h" #include // Cayenne authentication token. This should be obtained from the Cayenne Dashboard. char token[] = ""; // Your network name and password. char ssid[] = ""; char password[] = ""; float humidity, temp_f; // Values read from sensor DHT dht(DHTPIN, DHTTYPE, 11); // 11 works fine for ESP8266 void setup() { Serial.begin(9600); Cayenne.begin(token, ssid, password); dht.begin(); } void loop() { Cayenne.run(); } CAYENNE_OUT(V0){ Serial.println("entered out"); // Send the command to get temperatures. //sensors.requestTemperatures(); // This command writes the temperature in Celsius to the Virtual Pin. //Cayenne.celsiusWrite(VIRTUAL_PIN, sensors.getTempCByIndex(0)); // To send the temperature in Fahrenheit use the corresponding code below. //Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0)); // Check if any reads failed and exit early (to try again). do { humidity = dht.readHumidity(); // Read humidity (percent) delay(1000); } while (isnan(humidity)); Serial.print("temp: "); Serial.println(temp_f); Serial.print("humidity: "); Serial.println(humidity); Cayenne.virtualWrite(V0, humidity); } CAYENNE_OUT(V1){ Serial.println("entered out"); // Send the command to get temperatures. //sensors.requestTemperatures(); // This command writes the temperature in Celsius to the Virtual Pin. //Cayenne.celsiusWrite(VIRTUAL_PIN, sensors.getTempCByIndex(0)); // To send the temperature in Fahrenheit use the corresponding code below. //Cayenne.fahrenheitWrite(VIRTUAL_PIN, sensors.getTempFByIndex(0)); // Check if any reads failed and exit early (to try again). do { temp_f = dht.readTemperature(true); // Read temperature as Fahrenheit delay(1000); } while (isnan(temp_f)); Serial.print("temp: "); Serial.println(temp_f); Serial.print("humidity: "); Serial.println(humidity); Cayenne.virtualWrite(V1, temp_f); }