Advertisement
Guest User

Weather Station NodeMCU

a guest
Oct 31st, 2017
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. #include <DHT.h>
  2. #include <IFTTTMaker.h>
  3. #include <ESP8266WiFi.h>
  4. #include <WiFiClientSecure.h>
  5.  
  6. #define DHTTYPE   DHT11
  7. #define DHTPIN    14  // The signal pin f the DHT11, in this case 14, which corresponds to D5
  8. #define EVENT_NAME "THE NAME OF THE IFTTT Event"
  9. #define KEY "YOUR IFTTT API KEY GOES HERE..."
  10.  
  11. float temperature, humidity;
  12. const char ssid[] = "YOUR WIFI SSID";  
  13. const char password[] = "YOUR WIFI PASSWORD";
  14.  
  15. DHT dht(DHTPIN, DHTTYPE, 11); // Defining the DHT11
  16. WiFiClientSecure client; // Defining the client
  17. IFTTTMaker ifttt(KEY, client); // Defining the use of IFTTT
  18.  
  19. void setup() {
  20.   dht.begin();
  21.   humidity = dht.readHumidity(); // Reads the humidity from the sensor and stores it in a variable
  22.   temperature = dht.readTemperature(); // Reads the temperature from the sensor and stores it in a variable
  23.  
  24.   Serial.begin(115200);
  25.   WiFi.mode(WIFI_STA);
  26.   WiFi.disconnect();
  27.   delay(100);
  28.   Serial.print("Connecting Wifi: ");
  29.   Serial.println(ssid);
  30.   WiFi.begin(ssid, password);
  31.  
  32.   while (WiFi.status() != WL_CONNECTED) {
  33.     Serial.print(".");
  34.     delay(500);
  35.   }
  36.   Serial.println("");
  37.   Serial.println("WiFi connected");
  38. }
  39.  
  40. void loop() {
  41.   humidity = dht.readHumidity();
  42.   temperature = dht.readTemperature();
  43.  
  44. // You need to paste the variables containing the sensor data, which need to be converted to String type.
  45.  
  46.   if (ifttt.triggerEvent(EVENT_NAME, (String)temperature, (String)humidity) {
  47.       Serial.println("Sent!");
  48.   }
  49.   else {
  50.       Serial.println("Failed!");
  51.   }
  52.   delay(3600000 * 6); // Amount of time between e-mails, in miliseconds // 3 600 000 miliseconds = 1 hour // 1 hour * 6 = 6 hours
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement