Posted in Asterisk VoIP

Asterisk Wake Up call application

February 2, 2010 - 2 comments

If you want to be awaken by your Asterisk PBX, here’s a simple bit of code to add in your dial plan.

Basically, you would call 9253 followed by the time the phone should ring, for exemple if you want to be awaken at 06:30am you would call 92530630 (on your dialpad WAKE0610).

This code only allows to set ONE alarm.

If you want to delete -for exemple the 0630am- alarm, you would call 6692530610 (on dialpad NOWAKE0610).

Asterisk will create a call file and put it under /var/spool/asterisk/outgoing/
How does Asterisk know when to call you ? It will check the timestamp of the call files.

Make sure you enable func_strings.so module, it is required for STRFTIME.

[Context-This-Code-Should-Go-In]

; WAKE + hour + minute : sets a wake up call
exten => _9253XXXX,1,Answer()
exten => _9253XXXX,n,Set(wakeuptime=${EXTEN:4:4})
exten => _9253XXXX,n,Set(today=${STRFTIME(${EPOCH},,%Y%m%d)})
exten => _9253XXXX,n,Set(tomorrow=${STRFTIME($[${EPOCH} + 86400],,%Y%m%d)})
exten => _9253XXXX,n,Set(now=${STRFTIME(${EPOCH},,%Y%m%d%H%M)})
exten => _9253XXXX,n,System(echo -e "Channel: SIP/${CALLERID(num)}\\nContext: WakeUp\\nExtension: 92531" > /tmp/${UNIQUEID}.call)
exten => _9253XXXX,n,GotoIf($["${today}${wakeuptime}" < "${now}"]?tomorrow:today)
exten => _9253XXXX,n(today),NoOp(Scheduling wake up call for ${CALLERID(num)} today at ${wakeuptime} / )
exten => _9253XXXX,n,System(touch -t ${today}${wakeuptime} /tmp/${UNIQUEID}.call)
exten => _9253XXXX,n,Goto(move)
exten => _9253XXXX,n(tomorrow),NoOp(Scheduling wake up call for ${CALLERID(num)} tomorrow at ${wakeuptime} / )
exten => _9253XXXX,n,System(touch -t ${tomorrow}${wakeuptime} /tmp/${UNIQUEID}.call)
exten => _9253XXXX,n(move),System(mv /tmp/${UNIQUEID}.call /var/spool/asterisk/outgoing/${wakeuptime}.${UNIQUEID}.call)
exten => _9253XXXX,n,Wait(1)
exten => _9253XXXX,n,SayNumber(${wakeuptime})
exten => _9253XXXX,n,Hangup()

; NOWAKE + hour + minute : deletes a wake up call
exten => _669253XXXX,1,Answer()
exten => _669253XXXX,n,Set(wakeuptime=${EXTEN:6:4})
exten => _669253XXXX,n,NoOp(Deleting alarm set at ${wakeuptime})
exten => _669253XXXX,n,System(rm -f /var/spool/asterisk/outgoing/${wakeuptime}*)
exten => _669253XXXX,n,Wait(1)
exten => _669253XXXX,n,Background(auth-thankyou)
exten => _669253XXXX,n,Hangup()

[WakeUp]
;;; Context for outgoing wake up calls only, well you can always call 92531 but it's rather pointless
exten => 92531,1,Answer()
exten => 92531,n,Wait(1)
exten => 92531,n,Background(hello-world)
exten => 92531,n,Wait(1)
exten => 92531,n,Hangup()

Comments

The Adminblogger

February 3, 2010 - 0:10

Hi,

why not call an external script that does the setup of the call file instead of writing this pice of ugly (unreadable) code?

Kinda obscure code nobody can really read and understand, no comments etc :-)

i would rather call a script that does the voodoo and keep my config file small.

Just my 2 cents.

Marcel.

Sébastien Wains

February 3, 2010 - 0:43

Hi Marcel, thanks for your input.

1. By definition, Asterisk dialplan is ugly :-)
2. When “coding”, I usually only comment the “what”, not the “how”. I don’t need to explain “this is a condition” right ? Anyone used to asterisk dialplans would figure this one out in under 2 minutes. Even if the code and logic are bad.
3. I’m just sharing what works for me. I’ve found other solutions here and there but none were fitting my needs (and working out of the box). This is why I shared. Try it for yourself, copy & paste the code, it’ll work out of the box.
4. Yeah I could use an AGI or whatever script.. AGI would require to load res_agi.so, a 64 KB module plus the AGI script, compared to this 1.9KB code…
5. So I’m gonna leave it to the experts, is calling an external script (and potentially an external parser) more efficient than using pure dialplan commands and functions ?

Cheers
Seb

Leave Comment

Please consider visiting the partners below if you enjoyed this article :

If this post saved you time and money, please consider checking my Amazon wishlist.

Before submitting, some rules :
- Is your comment related to the article ?
- You're having a problem ? Have you checked Google, other howtos, docs, manpages ?
- You're still having the problem ? Have you raised log verbosity, checked traces, ran tcpdump ?
- Have you checked your configuratoin for typo ?
Unless your comment is providing additional info or respect the rules above, DON'T comment.
If you don't understand what you are doing, I urge you to read the documentation, I'm not your free Level 1 helpdesk guy.