Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <NTPClient.h>
- #include <esp8266-google-home-notifier.h>
- #include "DHT.h"
- #define DHTPIN 2
- #define DHTTYPE DHT22
- DHT dht(DHTPIN, DHTTYPE);
- int STARTHOUR = 9; //write here the time when the notifications start
- int ENDHOUR = 21; //write here the time to stop notifications
- const char* ssid = "NETSTREAM"; //enter here your wifi SSID name
- const char* password = "*#Magda2007"; //enter here your wifi PASSWORD
- String Notificare ="";
- unsigned long previous_time = 0;
- unsigned long pauza = 20000; // 20 seconds delay
- GoogleHomeNotifier ghn;
- const long utcOffsetInSeconds = 10800; //Edit here to get the right time for your area, delay is in seconds ! This value is valable for Romania CET
- WiFiUDP ntpUDP;
- NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);
- String daysOfTheWeek[7]={"vasárnap", "hétfő", "kedd", "szerda", "csütörtök", "péntek", "szombat"};
- String months[12]={"január", "február", "március", "április", "május", "június", "július", "augusztus", "szeptember", "október", "november", "december"};
- void initWiFi()
- {
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);
- Serial.print("Connecting to WIFI network");
- while (WiFi.status() != WL_CONNECTED) {
- Serial.print('.');
- delay(1000);
- }
- Serial.println("connected.");
- Serial.print("IP address: ");
- Serial.println(WiFi.localIP());
- }
- void setup()
- {
- Serial.begin(115200);
- Serial.println("");
- initWiFi();
- const char displayName[] = "Entryway speaker"; //Enter the name of your google home speaker here
- Serial.println("connecting to Google Home...");
- if (ghn.device(displayName, "hu") != true)
- {
- Serial.println(ghn.getLastError());
- return;
- }
- Serial.print("found Google Home(");
- Serial.print(ghn.getIPAddress());
- Serial.print(":");
- Serial.print(ghn.getPort());
- Serial.println(")");
- dht.begin();
- if (ghn.notify("Szia, a nevem D1 Mini, és el fogom mondani neked, a google home hangszórón keresztül, a pontos idöt, hömérsékletet, és páratartalmat, amit a szobádban mértem.") != true)
- {
- Serial.println(ghn.getLastError());
- return;
- }
- Serial.println("Done.");
- delay(15000);
- if (ghn.notify("A memóriámba betöltött kód elején, beállított órák között, 15 percenként, küldök értesítést, a hangszóródra.") != true)
- {
- Serial.println(ghn.getLastError());
- return;
- }
- Serial.println("Done.");
- timeClient.update();
- delay(20000);
- }
- void loop()
- {
- unsigned long current_time = millis();
- if ((WiFi.status() != WL_CONNECTED) && (current_time - previous_time >= pauza))
- {
- Serial.print(millis());
- Serial.println("Reconnecting to WIFI network");
- WiFi.disconnect();
- WiFi.reconnect();
- previous_time = current_time;
- }
- if (timeClient.getHours() > STARTHOUR)
- {
- if (timeClient.getHours() < ENDHOUR)
- {
- if (timeClient.getMinutes() == 0)
- {
- VorbesteGoogle();
- delay(120000);
- }
- if (timeClient.getMinutes() == 15)
- {
- VorbesteGoogle();
- delay(120000);
- }
- if (timeClient.getMinutes() == 30)
- {
- VorbesteGoogle();
- delay(120000);
- }
- if (timeClient.getMinutes() == 45)
- {
- VorbesteGoogle();
- delay(120000);
- }
- }
- }
- }
- void VorbesteGoogle()
- {
- timeClient.update();
- unsigned long epochTime = timeClient.getEpochTime();
- struct tm *ptm = gmtime ((time_t *)&epochTime);
- int monthDay = ptm->tm_mday;
- int currentMonth = ptm->tm_mon+1;
- int currentYear = ptm->tm_year+1900;
- String currentMonthName = months[currentMonth-1];
- float h = dht.readHumidity();
- float t = dht.readTemperature();
- float f = dht.readTemperature(true);
- if (isnan(h) || isnan(t) || isnan(f))
- {
- Serial.println(F("Failed to read from DHT sensor!"));
- return;
- }
- Notificare = Notificare +"Ma, ";
- Notificare = Notificare +daysOfTheWeek[timeClient.getDay()];
- Notificare = Notificare +", ";
- Notificare = Notificare +currentMonthName;
- Notificare = Notificare +monthDay;
- Notificare = Notificare +", ";
- Notificare = Notificare +currentYear;
- Notificare = Notificare +",a pontos idö, ";
- Notificare = Notificare + timeClient.getHours();
- Notificare = Notificare +"óra, és ";
- Notificare = Notificare + timeClient.getMinutes();
- Notificare = Notificare +"perc, ";
- Notificare = Notificare +"a hőmérséklet, ";
- Notificare = Notificare + String(t,1);
- Notificare = Notificare + "fok Celzius,";
- Notificare = Notificare + "és a relatív páratartalom pedig,";
- Notificare = Notificare + String(h,1);
- Notificare = Notificare + "százalék.";
- if (ghn.notify (Notificare.c_str()) != true)
- {
- Serial.println(ghn.getLastError());
- return;
- }
- Notificare = "";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement