The Raspberry Pi, known for its versatility and cost-effectiveness, has become the heart of numerous do-it-yourself projects, ranging from home automation to robotics. One distinctive and valuable application of the Raspberry Pi is its role as an Azaan (Prayer) notifier. For individuals who follow the Islamic faith, staying connected with daily prayer times is crucial. In this article, we’ll delve into the process of turning a Raspberry Pi into an Azaan Prayer Times Notifier, aiding in the fulfillment of religious duties in a more convenient manner.

Hardware and Software Requirements:

  1. Raspberry Pi (any model will work).
  2. MicroSD card with Raspbian OS.
  3. Speaker or audio output device.
  4. Internet connection (Wi-Fi or Ethernet).
  5. Access to an Islamic prayer times API.

Setting Up the Raspberry Pi:

The initial step involves the installation of the Raspbian OS on a microSD card, followed by configuring the Raspberry Pi. It’s essential to ensure a reliable internet connection.

Python Script for Prayer Times:

A Python script is necessary to retrieve prayer times from an Islamic prayer times API.

  1. Create a directory in the home

mkdir /home/<username>/azaan

  1. Create a python file named “azaan.py” and update it with below codes

nano azaan.py

copy and paste the code

#!/usr/bin/env python3

import datetime

import requests

import pytz

from crontab import CronTab

import re

# Set the coordinates of Offenbach am Main

LATITUDE = 50.103151

LONGITUDE = 8.766111

# Get the current date and time

utc = pytz.timezone(‘UTC’)

now = utc.localize(datetime.datetime.utcnow())

# Calculate the Fajr Azan time

fajr_azan_time = now + datetime.timedelta(hours=6)

# Make a request to the Islamic Prayer Times API to get the other Azan times

azan_times_api_url = “https://api.aladhan.com/v1/calendar”

params = {

“latitude”: LATITUDE,

“longitude”: LONGITUDE,

“method”: “3”, # Hanafi method

“date”: fajr_azan_time.strftime(“%Y-%m-%d”)

}

response = requests.get(azan_times_api_url, params=params)

# Parse the response and get the Azan times

azan_times = response.json()[“data”][0][“timings”]

# Print the Azan times

print(“Fajr:”, azan_times[“Fajr”])

print(“Dhuhr:”, azan_times[“Dhuhr”])

print(“Asr:”, azan_times[“Asr”])

print(“Maghrib:”, azan_times[“Maghrib”])

print(“Isha:”, azan_times[“Isha”])

# Update Crontab with Prayer Times

# ———————————

system_cron = CronTab(user=’mehedi’)

strPlayAzaanMP3Command = ‘mpg321 /home/<username>/azan/Abdul-Basit.mp3 > /dev/null 2>&1′

jobs = system_cron.find_command(strPlayAzaanMP3Command)

for j in jobs:

system_cron.remove(j)

# Function to add Azan time to cron

def addAzaanTime(strPrayerName, strPrayerTime, objCronTab, strCommand):

job = objCronTab.new(command=strCommand, comment=strPrayerName)

# Split the time and timezone parts

time_part, timezone_part = re.search(r'(\d+:\d+) \(([^)]+)\)’, strPrayerTime).groups()

# Parse the time part

hour, minute = map(int, time_part.split(‘:’))

# Create the desired format for CronTab

job.setall(minute, hour, ‘*’, ‘*’, ‘*’)

print(job)

# Iterate over the 5 daily Azan times and create Cron jobs for each

for prayer_name in [“Fajr”, “Dhuhr”, “Asr”, “Maghrib”, “Isha”]:

addAzaanTime(prayer_name, azan_times[prayer_name], system_cron, strPlayAzaanMP3Command)

# Save the Cron configuration to a file

system_cron.write()

CronTab Configuration:

The scheduling tool ‘CronTab,’ available on Linux-based systems, is utilized to establish scheduled tasks for playing the Azaan audio at designated prayer times. The script can be programmed to execute at specific times daily, such as the Fajr Azaan at dawn and the Maghrib Azaan at sunset.

Crontab -e

Then

Add the below line end of the script

* 0 * * * /usr/bin/python3 /home/<username>/azan/azan.py >> /tmp/cron_output.log 2>&1

Audio Output:

An audio output device or speaker is connected to the Raspberry Pi. Users can opt for the Raspberry Pi’s audio jack or USB audio adapters for improved sound quality. Download the Azaan MP3 from this URL: https://github.com/mirrayhan08/AzanPlayer/blob/main/Abdul-Basit.mp3

Azaan Audio Files:

Azaan audio files are either downloaded or recorded, corresponding to each prayer time that requires notification. These audio files are played by the Raspberry Pi when the scheduled time arrives.

Check the cron job

crontab -l -u mehedi

 

By Rayhan

My name is Rayhan and I'm an IT professional with over 10 years of experience in the field. I'm passionate about all things tech, and I love helping people solve their IT problems. In my free time, I enjoy tinkering with new gadgets and software, and I'm always on the lookout for the latest tech trends. I believe that technology has the power to make our lives easier and more enjoyable, and I'm excited to be a part of this ever-evolving field. Thank you for taking the time to visit my page.

Leave a Reply

Your email address will not be published. Required fields are marked *