Najad
Published © LGPL

ESP32 Based Islamic Prayer Time Display

Instead of calculating the prayer time using coordinates, we're fetching the prayer time data from the internet and displaying it on an LCD

BeginnerShowcase (no instructions)1,028
ESP32 Based Islamic Prayer Time Display

Things used in this project

Story

Read more

Schematics

Circuit for ESP32 Prayer time Display

Code

Code for ESP32 Prayer Time Display

Arduino
//program by https://diyusthad.com

#include <SPI.h>
#include <Wire.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>

#include <LiquidCrystal_I2C.h>

const char* ssid = "YOUR_SSID";
const char* password = "YOUR_WIFI_PASSWORD";

int lcdColumns = 16;
int lcdRows = 4;

LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);


const char* data_timings_Fajr ;
const char* data_timings_Sunrise ;
const char* data_timings_Dhuhr ;
const char* data_timings_Asr ;
const char* data_timings_Sunset ;
const char* data_timings_Maghrib ;
const char* data_timings_Isha ;
const char* data_timings_Imsak ;
const char* data_timings_Midnight ;


void setup() {

  Serial.begin(115200);

  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP Address: ");
  Serial.println(WiFi.localIP());

  lcd.init();
  // turn on LCD backlight
  lcd.setBacklight(10);
  fetchData();

}

void loop() {

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Fajr    : ");
  lcd.print(data_timings_Fajr);
  lcd.setCursor(0, 1);
  lcd.print("Dhuhr   : ");
  lcd.print(data_timings_Dhuhr);
  delay(2000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Asr     : ");
  lcd.print(data_timings_Asr);
  lcd.setCursor(0, 1);
  lcd.print("Maghrib : ");
  lcd.print(data_timings_Maghrib);
  delay(2000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Isha : ");
  lcd.print(data_timings_Isha);
  delay(2000);
}

void fetchData()
{
  if (WiFi.status() == WL_CONNECTED) {

    HTTPClient http;

    Serial.print("[HTTP] begin...\n");
    if (http.begin("http://api.aladhan.com/v1/timingsByCity?city=Dubai&country=United%20Arab%20Emirates&method=4")) {  // API Request


      Serial.print("[HTTP] GET...\n");
      // start connection and send HTTP header
      int httpCode = http.GET();

      // httpCode will be negative on error
      if (httpCode > 0) {
        // HTTP header has been send and Server response header has been handled
        Serial.printf("[HTTP] GET... code: %d\n", httpCode);

        // file found at server
        if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
          String payload = http.getString();

          DynamicJsonDocument doc(2048);
          deserializeJson(doc, payload);
          JsonObject data = doc["data"];

          JsonObject data_timings = data["timings"];

          data_timings = data["timings"];
          data_timings_Fajr = data_timings["Fajr"]; // "05:13"
          data_timings_Sunrise = data_timings["Sunrise"]; // "06:31"
          data_timings_Dhuhr = data_timings["Dhuhr"]; // "12:29"
          data_timings_Asr = data_timings["Asr"]; // "15:52"
          data_timings_Sunset = data_timings["Sunset"]; // "18:26"
          data_timings_Maghrib = data_timings["Maghrib"]; // "18:26"
          data_timings_Isha = data_timings["Isha"]; // "19:56"
          data_timings_Imsak = data_timings["Imsak"]; // "05:03"
          data_timings_Midnight = data_timings["Midnight"]; // "00:29"

          //Serial.println("fajr time:");
          //Serial.println(data_timings_Fajr);
          //Serial.println(data_timings_Dhuhr);
          //Serial.println(data_timings_Asr);
          //Serial.println(data_timings_Maghrib);
          //Serial.println(data_timings_Isha);

        }
      } else {
        Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
      }

      http.end();
    } else {
      Serial.printf("[HTTP} Unable to connect\n");
    }
  }
}

Credits

Najad

Najad

30 projects • 96 followers
Just crazy stuff​

Comments