Senin, 18 Januari 2021

Sketch NodeMCU Auto Tarhim Masjid Sei. Kakap

Note: 
Source code is under develop. Use any syntax you need. 

Referensi pengawatan DF Player Mini dan NodeMCU ESP8266 (https://www.nn-digital.com/blog/2019/06/13/mp3-player-menggunakan-dfplayer-mini-dan-arduino/ dan https://www.anakkendali.com/esp8266-nodemcu-wemos-mengakses-mp3-dfplayer/), silahkan sesuaikan pin-pin yang digunakan dengan kode program / sketch dibagian bawah.



Sumber gambar dibawah ini adalah https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299 :






Catatan penting cara meng-copy file ke micro sd yang digunakan untuk DF Player Mini:

Copy your mp3 into you micro SD card

NOTE: The order you copy the mp3 into micro SD card will affect the order mp3 played , which means play(1) function will play the first mp3 copied into micro SD card.

Sketch Auto Tarhim Masjid Sei. Kakap:

//----------------------------------------Include the NodeMCU ESP8266 Library---------------------------------------------------------------------------------------------------------------//
//----------------------------------------see here: https://www.youtube.com/watch?v=8jMr94B8iN0 to add NodeMCU ESP8266 library and board
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <ESP8266WebServer.h>

#include <Timer.h>

#include <PrayerTimes.h>

//RTC>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//#include <DS3231.h>
#include <RTClib.h>
#include <Wire.h>
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

#include <EEPROM.h>
//#include <DFPlayer_Mini_Mp3.h> //Code serial & MP3 from : https://www.nyebarilmu.com/tutorial-mengakses-module-mp3-dfplayer-mini/?fbclid=IwAR0b0fNagVHdLAKPjjR_crMkXfdeIf9Y9McVnNZzBmFOVlnDO0IH_zVg2z4
#include "DFRobotDFPlayerMini.h"
#include <SoftwareSerial.h>
#define PIN_BUSY D5
#define RELAY D6

DFRobotDFPlayerMini ABLedDFPlayer;
void printDetail(uint8_t type, int value);

SoftwareSerial mp3Serial(D1, D2); // RX, TX
//SoftwareSerial mp3Serial(D3, D4); // RX, TX
ESP8266WebServer server;  //--> Server
WiFiUDP udp;
IPAddress DestinationIP(192,168,4,2); //--> If the Destination IP is 192,168,4,2 then you can use the Destination 192,168,4,2 or 192,168,4,255
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
unsigned int localPort = 2000;

Timer tMain;  //, tStandBy, tHold;

//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
//Parameter2 simpan di EEPROM / FlashMemory
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

String ssidSaved;   //= "ABLed_NodeMCU_ESP8266";
String passwordSaved; // = "goodluck";
//----------------------------------------------------


int ihti = 0; //2;
int durasiAdzan = 30000;  //3 * 60000;  //3 menit
// PrayerTimes
double times[sizeof(TimeName)/sizeof(char*)];
int idFileMur = 0;

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  int oPM;  // = EEPROM.read(98);  //Cek opsi putar murottal. 
            //0 = manual / bebas jam kapan saja, 1 = beberapa menit sebelum adzan

  String jamMenitDetikMurottalSatu;
  String jamMenitDetikMurottalDua;
  String jamMenitDetikMurottalTiga;
  String jamMenitDetikMurottalEmpat;  
  String jamMenitDetikMurottalDefault;
  int durasiMurottalSatu;
  int durasiMurottalDua;
  int durasiMurottalTiga;
  int durasiMurottalEmpat;
  int durasiMurottalDefaultOpsiBebas;
  
  int selisihMntMurottalShubuh;   //berapa menit sebelum adzan shubuh
  int selisihMntMurottalDhuhur; //berapa menit sebelum adzan dhuhur
  int selisihMntMurottalAshar;  ////berapa menit sebelum adzan ashar
  int selisihMntMurottalMaghrib;  ////berapa menit sebelum adzan maghrib
  int selisihMntMurottalEmpatWktDefault;
  int durasiMurottalShubuh;
  int durasiMurottalDhuhur;
  int durasiMurottalAshar;
  int durasiMurottalMaghrib;
  int durasiMurottalDefaultOpsiTdkBebas;

  int fileMurottalShubuhDanSatu;
  int fileMurottalDhuhurDanDua;
  int fileMurottalAsharDanTiga;
  int fileMurottalMaghribDanEmpat;
  int fileMurottalDefault;

  int flagPlayMP3 = 0;
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

int volumeSuara;
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

//RTCDS3231
//.............................................................................>>>>>>>>>>>>>>>>>>>>>>>>
//DS3231 Clock;
RTC_DS3231 rtc;

byte Year;
byte Month;
byte Date;
byte DoW;
byte Hour;
byte Minute;
byte Second;

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


//----------------------------------------Make a wifi name and password as access point-----------------------------------------------------------------------------------------------------//
//const char* ssid = &ssidSaved;
//const char* password = &passwordSaved;
const char* ssid; // = ssidSaved.c_str();
const char* password; // = passwordSaved.c_str();
//IPAddress ap_local_IP(192,168,3,1);
//IPAddress ap_gateway(192,168,3,254);
//IPAddress ap_subnet(255,255,255,0);
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

char packetBuffer[50];
String inString;
char replyBuffer[50];
String strCon;

void readSSIDnPWD();
void playMP3(int idMurottal);
void writeEEPROM(int addr, char _char);
void writeEEPROM(int addr, String str);
void tampilInfoRTC();
void receive_packet();


//-----------------------------------------------------------------------------------------------SETUP--------------------------------------------------------------------------------------//
void setup() {
  // put your setup code here, to run once:

  // Wire / RTC, Start the I2C interface
  Wire.begin(0, 2);   //Setting wire (D3 / GPIO0 untuk SDA, dan D4 / GPIO2 untuk SCL)
  //Wire.begin(5, 4);   //Setting wire (5 untuk SDA dan 4 untuk SCL)
 
  rtc.begin();
  //rtc.adjust(DateTime(F(__DATE__),F(__TIME__)));  //Setting Time
  // Kalian dapat menambahkan bagian dibawah ini untuk set manual jam
  //rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));

  //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  
  EEPROM.begin(512); //Initialasing EEPROM
  //delay(10);

  //Code serial & MP3 from : https://www.nyebarilmu.com/tutorial-mengakses-module-mp3-dfplayer-mini/?fbclid=IwAR0b0fNagVHdLAKPjjR_crMkXfdeIf9Y9McVnNZzBmFOVlnDO0IH_zVg2z4
  Serial.begin (115200);
  delay(100);

  tampilInfoRTC();
  delay(1000);

/*  
  Serial.println("");
  Serial.println("Setting up software serial");
  mp3Serial.begin (9600);
  delay(100);
  Serial.println("Setting up mp3 player");
  //delay(100);
  mp3_set_serial (mp3Serial);  
  delay(10);  //1000); // Delay is required before accessing player. From my experience it's ~1 sec
  mp3_set_volume (15);
*/

  mp3Serial.begin (9600);
  delay(1000);
  Serial.println();
  Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));

  if (!ABLedDFPlayer.begin(mp3Serial)) {  //Use softwareSerial to communicate with mp3.
    Serial.println(F("Unable to begin:"));
    Serial.println(F("1.Please recheck the connection!"));
    Serial.println(F("2.Please insert the SD card!"));
    while(true);
  }
  Serial.println(F("DFPlayer Mini online."));

  ABLedDFPlayer.volume(15);  //Set volume value. From 0 to 30
  //ABLedDFPlayer.play(1);  //Play the first mp3

  pinMode(PIN_BUSY, INPUT);
  pinMode(RELAY, OUTPUT);

  digitalWrite(RELAY, 1); //Matikan relay

  pinMode(LED_BUILTIN, OUTPUT); 
  for (int i=0; i>= 10; i++)
  {
    if (i%2 == 0)
    {
      digitalWrite(LED_BUILTIN, LOW); //--> Turn off Led On Board
      delay(1000);
    }
    else
    {
      digitalWrite(LED_BUILTIN, HIGH); //--> Turn off Led On Board
      delay(1000);
    }
    
    
  }
  //-----------------------------------------------------------------------------------------------SETUP--------------------------------------------------------------------------------------//
  //Serial.println("Reading EEPROM ssid & password");
  //readSSIDnPWD(); 
  
  Serial.println("Configuring access point...");
  //Serial.println("Setting soft-AP configuration ... ");
  //WiFi.softAPConfig(ap_local_IP, ap_gateway, ap_subnet);
  //Serial.println(ssidSaved.c_str());
  //Serial.println(passwordSaved.c_str());
  
  //if (EEPROM.read(97) == 0xFF or EEPROM.read(97) == 0)
  //{
    ssid = "AB LED Auto Tarhim"; //"ABLed_NodeMCU_ESP8266";
    password = "bismillah";  //"goodluck";
    Serial.print("SSID: ");
    Serial.println(ssid);
    Serial.println("Reading pass");
    Serial.print("PASS: ");
    Serial.println(password);
    Serial.println("Setting soft-AP ... ");
    WiFi.softAP(ssid, password);  //--> Start Making ESP8266 NodeMCU as an access point
    Serial.print("Connect your wifi laptop/mobile phone to this NodeMCU Access Point : ");
    Serial.println(ssid);
  //}
  //else if (EEPROM.read(97) == 4);
  //{
    //Serial.print("SSID From EEPROM: ");
    //Serial.println(ssidSaved);
    //Serial.println("Reading EEPROM pass");
    //Serial.print("PASSWORD FROM EEPROM: ");
    //Serial.println(passwordSaved);
    //Serial.println("Setting soft-AP ... ");
    //WiFi.softAP(ssidSaved.c_str(), passwordSaved.c_str());  //--> Start Making ESP8266 NodeMCU as an access point
    //Serial.print("Connect your wifi laptop/mobile phone to this NodeMCU Access Point : ");
    //Serial.println(ssidSaved);
  //}

  Serial.println("");

  IPAddress apip = WiFi.softAPIP(); //--> Get the IP server
  Serial.print("NodeMCU IP : ");
  Serial.println(apip); //--> Prints the NodeMCU IP address
  
  server.begin(); //--> Start server
  Serial.println("HTTP server started");
  //----------------------------------------
  udp.begin(localPort);
  Serial.print("Local Port : ");
  Serial.println(udp.localPort());
  Serial.println();
  Serial.println();

  tMain.every(6000, cekPlayMP3);
  //tMain.every(2000, alarmSholat);
  tMain.every(1000, tampilJadwalSholat);

  loadDataEEPROM();
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

