long shot - Asterisk?

mudcow007
mudcow007 Posts: 3,861
edited September 2012 in Commuting chat
anyone on here ever done any programming in Asterisk?

basically trying to make an alarm to run through our PBX

i have set a call file up which works

Channel: local/777@internal
callerid: 777
MaxRetries: 5
Retrytime: 300
WaitTime: 45
Context: Alarm
Extension: s
Priority: 1

within Extensions

[alarm]
exten => s,1,SIPAddHeader(Call-Info:\; answer-after=0)
exten => s,n,Dial(SIP/901,,A(Hello-World)gS(1))
exten =>s,n,Hangup()

this works, but before pushing the call to 901 (our tannoy system) it rings the ext 777. when that extension answers the message is played over 901

once i have this setup i have to figure out "Crontab"

im stumped
Keeping it classy since '83

Comments

  • mtb-idle
    mtb-idle Posts: 2,179
    That's galling. :wink:
    FCN = 4
  • MTB-Idle wrote:
    That's galling. :wink:
    Ouch.Chapeau.

    Or even Gauling.... :wink:

    I suppose you'd have to be a star programmer...
    "Get a bicycle. You won't regret it if you live"
    Mark Twain
  • cookdn
    cookdn Posts: 410
    Hi mudcow

    I do Asterisk stuff but have not done call files for some time, I'll have a look at this later this afternoon. It appears like you are nearly there, usually these things need a minor (but potentially time consuming to find) tweak.

    Crontab is easier than it looks. What is your OS distro? We use RHEL derived Centos and depending on our needs most of the time we can get away with putting the script into one of the cron directories e.g. /etc/cron.hourly or /etc/cron.daily. This is preferable to mucking around with /etc/crontab directly but even that is not difficult once you get your head around the formatting.

    Best regards
    David
    Boardman CX Team
  • gtvlusso
    gtvlusso Posts: 5,112
    I don't know asterisk; but I do know c and c#....

    Anyway, I used to be a PBX engineer back in the days when you programmed in Hex codes.... :shock:

    Nice to see PBX's using SIP - Ip to desk innit?!

    for crontab - assumed to be run as root crontab:

    crontab -e to edit the crontab.

    crontab -l to view the crontab

    There are loads of webpages telling you the time formats and so on, so, I will let you google for that!

    Also worth backing up your crontab:

    crontab -l > /opt/<<application>>/<<filename>>.bak
  • mudcow007
    mudcow007 Posts: 3,861
    cheers guys

    distro is ubuntu "fiesty fawn" - never wanted to upgrade as "it works" plus im running a pretty version of asterisk

    thanks for the headsup about crontab.

    the dialling out thing is messing with my head now, i think ive had about 7 coffees today grr


    the master plan is to set up a break time alarm for our factory staff - yes i have already todl them we can buy a standalone system for it. but my md wants me to run it through the pbx

    so i will need cron to run the same thing 5 days a week, im pretty sure its just a case of setting the variables
    Keeping it classy since '83
  • gtvlusso
    gtvlusso Posts: 5,112
    Can you tell me what is not working with your file - what happens when you initiate the call manually? At which stage does it fail?

    Crontab is a breeze - last of your worries!
  • mudcow007
    mudcow007 Posts: 3,861
    gtvlusso wrote:
    Can you tell me what is not working with your file - what happens when you initiate the call manually? At which stage does it fail?

    Crontab is a breeze - last of your worries!


    well, as far as im aware, call files need a channel to initiate the call. im my case i have chosen

    Channel: local/777@internal (all our extensions are within "internal")

    as the call file runs through it pushes the call to context "alarm" an runs through s,1 - this is cool

    s,1 adds the auto answer header to the call, which then goes onto our tannoy phone @ 901 an plays "hello world"

    the issue is, the channel that is used to initiate the call has to ring an be answered to progress with the call.

    so, copy call file to outgoing > extension 777 rings > answer the call > tannoy plays "hello world"

    all i want it to do is the tannoy an not ring 777

    if thats possible
    Keeping it classy since '83
  • gtvlusso
    gtvlusso Posts: 5,112
    Sounds like you need a dummy extn.....or can you call the tannoy port direct?
  • cookdn
    cookdn Posts: 410
    I think I have this figured. :)

    When Asterisk processes the call file it dials the endpoint defined by the 'Channel' parameter. If the dialled endpoint answers then the call flow jumps into your dialplan logic at a position defined by 'Context' and 'Extension'.

    Effectively your use of the call file is to dial extension 777, when that is answered the dialplan logic dials extension 901, and when 777 and 901 are connected plays the HelloWorld audio message.

    Really what you want to do is dial extension 901 and when answered play your audio message without involving another endpoint. There is a good example of this on the voip-info.org wiki (http://www.voip-info.org/wiki/view/Aste ... foremergen).

    However I think I can see why you have gone about this the way you have. You need to send a modified SIP header to your tannoy system to instruct it to automatically answer the incoming call. It looks like you can do this directly in the call file by using the optional 'Set' parameter (http://www.voip-info.org/wiki/view/Aste ... fcallfiles) to specify the required SIP header (http://forums.digium.com/viewtopic.php?f=1&t=16276).

    The following call file and dialplan logic should do what I have just described if the information is correct and I have understood things properly.
    Channel: SIP/901@internal
    callerid: 777
    MaxRetries: 5
    Retrytime: 300
    WaitTime: 45
    Context: Alarm
    Extension: s
    Priority: 1
    Set: __SIPADDHEADER=Call-Info:\;answer-after=0
    
    [alarm]
    exten => s,1,Answer()
    exten => s,n,Wait(1)
    exten => s,n,Playback(Hello-World)
    exten => s,n,Wait(1)
    exten => s,n,Hangup()
    

    Note that this does need at least Asterisk v1.4 for the call file 'Set' parameter to handle dialplan functions.

    For scheduling your tannoy messages you can set the modification datetime of the call file to the time in the future when you want it to be processed in addition to writing it out directly using a script and crontab. This might give you some flexibility over scheduling without having lots of crontab entries.

    Hope this helps.

    Best regards
    David
    Boardman CX Team
  • Please see below the full extent of my computer programming knowledge:

    10 PRINT “HUTTON IS A JOEY”
    20 GO TO 10
    RUN

    I hope this helps.
  • mudcow007
    mudcow007 Posts: 3,861
    edited September 2012
    **edit

    im a spanner an couldnt type!

    David i owe you a beer or three!!

    by jingo it works

    i had a typo in my set function

    :mrgreen:
    Keeping it classy since '83
  • Asterix2.jpg
  • cookdn
    cookdn Posts: 410
    mudcow007 wrote:
    i tried your modified dialplan but it failed, its still calling the extension (901)

    i had to change your .call file

    from : channel: SIP/901@internal
    to channel: local/901@

    by the looks of it, its not using the "set" function, i also cant see it anywhere in the cli

    So the tannoy system (901) is now called direct (777 is no longer involved), but it doesn't auto answer?
    Boardman CX Team
  • cookdn
    cookdn Posts: 410
    Asterix2.jpg

    Nah, that dude is called Asterix. This is

    asterisk-bubble.png

    :)
    Boardman CX Team
  • mudcow007
    mudcow007 Posts: 3,861
    cookdn wrote:
    mudcow007 wrote:
    i tried your modified dialplan but it failed, its still calling the extension (901)

    i had to change your .call file

    from : channel: SIP/901@internal
    to channel: local/901@

    by the looks of it, its not using the "set" function, i also cant see it anywhere in the cli

    So the tannoy system (901) is now called direct (777 is no longer involved), but it doesn't auto answer?

    ahh you quoted as i edited my post

    it was a typo, it now works!

    i had a typo on the set function hence why it was ignoring it

    i just need to now figure out how i can set it to run multiple times through out the day, every day!
    Keeping it classy since '83
  • cookdn
    cookdn Posts: 410
    mudcow007 wrote:
    ahh you quoted as i edited my post

    it was a typo, it now works!

    Cool ... :D
    mudcow007 wrote:
    i had a typo on the set function hence why it was ignoring it

    Always the case, I must have burnt up hours on silly typos. Good you spotted it.
    mudcow007 wrote:
    i just need to now figure out how i can set it to run multiple times through out the day, every day!

    What is the schedule for the announcement? The shell script called by crontab shouldn't be too hard.

    Best regards
    David
    Boardman CX Team
  • mudcow007
    mudcow007 Posts: 3,861
    basically i need crontab to run the "alarm" at 10, 10:15 and 11:00 each day

    i understand if i put in * as a variable within day an month it will just keep doing what ever function.

    im guessing i can use 1-5 for weekdays?

    its the function i need to work out
    Keeping it classy since '83
  • davis
    davis Posts: 2,506
    mudcow007 wrote:
    basically i need crontab to run the "alarm" at 10, 10:15 and 11:00 each day

    i understand if i put in * as a variable within day an month it will just keep doing what ever function.

    im guessing i can use 1-5 for weekdays?

    its the function i need to work out

    That's:
    0   10,11 * * 1-5 #things to run at 10h00 and 11h00
    15  10    * * 1-5 #things to run at 10h15.
    

    Edited for weekday
    Sometimes parts break. Sometimes you crash. Sometimes it’s your fault.
  • mudcow007
    mudcow007 Posts: 3,861
    davis wrote:

    That's:
    0   10,11 * * 1-5 #things to run at 10h00 and 11h00
    15  10    * * 1-5 #things to run at 10h15.
    

    Edited for weekday

    thanks davis

    i need to copy a file an drop it into a specified folder, im guessing this would be something like
    0,5,10 * * * *cp /var/spool/asterisk/alarm.call /var/spool/asterisk/outgoing/alarm.call
    

    as a test im hoping i cant get it to run ever 5 mins

    muchass grassyarse!
    Keeping it classy since '83
  • davis
    davis Posts: 2,506
    mudcow007 wrote:
    davis wrote:

    That's:
    0   10,11 * * 1-5 #things to run at 10h00 and 11h00
    15  10    * * 1-5 #things to run at 10h15.
    

    Edited for weekday

    thanks davis

    i need to copy a file an drop it into a specified folder, im guessing this would be something like
    0,5,10 * * * *cp /var/spool/asterisk/alarm.call /var/spool/asterisk/outgoing/alarm.call
    

    as a test im hoping i cant get it to run ever 5 mins

    muchass grassyarse!

    yarp. Although if you want to do it every five minutes then:
    */5 * * * * cp /var/spool/asterisk/alarm.call /var/spool/asterisk/outgoing/alarm.call
    

    Works on most *nixes.
    Sometimes parts break. Sometimes you crash. Sometimes it’s your fault.
  • mudcow007
    mudcow007 Posts: 3,861
    Bloody marvelous!

    thanks all

    heres the finished article i think


    30 8 * * 1-5 cp /var/spool/asterisk/alarm.call /var/spool/asterisk/outgoing/alarm.call
    15,30,45 10 * * 1-5 cp /var/spool/asterisk/alarm.call /var/spool/asterisk/outgoing/alarm.call
    0 10,11,12,13,14,15 * * 1-5 cp /var/spool/asterisk/alarm.call /var/spool/asterisk/outgoing/alarm.call
    15,30,45 14,15 * * 1-4 cp /var/spool/asterisk/alarm.call /var/spool/asterisk/outgoing/alarm.call
    30 16 * * 1-5 cp /var/spool/asterisk/alarm.call /var/spool/asterisk/outgoing/alarm.call
    Keeping it classy since '83
  • jejv
    jejv Posts: 566
    So you did get a fix ?
  • EKE_38BPM
    EKE_38BPM Posts: 5,821
    10100000 00011111 00100100 00111100 01001011 00010011 11000100 10100111
    10101100 10110010 01101100 10101001 10010100 01101110 11110010 10010010
    11100000 00101011 01010010 01111010 01001101 00010000 10011110 11010011
    11010100 10011000 00101011 00101111 00011011 01011101 01010010 01011101
    00001100 10010110 00001101 00100010 10011000 11100100 10110000 11111111
    00111011 00101101 11111110 00000101 10110111 00000101 10001100 11100110
    01110001 01010000 01101011 01101001 11010011 00011001 11010110 10110111
    10010111 10101100 00010100 10110111 01001001 00001101 11111000 10101111
    10000011 10111100 11110010 01010000 10010111 00110111 11001011 01010010
    11000110 11100110 01101110 01100100 01111111 11110000 01101011 11011111
    10110110 01001100 01011000 00100011 10100001 00110010 01100101 00101111
    11111001 01101111 01001001 00111000 00000110 11011101 01000111 01110011
    10001110 00000011 10010000 01111101 00001100 01000110 01110011 00000110

    And if you don't understand that, well, you're just not hip.
    FCN 3: Raleigh Record Ace fixie-to be resurrected sometime in the future
    FCN 4: Planet X Schmaffenschmack 2- workhorse
    FCN 9: B Twin Vitamin - winter commuter/loan bike for trainees

    I'm hungry. I'm always hungry!
  • mudcow007
    mudcow007 Posts: 3,861
    EKE_38BPM wrote:
    10100000 00011111 00100100 00111100 01001011 00010011 11000100 10100111
    10101100 10110010 01101100 10101001 10010100 01101110 11110010 10010010
    11100000 00101011 01010010 01111010 01001101 00010000 10011110 11010011
    11010100 10011000 00101011 00101111 00011011 01011101 01010010 01011101
    00001100 10010110 00001101 00100010 10011000 11100100 10110000 0000110

    And if you don't understand that, well, you're just not hip.

    yeah, especially the blond one..... :wink:


    jejv wrote:
    So you did get a fix ?

    yap all done

    :mrgreen: i can sleep easy now
    Keeping it classy since '83
  • PBo
    PBo Posts: 2,493
    Godders1 wrote:
    Please see below the full extent of my computer programming knowledge:

    10 PRINT “HUTTON IS A JOEY”
    20 GO TO 10
    RUN

    I hope this helps.

    This is the only post in this entire thread that I understand.....

    Must say you are dating yourself....both by use of BBC MICRO/zx spectrum/c64 BASIC.......*

    ......and by use of the phrase "joey"!!!

    * I will date myself even further by pointing out that it would also have worked on a zx 80 and commodore PET
  • PBo
    PBo Posts: 2,493
    EKE_38BPM wrote:
    10100000 00011111 00100100 00111100 01001011 00010011 11000100 10100111
    10101100 10110010 01101100 10101001 10010100 01101110 11110010 10010010
    11100000 00101011 01010010 01111010 01001101 00010000 10011110 11010011
    11010100 10011000 00101011 00101111 00011011 01011101 01010010 01011101
    00001100 10010110 00001101 00100010 10011000 11100100 10110000 11111111
    00111011 00101101 11111110 00000101 10110111 00000101 10001100 11100110
    01110001 01010000 01101011 01101001 11010011 00011001 11010110 10110111
    10010111 10101100 00010100 10110111 01001001 00001101 11111000 10101111
    10000011 10111100 11110010 01010000 10010111 00110111 11001011 01010010
    11000110 11100110 01101110 01100100 01111111 11110000 01101011 11011111
    10110110 01001100 01011000 00100011 10100001 00110010 01100101 00101111
    11111001 01101111 01001001 00111000 00000110 11011101 01000111 01110011
    10001110 00000011 10010000 01111101 00001100 01000110 01110011 00000110

    And if you don't understand that, well, you're just not hip.

    I can't be bothered to work it out, but is it a "square" number?