#include #include //#include #include #include #include #include #include #define WIFI_SSID "Herech" #define WIFI_PASSWORD "here" #define FIREBASE_HOST "http://here.firebasedatabase.app/" #define FIREBASE_AUTH "AIherelM" const int RECV_PIN = 14; IRrecv irrecv(RECV_PIN); decode_results results; int digit; int debounceDelay = 100; // Debounce delay in milliseconds int Timeout = 2000; // Number entry timeout in milliseconds unsigned long lastKeyTime = 0; const String channelsName[50] = {"BBC", "CNN", "ESPN", "HBO", "NBC", "GEO TV", "Hum TV", "FOX", "ABC", "ARY Digital", "CBS", "Discovery Channel", "National Geographic", "History Channel", "Cartoon Network", "MTV", "VH1", "Comedy Central", "TLC", "Food Network", "PTV", "Express News", "Dunya News", "Samaa TV", "Aaj News", "92 News", "Bol News", "Dawn News", "Capital TV", "Abb Takk News", "Khyber TV", "Lahore News HD", "Neo TV", "City 42", "Waqt News", "Royal News", "PTV News", "TV One", "ARY News", "PTV Sports"}; const int numChannels = 12; const unsigned long channelHex[numChannels] = { 0xFF6897, 0xFF30CF, 0xFF18E7, 0xFF7A85, 0xFF10EF, 0xFF38C7, 0xFF5AA5, 0xFF42BD, 0xFF4AB5, 0xFF52AD, 0xFFA25D, 0xFF629D }; int currentChannel = 0; const long utcOffsetInSeconds = 3600; char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; String weekDays[7]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; String months[12]={"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, "time.windows.com", utcOffsetInSeconds); WiFiUDP udp; FirebaseData firebaseData; FirebaseJson json; int Vrdata = 0; void setup() { Serial.begin(115200); WiFi.begin(WIFI_SSID, WIFI_PASSWORD); while (WiFi.status() != WL_CONNECTED) { delay(1000); Serial.println("Connecting to WiFi..."); } Serial.println("Connected to WiFi"); Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); //dht1.begin(); //dht2.begin(); timeClient.begin(); irrecv.enableIRIn(); } void handleNumberSelection(int digit) { unsigned long currentTime = millis(); if (digit >= 0 && digit <= 9) { if (currentTime - lastKeyTime >= Timeout) { currentChannel = digit; //Serial.print("Current Channel: "); //Serial.println(currentChannel); } else { if (currentChannel >= 0 && currentChannel <=99){ currentChannel = currentChannel * 10 + digit;} } Serial.print("Current Channel: "); Serial.println(currentChannel); lastKeyTime = currentTime; } } void handleChannelChange(int direction) { if (direction == 1) {if (currentChannel >= 0 && currentChannel <=99){ currentChannel++; }else{currentChannel =0;} } else if (direction == -1) {if (currentChannel >= 0 && currentChannel <=99){ currentChannel--; }else{currentChannel =99;} } Serial.print("Current Channel: "); Serial.println(currentChannel); } void loop() { if (irrecv.decode(&results)) { switch (results.value) { case 0xFF629D: handleChannelChange(1); break; case 0xFFA25D: handleChannelChange(-1); break; default: for (int i = 0; i <= 99; i++) if (results.value == channelHex[i]) { handleNumberSelection(i); } } // Serial.println(channelsName[currentChannel]); irrecv.resume(); delay(300); } timeClient.update(); time_t epochTime = timeClient.getEpochTime(); Serial.print("Epoch Time: "); Serial.println(epochTime); String formattedTime = timeClient.getFormattedTime(); Serial.print("Formatted Time: "); Serial.println(formattedTime); int currentHour = timeClient.getHours(); Serial.print("Hour: "); Serial.println(currentHour); int currentMinute = timeClient.getMinutes(); Serial.print("Minutes: "); Serial.println(currentMinute); int currentSecond = timeClient.getSeconds(); Serial.print("Seconds: "); Serial.println(currentSecond); String weekDay = weekDays[timeClient.getDay()]; Serial.print("Week Day: "); Serial.println(weekDay); //Get a time structure struct tm *ptm = gmtime ((time_t *)&epochTime); int monthDay = ptm->tm_mday; Serial.print("Month day: "); Serial.println(monthDay); int currentMonth = ptm->tm_mon+1; Serial.print("Month: "); Serial.println(currentMonth); String currentMonthName = months[currentMonth-1]; Serial.print("Month name: "); Serial.println(currentMonthName); int currentYear = ptm->tm_year+1900; Serial.print("Year: "); Serial.println(currentYear); for (int i=0; i<=20; i++){ Vrdata++; delay(20); } //Print complete date: String time_stamp = String(currentYear) + "-" + String(currentMonth) + "-" + String(monthDay) + " " +String(formattedTime) ; Serial.print("Current date is : "); Serial.println(time_stamp); Serial.println(""); int User1 = map(Vrdata,0,4095,0,1000); Serial.println(User1); json.set("/data",User1); json.set("Hex: ",results.value); json.set("Channel Number",currentChannel); json.set("timestamp",time_stamp); json.set("Channel Name",channelsName[currentChannel]); Firebase.updateNode(firebaseData,"/User1",json); Serial.printf("Set json... %s\n", Firebase.push(firebaseData, F("/dht_readings"), json) ? "ok" : firebaseData.errorReason().c_str()); //Wait for 5 seconds delay(5000); }