//-----------------------------------------------------------------------------------------------LOOP---------------------------------------------------------------------------------------//
void loop() {
  // put your main code here, to run repeatedly:
  receive_packet();   //Flowchart 1
  //delay(10);

  //Arduino kirim ke B4A Android
  if (Serial.available() > 0) {
    char inChar = Serial.read();
    inString += inChar;
    if (inChar == '\n') {
      inString.toCharArray(replyBuffer, 50);
      udp.beginPacket(DestinationIP, localPort);  //2000);
      udp.write(replyBuffer);
      udp.endPacket();
      inString="";
    }
  }

  if (ABLedDFPlayer.available()) {
    printDetail(ABLedDFPlayer.readType(), ABLedDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
  }

  tMain.update();
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

//----------------------------------------------------------------------
// ALARM SHOLAT BERJALAN SAAT MASUK WAKTU SHOLAT
/*
void alarmSholat() {

  //RtcDateTime now = Rtc.GetDateTime();  
  DateTime now = rtc.now(); 

  int Hari = now.dayOfTheWeek();
  int Hor = now.hour();
  int Min = now.minute();
  int Sec = now.second();

  jadwalSholat();

  int hours, minutes, seconds;

  // Tanbih Imsak
  get_float_time_parts(times[0], hours, minutes);
  minutes = minutes + ihti;

  if (minutes < 10) { //jika wkt sholat shubuh, menitnya lbh kecil dari 10, maka set wkt tanbih imsak berkurang 10 utk menitnya dan berkurang 1 utk jamnya
    
    minutes = 60 - minutes;
    hours --;
    
  } else {
    
    minutes = minutes - 10 ;  // wkt sholat shubuh menitnya 10 atau lbh besar, maka menitnya lgsg dikurangkan 10 saja
    
  }

  if ((Hor - hours == 1) && (Min - minutes == 0)) {   //Jika jam saat ini dan menit saat ini sama dengan jam dan menit waktu tanbih, maka eksekusi kode berikut (bunyikan buzzer)

    Serial.println("Satu jam menuju tanbih imsyak");
    //BuzzerPendek();
    //Disp.clear();
    //Disp.setFont(ElektronMart6x8);
    //textCenter(0, "TANBIH");
    //textCenter(8, "IMSAK");
    //delay(durasiAdzan);
    //Disp.clear();

  }

  // Subuh
  get_float_time_parts(times[0], hours, minutes);
  minutes = minutes + ihti;

  if (minutes >= 60) {
    
    minutes = minutes - 60;
    hours ++;
    
  }

  if ((Hor - hours == 1) && (Min - minutes >= 0)) {

    Serial.println("Satu jam menuju adzan shubuh, auto tarhim On: ");
    ABLedDFPlayer.stop();
    delay(200);
    ABLedDFPlayer.play(idFileMur);
    delay(200);
  }
  else if ((Hor - hours == 0) && (Min - minutes >= 15)) {

    Serial.println("15 menit menuju adzan shubuh, auto tarhim Off: ");
    ABLedDFPlayer.stop();
    delay(200);
    
    idFileMur++;
    writeEEPROM(127, idFileMur);
    EEPROM.commit();
    //loadDataEEPROM();
    Serial.print("File murottal selanjutnya (dzuhur) adalah Juzz: ");
    Serial.println(idFileMur);
  }


  // Dzuhur
  get_float_time_parts(times[2], hours, minutes);
  minutes = minutes + ihti;

  if (minutes >= 60) {
    
    minutes = minutes - 60;
    hours ++;
    
  }

  if ((Hor - hours == 1) && (Min - minutes >= 0)) {

    Serial.println("Satu jam menuju adzan dzuhur, auto tarhim On: ");
    ABLedDFPlayer.stop();
    delay(200);
    ABLedDFPlayer.play(idFileMur);
    delay(200);
  }
  else if ((Hor - hours == 0) && (Min - minutes >= 15)) {

    Serial.println("15 menit menuju adzan dzhuhur, auto tarhim Off: ");
    ABLedDFPlayer.stop();
    delay(200);
    
    idFileMur++;
    writeEEPROM(127, idFileMur);
    EEPROM.commit();
    //loadDataEEPROM();
    Serial.print("File murottal selanjutnya (ashar) adalah Juzz: ");
    Serial.println(idFileMur);
  }


  // Ashar
  get_float_time_parts(times[3], hours, minutes);
  minutes = minutes + ihti;

  if (minutes >= 60) {
    
    minutes = minutes - 60;
    hours ++;
    
  }

  if ((Hor - hours == 1) && (Min - minutes >= 0)) {

    Serial.println("Satu jam menuju adzan ashar, auto tarhim On: ");
    ABLedDFPlayer.stop();
    delay(200);
    ABLedDFPlayer.play(idFileMur);
    delay(200);
  }
  else if ((Hor - hours == 0) && (Min - minutes >= 15)) {

    Serial.println("15 menit menuju adzan ashar, auto tarhim Off: ");
    ABLedDFPlayer.stop();
    delay(200);
    
    idFileMur++;
    writeEEPROM(127, idFileMur);
    EEPROM.commit();
    //loadDataEEPROM();
    Serial.print("File murottal selanjutnya (maghrib) adalah Juzz: ");
    Serial.println(idFileMur);
  }

  // Maghrib
  get_float_time_parts(times[5], hours, minutes);
  minutes = minutes + ihti;

  if (minutes >= 60) {
    
    minutes = minutes - 60;
    hours ++;
    
  }

  if ((Hor - hours == 1) && (Min - minutes >= 0)) {

    Serial.println("Satu jam menuju adzan maghrib, auto tarhim On: ");
    ABLedDFPlayer.stop();
    delay(200);
    ABLedDFPlayer.play(idFileMur);
    delay(200);
  }
  else if ((Hor - hours == 0) && (Min - minutes >= 15)) {

    Serial.println("15 menit menuju adzan maghrib, auto tarhim Off: ");
    ABLedDFPlayer.stop();
    delay(200);
    
    idFileMur++;
    writeEEPROM(127, idFileMur);
    EEPROM.commit();
    //loadDataEEPROM();
    Serial.print("File murottal selanjutnya (shubuh) adalah Juzz: ");
    Serial.println(idFileMur);
  }
}
*/
//----------------------------------------------------------------------

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

void tampilJadwalSholat() {

  jadwalSholat();

  static uint8_t i;
  static uint32_t pM;
  uint32_t cM = millis();
  
  char sholat[7];
  char jam[5];
  char TimeName[][9] = {"Subuh","Terbit","Dzuhur","Ashar","Terbenam","Maghrib","Isya'"};
  int hours, minutes;

  if (cM - pM >= 10) {
    
    pM = cM;

    if (i == 1) {i = 2;} // Abaikan Terbit
    if (i == 4) {i = 5;} // Abaikan Terbenam

    get_float_time_parts(times[i], hours, minutes);
  
    minutes = minutes + ihti;

    if (minutes >= 60) {
      minutes = minutes - 60;
      hours++;
    }

    String sholat = TimeName[i];
    sprintf(jam,"%02d:%02d", hours, minutes);     

    Serial.print("Sholat ");
    Serial.print(sholat);
    Serial.print(" : ");
    Serial.println(jam);
    
    i++;

    if (i > 6) {    //Waktu tanbih imsyak
      get_float_time_parts(times[0], hours, minutes);
      minutes = minutes + ihti;
      if (minutes < 11) {
        minutes = 60 - minutes;
        hours --;
      } else {
        minutes = minutes - 10 ;
      }
      sprintf(jam,"%02d:%02d", hours, minutes);
      
      Serial.print("Waktu Tanbih Imsyak : ");
      Serial.println(jam);

      i = 0;
      
      //if (i > 8) {    //jika i = 8, reset lagi i menjadi 0
        //i = 0;
        //Disp.drawRect(29,0,96,15,0,0);

        //tmpInfo = 0;
        //flagLoop = 1;
        //Disp.clear();
      //}      
    }  
  }
}

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//----------------------------------------------------------------------
//TAMPILKAN Jadwal Sholat

void jadwalSholat() {
  /*
    CALCULATION METHOD
    ------------------
    Jafari,   // Ithna Ashari
    Karachi,  // University of Islamic Sciences, Karachi
    ISNA,     // Islamic Society of North America (ISNA)
    MWL,      // Muslim World League (MWL)
    Makkah,   // Umm al-Qura, Makkah
    Egypt,    // Egyptian General Authority of Survey
    Custom,   // Custom Setting

    JURISTIC
    --------
    Shafii,    // Shafii (standard)
    Hanafi,    // Hanafi

    ADJUSTING METHOD
    ----------------
    None,        // No adjustment
    MidNight,   // middle of night
    OneSeventh, // 1/7th of night
    AngleBased, // angle/60th of night

    TIME IDS
    --------
    Fajr,
    Sunrise,
    Dhuhr,
    Asr,
    Sunset,
    Maghrib,
    Isha
  
  */

  //RtcDateTime now = Rtc.GetDateTime();
  DateTime now = rtc.now(); 
  
  int tahun = now.year();
  int bulan = now.month();
  int tanggal = now.day();
  float latitude = -0.00;   //-6.16;
  float longitude = 109.19; //106.61;
  int zonawaktu = 7;
  
  //set_calc_method(Karachi);
  set_calc_method(ISNA);
  set_asr_method(Shafii);
  set_high_lats_adjust_method(AngleBased);
  set_fajr_angle(20);
  set_isha_angle(18);  

  get_prayer_times(tahun, bulan, tanggal, latitude, longitude, zonawaktu, times);
}



//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void printDetail(uint8_t type, int value){
  switch (type) {
    case TimeOut:
      Serial.println(F("Time Out!"));
      break;
    case WrongStack:
      Serial.println(F("Stack Wrong!"));
      break;
    case DFPlayerCardInserted:
      Serial.println(F("Card Inserted!"));
      break;
    case DFPlayerCardRemoved:
      Serial.println(F("Card Removed!"));
      break;
    case DFPlayerCardOnline:
      Serial.println(F("Card Online!"));
      break;
    case DFPlayerPlayFinished:
      Serial.print(F("Number:"));
      Serial.print(value);
      Serial.println(F(" Play Finished!"));
      Serial.print("Pin BUSY = ");
      Serial.println(digitalRead(PIN_BUSY));
      break;
    case DFPlayerError:
      Serial.print(F("DFPlayerError:"));
      switch (value) {
        case Busy:
          Serial.println(F("Card not found"));
          break;
        case Sleeping:
          Serial.println(F("Sleeping"));
          break;
        case SerialWrongStack:
          Serial.println(F("Get Wrong Stack"));
          break;
        case CheckSumNotMatch:
          Serial.println(F("Check Sum Not Match"));
          break;
        case FileIndexOut:
          Serial.println(F("File Index Out of Bound"));
          break;
        case FileMismatch:
          Serial.println(F("Cannot Find File"));
          break;
        case Advertise:
          Serial.println(F("In Advertise"));
          break;
        default:
          break;
      }
      break;
    default:
      break;
  }
}
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//Load data EEPROM
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void loadDataEEPROM()
{
  Serial.println("Load data EEPROM...");
  
  oPM = EEPROM.read(98);  //Cek opsi putar murottal. 
                          //0 = manual / bebas jam kapan saja, 1 = beberapa menit sebelum adzan

  jamMenitDetikMurottalSatu = String(EEPROM.read(99) * 10000 + EEPROM.read(100) * 100 + EEPROM.read(101));
  jamMenitDetikMurottalDua = String(EEPROM.read(102) * 10000 + EEPROM.read(103) * 100 + EEPROM.read(104));
  jamMenitDetikMurottalTiga = String(EEPROM.read(105) * 10000 + EEPROM.read(106) * 100 + EEPROM.read(107));
  jamMenitDetikMurottalEmpat = String(EEPROM.read(108) * 10000 + EEPROM.read(109) * 100 + EEPROM.read(110));
  jamMenitDetikMurottalDefault = "000000";
  durasiMurottalSatu = EEPROM.read(111);
  durasiMurottalDua = EEPROM.read(112);
  durasiMurottalTiga = EEPROM.read(113);
  durasiMurottalEmpat = EEPROM.read(114);
  durasiMurottalDefaultOpsiBebas = 0;   //durasi 0 menit
  
  selisihMntMurottalShubuh = EEPROM.read(115);   //berapa menit sebelum adzan shubuh
  selisihMntMurottalDhuhur = EEPROM.read(116); //berapa menit sebelum adzan dhuhur
  selisihMntMurottalAshar = EEPROM.read(117);  ////berapa menit sebelum adzan ashar
  selisihMntMurottalMaghrib = EEPROM.read(118);  ////berapa menit sebelum adzan maghrib
  selisihMntMurottalEmpatWktDefault = 60; //60 menit sebelum adzan
  durasiMurottalShubuh = EEPROM.read(119);
  durasiMurottalDhuhur = EEPROM.read(120);
  durasiMurottalAshar = EEPROM.read(121);
  durasiMurottalMaghrib = EEPROM.read(122);
  durasiMurottalDefaultOpsiTdkBebas = 0; //durasi putar MP3 adalah 45 menit

  fileMurottalShubuhDanSatu = EEPROM.read(123);
  fileMurottalDhuhurDanDua = EEPROM.read(124);
  fileMurottalAsharDanTiga = EEPROM.read(125);
  fileMurottalMaghribDanEmpat = EEPROM.read(126);
  fileMurottalDefault = 1;

  idFileMur = EEPROM.read(127);
  
  Serial.println("Data EEPROM berhasil di load...");
  Serial.println();
}

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
String hitungJamStop(int jamMulai, int mntMulai, int durasi, int jamStop, int mntStop)
{
  //Serial.println("Menghitung jam stop dan menit stop.");
  String jamStopStr;
  String mntStopStr;
  
        if (durasi >= 60)
        {
          jamStop = jamMulai + (durasi / 60);
          mntStop = mntMulai + (durasi % 60);

          if (mntStop >= 60)
          {
            jamStop += mntStop / 60;
            mntStop = mntStop % 60;
          }
        }
        else
        {
          if (durasi + mntMulai >= 60)
          {
            jamStop = jamMulai + ((durasi + mntMulai) / 60);
            mntStop = (durasi + mntMulai) % 60;
          }
          else
          {
            jamStop = jamMulai;
            mntStop = mntMulai + durasi;
          }
        }

        if (jamStop < 10)
        {
            jamStopStr = "0" + String(jamStop);
        }
        else
        {
            jamStopStr = String(jamStop);
        }

        if (mntStop < 10)
        {
            mntStopStr = "0" + String(mntStop);
        }
        else
        {
            mntStopStr = String(mntStop);
        }

        //Serial.print("Jam stop dan menit stop: ");
        //Serial.println(jamStopStr + mntStopStr);
        
        return jamStopStr + mntStopStr;
}


//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//
void cekPlayMP3()
{ 
  Serial.println();
  tampilInfoRTC();
 
  DateTime now = rtc.now(); 

  if (now.hour() == 22 and now.minute() == 0)
  {
     Serial.println("Jam sekarang memasuki pukul 22.00 WIB, saatnya NodeMCU memasuki mode DEEP SLEEP selama 5 jam atau 18.000 detik atau 18.000.000.000 uS atau 18000e6 atau 18e9.");
     delay(60000);
     ESP.deepSleep(18e9);   //Deep sleep selama 5 jam atau 18.000 detik
     //ESP.deepSleep(0.06e9); //60 detik, for testing
  }

  if (now.hour() == 7 and now.minute() == 0)
  {
     Serial.println("Jam sekarang memasuki pukul 07.00 WIB, saatnya NodeMCU memasuki mode DEEP SLEEP selama 3 jam atau 10.800 detik atau 10.800.000.000 uS atau 10800e6.");
     delay(60000);
     ESP.deepSleep(10800e6);  //Deep sleep selama 3 jam atau 10.800 detik
     //ESP.deepSleep(60000e3);  //60 detik juga, sama dengan 60e6
  }
    
  if (oPM == 0) //Murottal waktu bebas
  {
    Serial.println("");
    Serial.println("Murottal Mode Waktu Bebas.");

    int durasiMS = durasiMurottalSatu;
  int durasiMD = durasiMurottalDua;
  int durasiMT = durasiMurottalTiga;
  int durasiME = durasiMurottalEmpat;

  Serial.println(String(now.hour()) + ":" + String(now.minute()) + ":" + String(now.second()));
  Serial.print("Durasi Murottal Satu: ");
  Serial.println(durasiMS);
  Serial.print("Durasi Murottal Dua: ");
  Serial.println(durasiMD);
  Serial.print("Durasi Murottal Tiga: ");
  Serial.println(durasiMT);
  Serial.print("Durasi Murottal Empat: ");
  Serial.println(durasiME);
  Serial.println("");

  Serial.print("File murottal shubuh & satu: ");
  Serial.println(fileMurottalShubuhDanSatu);
  Serial.print("File murottal dhuhur & dua: ");
  Serial.println(fileMurottalDhuhurDanDua);
  Serial.print("File murottal ashar & tiga: ");
  Serial.println(fileMurottalAsharDanTiga);
  Serial.print("File murottal maghrib & empat: ");
  Serial.println(fileMurottalMaghribDanEmpat);
  Serial.println("");
      
    int jam1 = jamMenitDetikMurottalSatu.toInt() / 10000;
    int mnt1 = (jamMenitDetikMurottalSatu.toInt() % 10000) / 100;
    int jam2 = jamMenitDetikMurottalDua.toInt() / 10000;
    int mnt2 = (jamMenitDetikMurottalDua.toInt() % 10000) / 100;
    int jam3 = jamMenitDetikMurottalTiga.toInt() / 10000;
    int mnt3 = (jamMenitDetikMurottalTiga.toInt() % 10000) / 100;
    int jam4 = jamMenitDetikMurottalEmpat.toInt() / 10000;
    int mnt4 = (jamMenitDetikMurottalEmpat.toInt() % 10000) / 100;

    int jamStop1 = ((hitungJamStop(jam1, mnt1, durasiMS, 0, 0)).toInt()) / 100;
    int mntStop1 = ((hitungJamStop(jam1, mnt1, durasiMS, 0, 0)).toInt()) % 100;
    int jamStop2 = ((hitungJamStop(jam2, mnt2, durasiMD, 0, 0)).toInt()) / 100;
    int mntStop2 = ((hitungJamStop(jam2, mnt2, durasiMD, 0, 0)).toInt()) % 100;
    int jamStop3 = ((hitungJamStop(jam3, mnt3, durasiMT, 0, 0)).toInt()) / 100;
    int mntStop3 = ((hitungJamStop(jam3, mnt3, durasiMT, 0, 0)).toInt()) % 100;
    int jamStop4 = ((hitungJamStop(jam4, mnt4, durasiME, 0, 0)).toInt()) / 100;
    int mntStop4 = ((hitungJamStop(jam4, mnt4, durasiME, 0, 0)).toInt()) % 100;
    
    
    Serial.print("Jam Putar 1: ");
    Serial.print(jam1);
    Serial.print(":");
    Serial.println(mnt1);
    Serial.print("Jam Stop 1: ");
    Serial.print(jamStop1);
    Serial.print(":");
    Serial.println(mntStop1);
    
    Serial.print("Jam Putar 2: ");
    Serial.print(jam2);
    Serial.print(":");
    Serial.println(mnt2);
    Serial.print("Jam Stop 2: ");
    Serial.print(jamStop2);
    Serial.print(":");
    Serial.println(mntStop2);
    
    Serial.print("Jam Putar 3: ");
    Serial.print(jam3);
    Serial.print(":");
    Serial.println(mnt3);
    Serial.print("Jam Stop 3: ");
    Serial.print(jamStop3);
    Serial.print(":");
    Serial.println(mntStop3);
    
    Serial.print("Jam Putar 4: ");
    Serial.print(jam4);
    Serial.print(":");
    Serial.println(mnt4);
    Serial.print("Jam Stop 4: ");
    Serial.print(jamStop4);
    Serial.print(":");
    Serial.println(mntStop4);

    if (digitalRead(PIN_BUSY) == 0)  //DF Player is playing music
    { 
        Serial.println("Pin Busy = 0");
        
        if (now.hour() == jamStop1 && now.minute() >= mntStop1) //jika jam dan mnt skrg sama dengan jamStop dan mntStop
        {
          Serial.println("Murottal stopped.");
          ABLedDFPlayer.stop();
          flagPlayMP3 = 0;
        }

        if (now.hour() == jamStop2 && now.minute() >= mntStop2) //jika jam dan mnt skrg sama dengan jamStop dan mntStop
        {
          Serial.println("Murottal stopped.");
          ABLedDFPlayer.stop();
          flagPlayMP3 = 0;
        }

        if (now.hour() == jamStop3 && now.minute() >= mntStop3) //jika jam dan mnt skrg sama dengan jamStop dan mntStop
        {
          Serial.println("Murottal stopped.");
          ABLedDFPlayer.stop();
          flagPlayMP3 = 0;
        }

        if (now.hour() == jamStop4 && now.minute() >= mntStop4) //jika jam dan mnt skrg sama dengan jamStop dan mntStop
        {
          Serial.println("Murottal stopped.");
          ABLedDFPlayer.stop();
          flagPlayMP3 = 0;
        }
    }

    if (digitalRead(PIN_BUSY) == 1)  //MP3 player idle
    {
      Serial.println("");
      Serial.println("Pin Busy = 1");
      
      if ((now.hour() == jam1 && now.minute() >= mnt1))
      {
        Serial.println("Jam dan Menit sekarang masuk jam putar murottal 1.");
        if (now.hour() < jamStop1 or (now.hour() == jamStop1 and now.minute() < mntStop1))
        {
          Serial.println("Jam dan Menit sekarang < jam stop.");

            if (flagPlayMP3 == 1)
            {
              Serial.println("flagPlayMP3 = 1");
              ABLedDFPlayer.next();
            }
            
            if (flagPlayMP3 == 0)
            {
              Serial.println("flagPlayMP3 = 0");
              Serial.print("Play murottal file: ");
              Serial.println(fileMurottalShubuhDanSatu);
              //mp3_play(fileMurottalShubuhDanSatu); //memainkan lagu pada folder mp3 yang sudah direname dengan nama 0001.mp3, file name 0000.mp3 - 9999.mp3
              ABLedDFPlayer.play(fileMurottalShubuhDanSatu);  

              flagPlayMP3 = 1;
            }
        }
      } 
      else if ((now.hour() == jam2 && now.minute() >= mnt2))
      {
        Serial.println("Jam dan Menit sekarang masuk jam putar murottal 2.");
        if (now.hour() < jamStop2 or (now.hour() == jamStop2 and now.minute() < mntStop2))
        {
          Serial.println("Jam dan Menit sekarang < jam stop.");
        
          //if (digitalRead(PIN_BUSY) == 1)  //DF Player idle
          //{
            //Serial.println("Pin Busy = 1");

            if (flagPlayMP3 == 1)
            {
              Serial.println("flagPlayMP3 = 1");
              ABLedDFPlayer.next();
            }
            
            if (flagPlayMP3 == 0)
            {
              Serial.println("flagPlayMP3 = 0");
              Serial.print("Play murottal file: ");
              Serial.println(fileMurottalDhuhurDanDua);
              ABLedDFPlayer.play(fileMurottalDhuhurDanDua);  

              flagPlayMP3 = 1;
            }
          //}
        }
      }
    else if ((now.hour() == jam3 && now.minute() >= mnt3))
    {
        Serial.println("Jam dan Menit sekarang masuk jam putar murottal 3.");
        if (now.hour() < jamStop3 or (now.hour() == jamStop3 and now.minute() < mntStop3))
        {
          Serial.println("Jam dan Menit sekarang < jam stop.");
        
          //if (digitalRead(PIN_BUSY) == 1)  //DF Player idle
          //{
            //Serial.println("Pin Busy = 1");

            if (flagPlayMP3 == 1)
            {
              Serial.println("flagPlayMP3 = 1");
              ABLedDFPlayer.next();
            }
            
            if (flagPlayMP3 == 0)
            {
              Serial.println("flagPlayMP3 = 0");
              Serial.print("Play murottal file: ");
              Serial.println(fileMurottalAsharDanTiga);
              ABLedDFPlayer.play(fileMurottalAsharDanTiga);  

              flagPlayMP3 = 1;
            }
          //}
        }
      }
      else if ((now.hour() == jam4 && now.minute() >= mnt4))
      {
        Serial.println("Jam dan Menit sekarang masuk jam putar murottal 4.");
        if (now.hour() < jamStop4 or (now.hour() == jamStop4 and now.minute() < mntStop4))
        {
          Serial.println("Jam dan Menit sekarang < jam stop.");
        
          //if (digitalRead(PIN_BUSY) == 1)  //DF Player idle
          //{
            //Serial.println("Pin Busy = 1");

            if (flagPlayMP3 == 1)
            {
              Serial.println("flagPlayMP3 = 1");
              ABLedDFPlayer.next();
            }
            
            if (flagPlayMP3 == 0)
            {
              Serial.println("flagPlayMP3 = 0");
              Serial.print("Play murottal file: ");
              Serial.println(fileMurottalMaghribDanEmpat);
              ABLedDFPlayer.play(fileMurottalMaghribDanEmpat);  

              flagPlayMP3 = 1;
            }
          //}
        }
      } 
    }
  }
  else  //Mode putar murottal beberapa menit sebelum adzan
  {
    Serial.println("");
    Serial.println("Murottal Mode 2, Satu Jam Sebelum adzan.");
    //RtcDateTime now = Rtc.GetDateTime();  
     //DateTime now = rtc.now(); 

    int Hari = now.dayOfTheWeek();
    int Hor = now.hour();
    int Min = now.minute();
    int Sec = now.second();

    jadwalSholat();

    int hours, minutes, seconds;

    // Tanbih Imsak
    get_float_time_parts(times[0], hours, minutes);
    minutes = minutes + ihti;

    if (minutes < 10) { //jika wkt sholat shubuh, menitnya lbh kecil dari 10, maka set wkt tanbih imsak berkurang 10 utk menitnya dan berkurang 1 utk jamnya
    
      minutes = 60 - minutes;
      hours --;
    
    } else {
    
      minutes = minutes - 10 ;  // wkt sholat shubuh menitnya 10 atau lbh besar, maka menitnya lgsg dikurangkan 10 saja
    
    }

    if ((hours - Hor == 1) && (Min - minutes == 0)) {   //Jika jam saat ini dan menit saat ini sama dengan jam dan menit waktu tanbih, maka eksekusi kode berikut (bunyikan buzzer)

      Serial.println("Satu jam menuju tanbih imsyak");
      //BuzzerPendek();
      //Disp.clear();
      //Disp.setFont(ElektronMart6x8);
      //textCenter(0, "TANBIH");
      //textCenter(8, "IMSAK");
      //delay(durasiAdzan);
      //Disp.clear();

    }

    // Subuh
    get_float_time_parts(times[0], hours, minutes);
    minutes = minutes + ihti;

    if (minutes >= 60) {
    
      minutes = minutes - 60;
      hours ++;
    
    }

    if ((hours - Hor == 1) && (Min - minutes == 0)) {

      Serial.println("Satu jam menuju adzan shubuh, auto tarhim On: ");
      if (digitalRead(PIN_BUSY) == 1)   //kalau mp3 player idle
      {
        digitalWrite(RELAY, 0);
        delay(30000);
        ABLedDFPlayer.stop();
        delay(200);
        ABLedDFPlayer.play(idFileMur);
        delay(200);
      }
    }
    else if ((hours - Hor == 0) && (minutes - Min == 15)) {

      Serial.println("15 menit menuju adzan shubuh, auto tarhim Off: ");
      ABLedDFPlayer.stop();
      delay(200);
      
      idFileMur++;
      writeEEPROM(127, idFileMur);
      EEPROM.commit();
      //loadDataEEPROM();
      Serial.print("File murottal selanjutnya (dzuhur) adalah Juzz: ");
      Serial.println(idFileMur);
      Serial.println("Delay 60 detik");
      delay(60000);
    }
    else if ((Hor - hours == 1) && (Min - minutes == 0)) {

      Serial.println("10 detik menuju Relay OFF.");
      delay(10000);
      digitalWrite(RELAY, 1);
      Serial.println("Relay OFF");
      Serial.println("Delay 60 detik");
      delay(60000);
    }


    // Dzuhur
    get_float_time_parts(times[2], hours, minutes);
    minutes = minutes + ihti;

    if (minutes >= 60) {
    
      minutes = minutes - 60;
      hours ++;
    
    }

    if ((hours - Hor == 1) && (Min - minutes == 0)) {

      Serial.println("Satu jam menuju adzan dzuhur, auto tarhim On: ");
      if (digitalRead(PIN_BUSY) == 1)   //kalau mp3 player idle
      {
        digitalWrite(RELAY, 0);
        delay(30000);
        ABLedDFPlayer.stop();
        delay(200);
        ABLedDFPlayer.play(idFileMur);
        delay(200);
      }
    }
    else if ((hours - Hor == 0) && (minutes - Min == 15)) {

      Serial.println("15 menit menuju adzan dzhuhur, auto tarhim Off: ");
      ABLedDFPlayer.stop();
      delay(200);
    
      idFileMur++;
      writeEEPROM(127, idFileMur);
      EEPROM.commit();
      //loadDataEEPROM();
      Serial.print("File murottal selanjutnya (ashar) adalah Juzz: ");
      Serial.println(idFileMur);
      Serial.println("Delay 60 detik");
      delay(60000);
    }
    else if ((Hor - hours == 1) && (Min - minutes == 0)) {

      Serial.println("10 detik menuju Relay OFF.");
      delay(10000);
      digitalWrite(RELAY, 1);
      Serial.println("Relay OFF");
      Serial.println("Delay 60 detik");
      delay(60000);
    }


    // Ashar
    get_float_time_parts(times[3], hours, minutes);
    minutes = minutes + ihti;

    if (minutes >= 60) {
    
      minutes = minutes - 60;
      hours ++;
    
    }

    if ((hours - Hor == 1) && (Min - minutes == 0)) {

      Serial.println("Satu jam menuju adzan ashar, auto tarhim On: ");
      if (digitalRead(PIN_BUSY) == 1)   //kalau mp3 player idle
      {
        digitalWrite(RELAY, 0);
        delay(30000);
        ABLedDFPlayer.stop();
        delay(200);
        ABLedDFPlayer.play(idFileMur);
        delay(200);
      }
    }
    else if ((hours - Hor == 0) && (minutes - Min == 15)) {

      Serial.println("15 menit menuju adzan ashar, auto tarhim Off: ");
      ABLedDFPlayer.stop();
      delay(200);
    
      idFileMur++;
      writeEEPROM(127, idFileMur);
      EEPROM.commit();
      //loadDataEEPROM();
      Serial.print("File murottal selanjutnya (maghrib) adalah Juzz: ");
      Serial.println(idFileMur);
      Serial.println("Delay 60 detik");
      delay(60000);
    }
    else if ((Hor - hours == 1) && (Min - minutes == 0)) {

      Serial.println("10 detik menuju Relay OFF.");
      delay(10000);
      digitalWrite(RELAY, 1);
      Serial.println("Relay OFF");
      Serial.println("Delay 60 detik");
      delay(60000);
    }

    // Maghrib
    get_float_time_parts(times[5], hours, minutes);
    minutes = minutes + ihti;

    if (minutes >= 60) {
    
      minutes = minutes - 60;
      hours ++;
    
    }

    if ((hours - Hor == 1) && (Min - minutes == 0)) {

      Serial.println("Satu jam menuju adzan maghrib, auto tarhim On: ");
      if (digitalRead(PIN_BUSY) == 1)   //kalau mp3 player idle
      {
        digitalWrite(RELAY, 0);
        delay(30000);
        ABLedDFPlayer.stop();
        delay(200);
        ABLedDFPlayer.play(idFileMur);
        delay(200);
      }
    }
    else if ((hours - Hor == 0) && (minutes - Min == 15)) {

      Serial.println("15 menit menuju adzan maghrib, auto tarhim Off: ");
      ABLedDFPlayer.stop();
      delay(200);
    
      idFileMur++;
      writeEEPROM(127, idFileMur);
      EEPROM.commit();
      //loadDataEEPROM();
      Serial.print("File murottal selanjutnya (shubuh) adalah Juzz: ");
      Serial.println(idFileMur);
      Serial.println("Delay 60 detik");
      delay(60000);
    }
    else if ((Hor - hours == 1) && (Min - minutes == 0)) {

      Serial.println("10 detik menuju Relay OFF.");
      delay(10000);
      digitalWrite(RELAY, 1);
      Serial.println("Relay OFF");
      Serial.println("Delay 60 detik");
      delay(60000);
    }
  }
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//


//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//


void tampilInfoRTC()
{
  DateTime now = rtc.now();       //Menampilkan RTC pada variable now

  Serial.print("Hari: ");
  Serial.println(now.dayOfTheWeek());
  Serial.print("Tanggal : ");
  Serial.print(now.day());        //Menampilkan Tanggal
  Serial.print("/");
  Serial.print(now.month());      //Menampilkan Bulan
  Serial.print("/");
  Serial.print(now.year());       //Menampilkan Tahun
  Serial.print(" ");
  
  Serial.print("Jam : ");
  Serial.print(now.hour());       //Menampilkan Jam
  Serial.print(":");
  Serial.print(now.minute());     //Menampilkan Menit
  Serial.print(":");
  Serial.print(now.second());     //Menampilkan Detik
  Serial.println();
 
  //delay(1000);
}

//----------------------------------------Procedure for receiving text / messages from the sender-------------------------------------------------------------------------------------------//
void receive_packet() {
  int packetSize = udp.parsePacket();
  if (packetSize) {
    IPAddress remoteIp = udp.remoteIP();
    //DestinationIP = udp.remoteIP();
    int len = udp.read(packetBuffer, 255);
    if (len > 0) packetBuffer[len] = 0;
    strCon = packetBuffer;
    Serial.println(packetBuffer);

    //-------------------------------Conditions for controlling LEDs
    if (strCon=="led on") {
      digitalWrite(LED_BUILTIN, LOW);
    }
    else if (strCon=="led off") {
      digitalWrite(LED_BUILTIN, HIGH);
    }
    else if (strCon=="nama ssid") {
      while(true)
      {
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
          //Serial.println(packetBuffer);

          if (strCon=="default")
          {
            writeEEPROM(97, 0);
            EEPROM.commit();
            Serial.println("EEPROM 97 jadi 0");
          }
          else
          {
            writeEEPROM(97, 4);
            writeEEPROM(0, strCon);
            
            //EEPROM.commit();
            Serial.println("EEPROM 97 jadi 4");
          }
          
          break;
        }
      }
    }
    else if (strCon=="password wifi") {
      while(true)
      {
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
          //Serial.println(packetBuffer);

          writeEEPROM(32, strCon);

          break;
        }
      }
    }
    else if (strCon=="set time") {
      Serial.println("Setting jam kontroler.");
      
      DateTime now = rtc.now(); 
      long val;
      int jam;
      int mnt;
      int dtk;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;

          val = strCon.toInt();
          Serial.println(val);
          
          if (val > -1)
          {
            jam = val / 10000;
            mnt = (val % 10000) / 100;
            dtk = (val % 10000) % 100;

            //rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
            rtc.adjust(DateTime(now.year(), now.month(), now.day(), jam, mnt, dtk));
          }
          
          break;
        }
      }
    }
    else if (strCon=="set date") {
      Serial.println("Setting tanggal kontroler.");

      DateTime now = rtc.now(); 
      long val;
      int thn;
      int bln;
      int tgl;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;

          val = strCon.toInt();
          Serial.println(val);
          
          if (val > -1)
          {
            thn = val / 10000;
            bln = (val % 10000) / 100;
            tgl = (val % 10000) % 100;

            //rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
            rtc.adjust(DateTime(thn, bln, tgl, now.hour(), now.minute(), now.second()));
          }
          
          break;
        }
      }
    }
    else if (strCon=="tampil waktu") {
      while(true)
      {
        static uint32_t pM;
        uint32_t cM = millis();

        if (cM - pM >= 1000)
        {
          pM = cM;
          tampilInfoRTC(); 
        }
  
        if (udp.parsePacket()) 
        {
            remoteIp = udp.remoteIP();
            len = udp.read(packetBuffer, 255);
            if (len > 0) packetBuffer[len] = 0;
            strCon = packetBuffer;

            if (strCon == "kembali")
            {
              break;
            }
         }
         delay(100);
       } 
    }
    else if (strCon=="opsi putar murottal") {
      Serial.println("Opsi putar murottal, 0 waktu bebas, 1 beberapa menit sebelum adzan.");
      Serial.print("Nilai EEPROM 98 saat ini: ");
      Serial.println(EEPROM.read(98));
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
          
          if (strCon == "0")    //Waktu bebas
          {
            writeEEPROM(98, 0);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();
            
            break;
          }
          else if (strCon == "1")   //beberapa menit sebelum adzan
          {
            writeEEPROM(98, 1);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();
            
            break;
          }
          else if (strCon != "0" or strCon != "1")
          {
            Serial.println("Masukkan angka 0 atau 1");
          }
        }
      }
    }
    else if (strCon=="opsi 1 jam putar murottal satu") {
      Serial.println("Opsi 1 (bebas) jam putar murottal satu.");
      Serial.println("Masukkan Jam dan Menit murottal akan diputar.");
      Serial.println("Alamat EEPROM digunakan 99-101.");

      long val;
      int jam;
      int mnt;
      int dtk;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          val = strCon.toInt();
          Serial.println(val);
          
          if (val > -1)
          {
            jam = val / 10000;
            mnt = (val % 10000) / 100;
            dtk = (val % 10000) % 100;

            writeEEPROM(99, jam);
            writeEEPROM(100, mnt);
            writeEEPROM(101, dtk);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();

            Serial.print("Jam putar murottal satu sudah diset. Waktu putar: ");
            Serial.print(EEPROM.read(99));
            Serial.print(EEPROM.read(100));
            Serial.println(EEPROM.read(101));
            
            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, cth: untuk tanggal 20210129, untuk jam 214859");
          }
        }
      }
    }
    else if (strCon=="opsi 1 jam putar murottal dua") {
      Serial.println("Opsi 1 (bebas) jam putar murottal dua.");
      Serial.println("Masukkan Jam dan Menit murottal akan diputar.");
      Serial.println("Alamat EEPROM digunakan 102-104.");

      long val;
      int jam;
      int mnt;
      int dtk;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          val = strCon.toInt();
          Serial.println(val);
          
          if (val > -1)
          {
            Serial.println(val);
            
            jam = val / 10000;
            mnt = (val % 10000) / 100;
            dtk = (val % 10000) % 100;

            Serial.println("Write to EEWPROM");
            
            writeEEPROM(102, jam);
            writeEEPROM(103, mnt);
            writeEEPROM(104, dtk);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();
            
            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, cth: untuk tanggal 20210129, untuk jam 214859");
          }
        }
      }
    }
    else if (strCon=="opsi 1 jam putar murottal tiga") {
      Serial.println("Opsi 1 (bebas) jam putar murottal tiga.");
      Serial.println("Masukkan Jam dan Menit murottal akan diputar.");
      Serial.println("Alamat EEPROM digunakan 105-107.");

      long val;
      int jam;
      int mnt;
      int dtk;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          val = strCon.toInt();
          Serial.println(val);
          
          if (val > -1)
          {
            jam = val / 10000;
            mnt = (val % 10000) / 100;
            dtk = (val % 10000) % 100;

            writeEEPROM(105, jam);
            writeEEPROM(106, mnt);
            writeEEPROM(107, dtk);
            EEPROM.commit();
            
            Serial.println("EEPROM Committed");
            loadDataEEPROM();
            
            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, cth: untuk tanggal 20210129, untuk jam 214859");
          }
        }
      }
    }
    else if (strCon=="opsi 1 jam putar murottal empat") {
      Serial.println("Opsi 1 (bebas) jam putar murottal empat.");
      Serial.println("Masukkan Jam dan Menit murottal akan diputar.");
      Serial.println("Alamat EEPROM digunakan 108-110.");

      long val;
      int jam;
      int mnt;
      int dtk;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          val = strCon.toInt();
          Serial.println(val);
          
          if (val > -1)
          {
            jam = val / 10000;
            mnt = (val % 10000) / 100;
            dtk = (val % 10000) % 100;

            writeEEPROM(108, jam);
            writeEEPROM(109, mnt);
            writeEEPROM(110, dtk);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();

            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, cth: untuk tanggal 20210129, untuk jam 214859");
          }
        }
      }
    }
    else if (strCon=="opsi 1 durasi putar murottal satu") {
      Serial.println("Opsi 1 durasi putar murottal satu.");
      Serial.println("Masukkan Menit berapa lama murottal akan diputar.");
      Serial.println("Alamat EEPROM digunakan 111.");

      int durasi;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          durasi = strCon.toInt();
          Serial.println(durasi);
          
          if (durasi > 0 && durasi < 256)
          {
            writeEEPROM(111, durasi);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();
            
            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, cth: 60 untuk durasi 60 menit, maximum durasi 255 menit");
          }
        }
      }
    }
    else if (strCon=="opsi 1 durasi putar murottal dua") {
      Serial.println("Opsi 1 durasi putar murottal dua.");
      Serial.println("Masukkan Menit berapa lama murottal akan diputar.");
      Serial.println("Alamat EEPROM digunakan 112.");

      int durasi;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          durasi = strCon.toInt();
          Serial.println(durasi);
          
          if (durasi > 0 && durasi < 256)
          {
            writeEEPROM(112, durasi);
            EEPROM.commit();
            
            Serial.println("EEPROM Committed");
            loadDataEEPROM();

            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, cth: 60 untuk durasi 60 menit, maximum durasi 255 menit");
          }
        }
      }
    }
    else if (strCon=="opsi 1 durasi putar murottal tiga") {
      Serial.println("Opsi 1 durasi putar murottal tiga.");
      Serial.println("Masukkan Menit berapa lama murottal akan diputar.");
      Serial.println("Alamat EEPROM digunakan 113.");

      int durasi;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          durasi = strCon.toInt();
          Serial.println(durasi);
          
          if (durasi > 0 && durasi < 256)
          {
            writeEEPROM(113, durasi);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();
            
            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, cth: 60 untuk durasi 60 menit, maximum durasi 255 menit");
          }
        }
      }
    }
    else if (strCon=="opsi 1 durasi putar murottal empat") {
      Serial.println("Opsi 1 durasi putar murottal empat.");
      Serial.println("Masukkan Menit berapa lama murottal akan diputar.");
      Serial.println("Alamat EEPROM digunakan 114.");

      int durasi;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          durasi = strCon.toInt();
          Serial.println(durasi);
          
          if (durasi > 0 && durasi < 256)
          {
            writeEEPROM(114, durasi);
            EEPROM.commit();
            
            Serial.println("EEPROM Committed");
            loadDataEEPROM();

            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, cth: 60 untuk durasi 60 menit, maximum durasi 255 menit");
          }
        }
      }
    }
    else if (strCon=="opsi 2 jam putar murottal shubuh") {
      Serial.println("opsi 2 jam putar murottal shubuh");
      Serial.println("Masukkan Menit berapa lama sebelum adzan murottal akan diputar.");
      Serial.println("Alamat EEPROM digunakan 115.");

      int durasi;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          durasi = strCon.toInt();
          Serial.println(durasi);
          
          if (durasi > 0 && durasi < 256)
          {
            writeEEPROM(115, durasi);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();
            
            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, cth: 60 untuk durasi 60 menit, maximum durasi 255 menit");
          }
        }
      }
    }
    else if (strCon=="opsi 2 jam putar murottal dhuhur") {
      Serial.println("opsi 2 jam putar murottal dhuhur");
      Serial.println("Masukkan Menit berapa lama sebelum adzan murottal akan diputar.");
      Serial.println("Alamat EEPROM digunakan 116.");

      int durasi;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          durasi = strCon.toInt();
          Serial.println(durasi);
          
          if (durasi > 0 && durasi < 256)
          {
            writeEEPROM(116, durasi);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();
            
            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, cth: 60 untuk durasi 60 menit, maximum durasi 255 menit");
          }
        }
      }
    }
    else if (strCon=="opsi 2 jam putar murottal ashar") {
      Serial.println("opsi 2 jam putar murottal ashar");
      Serial.println("Masukkan Menit berapa lama sebelum adzan murottal akan diputar.");
      Serial.println("Alamat EEPROM digunakan 117.");

      int durasi;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          durasi = strCon.toInt();
          Serial.println(durasi);
          
          if (durasi > 0 && durasi < 256)
          {
            writeEEPROM(117, durasi);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();
            
            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, cth: 60 untuk durasi 60 menit, maximum durasi 255 menit");
          }
        }
      }
    }
    else if (strCon=="opsi 2 jam putar murottal maghrib") {
      Serial.println("opsi 2 jam putar murottal ashar");
      Serial.println("Masukkan Menit berapa lama sebelum adzan murottal akan diputar.");
      Serial.println("Alamat EEPROM digunakan 118.");

      int durasi;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          durasi = strCon.toInt();
          Serial.println(durasi);
          
          if (durasi > 0 && durasi < 256)
          {
            writeEEPROM(118, durasi);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();
            
            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, cth: 60 untuk durasi 60 menit, maximum durasi 255 menit");
          }
        }
      }
    }
    else if (strCon=="opsi 2 durasi putar murottal shubuh") {
      Serial.println("opsi 2 durasi putar murottal shubuh.");
      Serial.println("Masukkan Menit lama durasi murottal akan diputar.");
      Serial.println("Alamat EEPROM digunakan 119.");

      int durasi;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          durasi = strCon.toInt();
          Serial.println(durasi);
          
          if (durasi > 0 && durasi < 256)
          {
            writeEEPROM(119, durasi);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();
            
            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, cth: 60 untuk durasi 60 menit, maximum durasi 255 menit");
          }
        }
      }
    }
    else if (strCon=="opsi 2 durasi putar murottal dhuhur") {
      Serial.println("opsi 2 durasi putar murottal dhuhur.");
      Serial.println("Masukkan Menit lama durasi murottal akan diputar.");
      Serial.println("Alamat EEPROM digunakan 120.");

      int durasi;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          durasi = strCon.toInt();
          Serial.println(durasi);
          
          if (durasi > 0 && durasi < 256)
          {
            writeEEPROM(120, durasi);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();
            
            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, cth: 60 untuk durasi 60 menit, maximum durasi 255 menit");
          }
        }
      }
    }
    else if (strCon=="opsi 2 durasi putar murottal ashar") {
      Serial.println("opsi 2 durasi putar murottal ashar.");
      Serial.println("Masukkan Menit lama durasi murottal akan diputar.");
      Serial.println("Alamat EEPROM digunakan 121.");

      int durasi;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          durasi = strCon.toInt();
          Serial.println(durasi);
          
          if (durasi > 0 && durasi < 256)
          {
            writeEEPROM(121, durasi);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();
            
            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, cth: 60 untuk durasi 60 menit, maximum durasi 255 menit");
          }
        }
      }
    }
    else if (strCon=="opsi 2 durasi putar murottal maghrib") {
      Serial.println("opsi 2 durasi putar murottal maghrib.");
      Serial.println("Masukkan Menit lama durasi murottal akan diputar.");
      Serial.println("Alamat EEPROM digunakan 122.");

      int durasi;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          durasi = strCon.toInt();
          Serial.println(durasi);
          
          if (durasi > 0 && durasi < 256)
          {
            writeEEPROM(122, durasi);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();
            
            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, cth: 60 untuk durasi 60 menit, maximum durasi 255 menit");
          }
        }
      }
    }
    else if (strCon=="file murottal shubuh") {
      Serial.println("File murottal shubuh");
      Serial.println("Alamat EEPROM digunakan 123.");

      int fileMurottal;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          fileMurottal = strCon.toInt();
          Serial.println(fileMurottal);
          
          if (fileMurottal > 0 && fileMurottal < 256)
          {
            writeEEPROM(123, fileMurottal);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();
            
            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, 1-255.");
          }
        }
      }
    }
    else if (strCon=="file murottal dhuhur") {
      Serial.println("File murottal dhuhur");
      Serial.println("Alamat EEPROM digunakan 124.");

      int fileMurottal;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          fileMurottal = strCon.toInt();
          Serial.println(fileMurottal);
          
          if (fileMurottal > 0 && fileMurottal < 256)
          {
            writeEEPROM(124, fileMurottal);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();
            
            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, 1-255.");
          }
        }
      }
    }
    else if (strCon=="file murottal ashar") {
      Serial.println("File murottal ashar");
      Serial.println("Alamat EEPROM digunakan 125.");

      int fileMurottal;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          fileMurottal = strCon.toInt();
          Serial.println(fileMurottal);
          
          if (fileMurottal > 0 && fileMurottal < 256)
          {
            writeEEPROM(125, fileMurottal);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();
            
            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, 1-255.");
          }
        }
      }
    }
    else if (strCon=="file murottal maghrib") {
      Serial.println("File murottal maghrib");
      Serial.println("Alamat EEPROM digunakan 126.");

      int fileMurottal;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          fileMurottal = strCon.toInt();
          Serial.println(fileMurottal);
          
          if (fileMurottal > 0 && fileMurottal < 256)
          {
            writeEEPROM(126, fileMurottal);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();
            
            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, 1-255.");
          }
        }
      }
    }
    else if (strCon=="set juzz mulai") {
      Serial.println("File murottal otomatis.");
      Serial.println("Alamat EEPROM digunakan 127.");

      int fileMurottal;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          fileMurottal = strCon.toInt();
          Serial.println(fileMurottal);
          
          if (fileMurottal > 0 && fileMurottal < 31)
          {
            writeEEPROM(127, fileMurottal);
            EEPROM.commit();

            Serial.println("EEPROM Committed");
            loadDataEEPROM();
            
            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, 1-30.");
          }
        }
      }
    }
    else if (strCon=="playMP3") {
      Serial.println("Playing MP3");
      Serial.println("Masukkan ID File: 1-9999 ==> 1-255");

      int fileMurottal;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          fileMurottal = strCon.toInt();
          Serial.println(fileMurottal);
          
          if (fileMurottal > 0 && fileMurottal < 256)
          {
            Serial.print("Play MP3, ID File: ");
            Serial.println(fileMurottal);
            //mp3_play(fileMurottal);
            ABLedDFPlayer.stop();
            delay(200);
            ABLedDFPlayer.play(fileMurottal);
            delay(200);

            Serial.print("Current File Number:");
            Serial.println(ABLedDFPlayer.readCurrentFileNumber());
            Serial.print("Pin Busy: ");
            Serial.println(digitalRead(PIN_BUSY));

            break;
          }
          else
          {
            Serial.println("Masukkan format bilangan yang benar, 1-255.");
          }
        }
      }
    }
    else if (strCon=="stopMP3") {
      Serial.println("Stopping MP3");
      ABLedDFPlayer.stop();
      flagPlayMP3 = 0;

      Serial.print("Pin Busy: ");
      Serial.println(digitalRead(PIN_BUSY));
    }
    else if (strCon=="volumeMP3") {
      Serial.println("Set volume MP3");
      Serial.println("Masukkan nilai level volume: 0-30.");

      int levelVolume;
      
      while(true)
      { 
        if (udp.parsePacket()) 
        {
          remoteIp = udp.remoteIP();
          len = udp.read(packetBuffer, 255);
          if (len > 0) packetBuffer[len] = 0;
          strCon = packetBuffer;
         
          levelVolume = strCon.toInt();

          if (levelVolume >= 0 && levelVolume <31)
          {
              ABLedDFPlayer.volume(levelVolume);
              Serial.print("Level volume: ");
              Serial.println(levelVolume);

              break;
          }
          else
          {
            Serial.println("Masukkan nilai yang benar: 0-30");
          }
        }
      }
    }
    else if (strCon=="restart") {
      ESP.restart();
    }
  }
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

