Home AMX User Forum NetLinx Studio

Islamic Prayer time module.

Hi All,

I Want to write a program for Islamic prayer timings. I need to play the music automatically when the prayer time comes. There are 5 different times in a day and everyday the time will change.
Can anyone guide me on this?

Please share if anyone have module.

Thanks in advance.

Comments

  • ericmedleyericmedley Posts: 4,177
    There are any number of ways to accomplish this. but, the easiest would be to just watch the "time" the keyword "Time" is a little function that when called sends you back a text message in the format <HH:MM:SS> which is based on the master's clock.
    {'05:00:00'}
    So a very simple way is to just look for the strings you want.

    This code snpet is just for the theory of it. You'll need to decide how you want to implement it in your code...
    DEFINE_VARIABLE
    
    volatile char Prayer_Times[][8]={
      {'05:00:00'}  // These are just initial values that can be changed dynamically
      ,{'10:00:00'}
      ,{'12:00:00'}
      ,{'15:00:00'}
      ,{'21:00:00'}
    }
    
    DEFINE_EVENT
    
    TIMLINE_EVENT[Prayer_Timer]{ // A timeline that triggers once very minute...
    sack_var char MyTIme[8]
    stack_var integer nloop;
    MyTime=TIME;
    for(nloop=length_array(Prayer_Times);nloop;nloop--){
      if(MyTime==Prayer_Times[nloop]){
        // it's prayer time X, where X=nloop, do something
        }
    }
    

    this should get you started. You can use a variable to dynamically alter the prayer times if you with or just keep them at the exact same time. You'll have to setup the timeline, of course. And like I say, there are any number of ways to approach this. This is just a basic start to get you going.

  • Thanks for your reply. The main problem i am facing is to pull the 5 different times from the internet. Also its not the same time for everyday .

    Please guide me on this.

    Thanks.
  • ericmedleyericmedley Posts: 4,177
    Yeah, I realized that the times are different. However, that is a whole other issue. My best advice is to see if you can find an RSS type feed that can provide it. Or, if you have access to some kind of document like an excel spread sheet that might have the times. You can then just parse for the data. I do not know of any such things. Sorry.
  • I wrote one in Duet awhile ago. Scraped the math out of some open source javascript. In the end we just subscribed to a service that provides the time based on location and wrote a simple Nelinx layer web client to handle the data.
  • I can help you on that, I have been working on this module for sometime and it is already done now, I have built a Netlinx module that will do the calculation based on your location and it will notify the Netlinx code through 7 channel events, one for each pray time plus sunrise and sunset
    I'm afraid that I will not be able to share the code with you because I have done it for commercial use, if you wish I can share the module with you but you will need to buy a license for it to have it fully working
    the module doesn't use any online services to calculate the times, everything is done locally in the Netlinx master
    Please let me know if this works for you
  • sling100sling100 Posts: 123
    Have a look at this

    http://praytimes.org/calculation/
    http://praytimes.org/wiki/Code

    If you are familiar with Julian dates I reckon you could write something in Netlinx.
    There's a number of examples in other languages on the wiki page that you could adapt fairly easily too.

    Simon
  • AhmadAhmad Posts: 1

    Certainly! Here's a shorter version using Python with the pygame library:

    import time
    import pygame
    from datetime import datetime
    
    pygame.mixer.init()
    
    prayer_timings = {
        "Fajr": "05:30",
        "Dhuhr": "12:00",
        "Asr": "15:30",
        "Maghrib": "18:45",
        "Isha": "20:00"
    }
    
    def check_prayer_time():
        current_time = datetime.now().strftime("%H:%M")
    
        for prayer, time in prayer_timings.items():
            if current_time == time:
                print(f"It's {prayer} time!")
                pygame.mixer.music.load('your_music_file.mp3')
                pygame.mixer.music.play()
                return
    
    while True:
        check_prayer_time()
        time.sleep(60)
    

    Replace 'your_music_file.mp3' with the actual path to your music file. This program continuously checks the current time against predefined prayer timings and plays music when it's time for a prayer. Adjust the prayer timings and customize as needed.

Sign In or Register to comment.