//----------------------------------------Procedure for receiving text / messages from the sender-------------------------------------------------------------------------------------------//
void playMP3(int idMurottal) {
  //mp3_play (idMurottal); //memainkan lagu 1 pada folder mp3 yang sudah direname dengan nama 0001.mp3
  //delay (10000); //jeda 10 detik
  //mp3_next (); //memainkan lagu 2 dengan mode next
  //delay (10000);
  //mp3_play (idMurottal); //memainkan lagu 3
  //delay (6000);

  //Sketch from: https://www.nyebarilmu.com/tutorial-mengakses-module-mp3-dfplayer-mini/?fbclid=IwAR0b0fNagVHdLAKPjjR_crMkXfdeIf9Y9McVnNZzBmFOVlnDO0IH_zVg2z4
  //Serial.println("Stop");
  //mp3_stop ();
  //Serial.print("Busy: ");
  //Serial.println(digitalRead(PIN_BUSY));
  //delay(500);
  //Serial.println("play next");
  //mp3_next ();
  //Serial.print("Busy: ");
  //Serial.println(digitalRead(PIN_BUSY));
  //delay (12000);
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------//

//---------------------------------------- Read eeprom for ssid and pass
void readSSIDnPWD()
{
  ssidSaved = "";
  passwordSaved = "";
  
  for (int i = 0; i < 32; ++i)
  {
    ssidSaved += char(EEPROM.read(i));
  }
  
  for (int i = 32; i < 96; ++i)
  {
    passwordSaved += char(EEPROM.read(i));
  }
   
}


//---------------------------------------- Read eeprom for ssid and pass

char readEEPROM(int addr)
{
  return char(EEPROM.read(addr));
}

void writeEEPROM(int addr, int nilai)
{
  EEPROM.write(addr, nilai);
}

void writeEEPROM(int addr, char nilai)
{
  EEPROM.write(addr, nilai);
}


void writeEEPROM(int addr, String str)
{
  if (addr == 0 and str.length() <= 32)  //store ssid
  {
    for (int i=addr; i<32; i++)
    {
      if (addr < str.length())
      {
        EEPROM.write(addr, str[i]);
        //Serial.println(str[i]);
        //delay(10);
      }
      else
      {
        EEPROM.write(addr, 0xFF);
      }
      
      addr++;
    }
  }
  else if (addr == 32 and str.length() <= 96) //store password
  {
    for (int i=addr; i<96; i++)
    {
      if (addr < str.length())
      {
        EEPROM.write(addr, str[i]);
        Serial.println(str[i]);
        delay(10);
      }
      else
      {
        EEPROM.write(addr, 0xFF);
      }
      
      addr++;
    }
  }
  else
  {
    for (int i=addr; i<str.length(); i++)
    {
      char aChar = i;
      Serial.print("Writing ");
      Serial.print(str[i]);
      Serial.print(" on EEPROM at address ");
      Serial.println(aChar);
      EEPROM.write(addr, str[i]);
      addr++;
    }
  }
  
    EEPROM.commit(); 
}



Tidak ada komentar:

Posting Komentar