Home » 2007 » February

Monthly Archives: February 2007

The Most Versatile VoIP Provider: FREE PORTING

Introducing Nerd Vittles Phone Genie for Asterisk

From Our Disney Cruise Family ScrapbookEver left your home or office and wished you had transferred your calls to your cellphone before you departed. Unless you've done a good bit of design work on your Asterisk® PBX or paid Ma Bell half your monthly paycheck, you're probably S.O.L. until you return to home base. Well, at least until today. Today we introduce version 1.0 of Phone Genie for Asterisk, an all-purpose web utility that lets you reconfigure virtually anything and everything on your Asterisk system on the fly using an incredibly powerful HTML command language that you can master in a matter of minutes. All you'll need is a web browser including most cellphone web browsers as well. And, of course, it's free.

The easiest way to explain how powerful Phone Genie for Asterisk really can be is to give a few examples. So, let's assume you've registered a fully-qualified domain name for your Asterisk server using a free service such as DynDNS.org. Let's use asterisk.dydns.org in our example. Now you're on the road and want to forward calls from extension 200 on your PBX in a Flash system to your cellphone: 678-234-5678. All you need to do is open the browser on your cellphone or any desktop PC and enter the following web address:

http://asterisk.dyndns.org/nv-genie.php?action=dbput&family=CF&key=200&value=6782345678&pw=1234

If you're new to Asterisk, a few hints may be in order. What the Nerd Vittles' Phone Genie does is provide a web interface to the complete Asterisk Manager API. If you also happen to be using the Asterisk Management Portal or freePBX, then the sky's the limit since there are dozens of functions you can execute by simply manipulating data stored in Asterisk's internal database. We'll give you some examples today, and add many more in the coming weeks and months. For today, you'll have to settle for the Phone Genie Starter Kit with three critical Asterisk Manager tools. These three tools give you complete control over Asterisk's internal database: dbget to query the Asterisk internal database, dbput to add and update information in the database, and dbdel to delete records from the database. For the Asterisk whiz kids out there, you're probably chuckling that there's no such command as dbdel in the Asterisk Manager API. And you'd be right, but now there is... at least with the Nerd Vittles Phone Genie.

Do you have to be a whiz kid to use the Phone Genie? Not at all. In fact, all you really need to do is download the application into the default web directory on your Asterisk, PBX in a Flash, trixbox, or Asterisk@Home web server, and keep reading. We've tested Phone Genie with versions of Asterisk@Home dating back to 2.8, and it works perfectly with PBX in a Flash.

Installation and Setup. To begin, you'll need to download the Phone Genie application and set up a very secure password. Why? Because anyone with the web site address of your Asterisk server and access to this application could trash your Asterisk system faster than you can mutter "Genie in a Bottle." So log into your PBX in a Flash server as root and issue these commands:

cd /var/www/html
wget http://nerdvittles.com/trixbox123/phonegenie.zip
unzip phonegenie.zip
rm -f phonegenie.zip
chown asterisk:asterisk nv-genie.php
chmod +x nv-genie.php

Once the application is in place, you need to edit the file and change the default password to something secure: nano -w nv-genie.php. On line 2 of the file, change 1234 to a numeric value that only you know! Do NOT include non-numeric characters or PHP will reset your password to zero... which isn't that secure. You shouldn't have to change anything else in the file unless you've "improved" the account name and password used to access your Asterisk Manager API in /etc/asterisk/manager.conf. This Manager password is more secure than it appears because it only works from 127.0.0.1, i.e. localhost. So, without adding another entry in this file, you could not run this application from a web server that's different than your Asterisk server.

Getting Started with Call Forwarding. Now that everything's installed and configured, it's time for a test run. For this to work, you'll need a fairly recent version of Asterisk@Home or TrixBox with AMP or freePBX since we'll be using freePBX functions. If you're going to access the Phone Genie application from inside your firewall where your Asterisk server also resides, then you'll need the internal IP address of your Asterisk server. Otherwise, you'll need to configure your firewall to forward port 80 HTTP traffic to the internal IP address of your Asterisk server. And you'll need either the external IP address of your Asterisk system or the fully-qualified domain name for your system. Next, you'll need an extension number on your Asterisk system that we can experiment with. If you want to be able to forward incoming calls back out to your cellphone, then you'll need at least two trunks. The DID trunk handles the incoming call, and a termination trunk will actually forward the inbound call back out to your cell. We'll also need the phone number of your cellphone in the same format that you would dial it on your Asterisk PBX. For example, if a prefix of 1 is required to call outside your PBX, then the number would look like this: 16782345678.

Once you have all the pieces of information, open a web browser and issue a command that looks something like this for a web browser inside your firewall. Otherwise, follow the sample above.

NOTE: All database entries are case-sensitive so be sure you use the family name exactly as it should appear in your database. FreePBX uses CF in ALL CAPS for the call forwarding family of data.

http://192.168.0.123/nv-genie.php?action=dbput&family=CF&key=200&value=6782345678&pw=1234

Substitute your own internal or external address for 192.168.0.123. To forward a call, we'll use the freePBX CF function and we'll use dbput to put the information in Asterisk's internal database. Use your real extension number instead of 200. This becomes the key in Asterisk database lingo. Substitute your properly formatted cellphone number for 6782345678. And replace 1234 with the password you stored in the nv-genie.php file. This becomes the value for the call forwarding key 200. Once you get this working either internally or externally on your cellphone, you can save your entry as a favorite in your browser and forward calls at any time with one click!

In addition to a confirmation message, you can check your work in a couple other ways. You can obviously call the extension and see if it forwards the call to your cellphone. You also can query the Asterisk database using Phone Genie. The syntax for a query is almost identical to a dbput command except you don't need to include a value. Here's what it would look like for a query from your cell phone browser:

http://asterisk.dyndns.org/nv-genie.php?action=dbget&family=CF&key=200&pw=1234

When you return to home base and want to cancel the call forwarding, you can either pick up the extension you forwarded and dial *73 or you can use Phone Genie's dbdel function. This also can be saved as a favorite so that it's one click away when you need it.

http://192.168.0.123/nv-genie.php?action=dbdel&family=CF&key=200&pw=1234

<sermon> It goes without saying, but we'll say it anyway. Don't start randomly using dbdel to delete stuff out of the Asterisk internal database or you'll find yourelf with a whirring boat anchor in a matter of minutes. Both Asterisk and FreePBX rely upon database entries to function at all. Rule #1: If in doubt, leave it alone! <end of sermon>

What Else Can Phone Genie Do? We've barely scratched the surface of what lies ahead. For a list of database entries that you can query, manipulate, and delete, open the Asterisk CLI after logging into your server as root: asterisk -rvvvvv. Now issue the following command: database show. In the listing, you'll see some entries that look like this: /CALLTRACE/502 : 500 . Call Trace is a database family that keeps track of the number that last called a particular extension. In this example, extension 502 was called by extension 500. An easy way to figure this out when you're on the road would be to issue a query using the Phone Genie:

http://asterisk.dyndns.org/nv-genie.php?action=dbget&family=CALLTRACE&key=502&pw=1234

Asterisk Database Display. There may be times when you just want to review a group of settings in your Asterisk database or even the entire database without having to start up a CLI session. The dbshow action in Phone Genie provides this functionality. In its simplest form, the command looks like the following to display your entire Asterisk database:

http://asterisk.dyndns.org/nv-genie.php?action=dbshow&pw=1234

If you'd prefer to display only a single family of entries in the database, then the syntax looks like this:

http://asterisk.dyndns.org/nv-genie.php?action=dbshow&family=CALLTRACE&pw=1234

That's about it for today. We'll leave you with a partial list of freePBX functions that can be controlled from within Phone Genie. We'll cover other things you can do with the Asterisk Manager and Phone Genie in a future article. If you're in a hurry to add some additional functions and you speak PHP, please feel free to add away. Send us your additions and we'll include them in the next version. Enjoy!

  • Call Forwarding - Enable
  • Dialcode: *72

    Phone Genie: http://192.168.0.123/nv-genie.php?action=dbput&family=CF&key=200&value=6782345678&pw=1234

  • Call Forwarding - Disable
  • Dialcode: *73

    Phone Genie: http://192.168.0.123/nv-genie.php?action=dbdel&family=CF&key=200&pw=1234

  • Call Forwarding on Busy - Enable
  • Dialcode: *90

    Phone Genie: http://192.168.0.123/nv-genie.php?action=dbput&family=CFB&key=200&value=6782345678&pw=1234

  • Call Forwarding on Busy - Disable
  • Dialcode: *91

    Phone Genie: http://192.168.0.123/nv-genie.php?action=dbdel&family=CFB&key=200&pw=1234

  • Call Forwarding Unavailable - Enable
  • Dialcode: *52

    Phone Genie: http://192.168.0.123/nv-genie.php?action=dbput&family=CFU&key=200&value=6782345678&pw=1234

  • Call Forwarding Unavailable - Disable
  • Dialcode: *53

    Phone Genie: http://192.168.0.123/nv-genie.php?action=dbdel&family=CFU&key=200&pw=1234

  • Call Tracing
  • Dialcode: *69

    Phone Genie: http://192.168.0.123/nv-genie.php?action=dbget&family=CALLTRACE&key=200&pw=1234

  • Call Waiting - Enable
  • Dialcode: *70

    Phone Genie: http://192.168.0.123/nv-genie.php?action=dbput&family=CW&key=200&value=ENABLED&pw=1234

  • Call Waiting - Disable
  • Dialcode: *71

    Phone Genie: http://192.168.0.123/nv-genie.php?action=dbdel&family=CW&key=200&pw=1234

  • Do Not Disturb - Enable
  • Dialcode: *78

    Phone Genie: http://192.168.0.123/nv-genie.php?action=dbput&family=DND&key=200&value=YES&pw=1234

  • Do Not Disturb - Disable
  • Dialcode: *79

    Phone Genie: http://192.168.0.123/nv-genie.php?action=dbdel&family=DND&key=200&pw=1234


    NOTE: The Best of Nerd Vittles tutorial on Phone Genie for Asterisk covers all updates and new features.


    Nerd Vittles Demo Hot Line (courtesy of les.net). You now can take a number of Nerd Vittles projects for a test drive... by phone! The current demos include (1) MailCall for Asterisk with password 1111 (retrieve your email by phone), (2) NewsClips for Asterisk (latest news headlines in dozens of categories), (3) Weather Forecasts by U.S. Airport Code, and (4) Weather Forecasts by U.S. ZIP Code. You're not prompted for #4 yet, but it does work! Just call our number (shown in the left margin) and take any or all of them for a spin. The sound quality may not be perfect due to performance limitations of our ancient Intel 386 demo machine. But the price is right.

    Nerd Vittles Fan Club Map. Thanks for visiting! We hope you'll take a second and add yourself to our Frappr World Map compliments of Google. In making your entry, you can choose an icon: guy, gal, nerd, or geek. For those that don't know the difference in the last two, here's the best definition we've found: "a nerd is very similar to a geek, but with more RAM and a faster modem." We're always looking for the best BBQ joints on the planet. So, if you know of one, add it to the map while you're visiting as well.


    Some Recent Nerd Vittles Articles of Interest...

    Programmer’s Corner: Asterisk Weather Station Updates

    Now that we've solved Asterisk weather forecasting for the rest of the world, wouldn't you know our U.S. weather reports would come unglued. One of the problems with depending upon the web data of other organizations (such as the National Weather Service) is that, when they shift gears, you have to make adjustments to your applications as well. So this week is cleanup time at Nerd Vittles. In its infinite wisdom, the National Weather Service decided last week to add latitude, longitude, and elevation information to all of their weather reports. This caused some wrinkles in both the Asterisk® Weather Station by Airport Code and Zip Code applications which didn't know how to interpret this new data. Personally, we were always big supporters of more federal holidays because it meant the bureaucrats and politicians had less time to screw things up. These new "improvements" are a good example of what happens when federal workers have too much time on their hands.

    All of the Nerd Vittles weather applications for Asterisk (except last week's Worldwide Weather Forecasts) depend upon NOAA web site information at a web link that looks like the following. You can enter either a zip code or a city and state.

    http://www.srh.noaa.gov/port/port_zc.php?inputstring=Charleston,SC

    Using MySQL databases, we convert telephone input of airport codes and zip codes into City and State information which then can be passed to NOAA's web link to collect the information that we use to convert the text to speech with the Flite application. If you look at one of the reports, you'll see that the main page display now looks like this:


    Charleston, SC
    Current Local Conditions at:
    Charleston Air Force Base
    Lat: 32.91 Lon: -80.03 Elev: 59.055
    Last Update: 02/20/07, 08:56 AM EST
    Fair: 48 °F

    Forecast at a Glance
    Detailed 7-day Forecast
    Your Local Radar
    Current Conditions
    Satellite Image
    Hazardous Weather
    Area Forecast Discussion

    Changes in Latitudes. So, Problem #1 is that there's a new Line 4 on the web page with the Latitude, Longitude, and Elevation information. Problem #2 is what to do with it. The two options, of course, are to discard it and leave things the way they were in the Asterisk weather reports or to convert it into intelligible text and play it with the weather report. The addition is a little puzzling quite frankly because it's static information and it really doesn't pertain to the weather other than telling you how close to the equator you are or how close to the sun you live plus or minus 93 million miles. They could just as easily have added the State Bird or State Flower but, no, we have Latitude, Longitude, and Elevation to deal with instead. The good news is that, if you ever want to build an application that computes the distance between two cities, this new information combined with searches for two cities using the NOAA link above will give you everything you need to make the calculation without having to rely upon a ZIP code database with latitude and longitude information (which we've previously given you). So we'll leave that as your homework project. With a little Googling, you can find the formula. And we'll throw in one of our PBX-in-a-Flash drives to the first person that posts a comment with working PHP code that correctly calculates the distance between two U.S. cities using NOAA website data only.

    Manually Updating the Weather Applications. We've made the management decision to throw the new data in the proverbial bit bucket, but we also want to show you how to convert the data into a usable format for the one or two folks that just can't live without it. Why are we going to such pains? Because we want to encourage others to build PHP applications for Asterisk that do something useful. And, if you walk through the Nerd Vittles code for these applications, it will give you a good idea how to get started. Looking through the code, you'll notice that we have to parse the web data to actually collect the information we need to "play" a weather report on the telephone. So, to strip out this line of text, there are a couple ways to approach it. One way would be to look for Lat: and then search for the next line break character: <br> and strip out the intervening text. We chose to actually count line breaks after the Current Local Conditions line (above) until we got to the desired string of text:

    // new code to delete Latitude, Longitude, and Elevation info from report
    $start = strpos($newvalue,"<br>") ;
    $start2 = strpos($newvalue,"<br>",$start+1) ;
    $start3 = strpos($newvalue,"<br>",$start2+1) ;
    $newvalue = substr($newvalue,0,$start2) . " " . substr($newvalue,$start3) ;
    // new code ends here

    So the new code above needs to be inserted immediately after the line that looks like this:

    $newvalue=substr($newvalue, 0, $finish);

    This change should be made in both /var/lib/asterisk/agi-bin/nv-weather.php and /var/lib/asterisk/agi-bin/nv-weather-zip.php if you happen to be using both the Weather Station by Airport Code and by Zip Code. And, not to worry, we've fixed the original downloadable code so that newbie's will never know anything changed.

    If you'd prefer to actually have the Latitude, Longitude, and Elevation information spoken to callers, then you'd obviously not include the new code above. Instead, we need to add three new parsing instructions after the following line:

    $newvalue = str_replace( "NA:", " ", $newvalue );

    Here are the new lines you'd insert to translate the NOAA abbreviations into Plain English:

    $newvalue = str_replace( "Lat:", "Latitude: ", $newvalue );
    $newvalue = str_replace( "Lon:", ". Longitude: ", $newvalue );
    $newvalue = str_replace( "Elev:", ". Elevation: ", $newvalue );

    Now that we've covered all the theory, it occurred to us that some of you might just like to download the new code. If you prefer that approach, here are the step-by-step instructions for each application. These instructions assume that you've already installed the Weather Applications previously. If not, just choose your desired installation from the Best of Nerd Vittles site.

    Installing Weather by Airport Code Update. To install the Weather by Airport Code update, log into your Asterisk server as root and issue the following commands:

    cd /var/lib/asterisk/agi-bin
    rm -f nv-weather2-zip.*
    wget http://nerdvittles.com/wp-content/nv-weather2.zip
    mv nv-weather.php nv-weather.old2.php
    unzip nv-weather2.zip
    rm -f nv-weather2.zip
    chmod 775 nv-weather.php
    chown asterisk:asterisk nv-weather.php

    Installing Weather by Zip Code Update. To install the Weather by Zip Code update, log into your Asterisk server as root and issue the following commands:

    cd /var/lib/asterisk/agi-bin
    rm -f nv-weather-zip.zip
    wget http://nerdvittles.com/trixbox123/nv-weather-zip.zip
    mv nv-weather-zip.php nv-weather-zip.old.php
    unzip nv-weather-zip.zip
    rm -f nv-weather-zip.zip
    chown asterisk:asterisk nv-weather-zip.php
    chmod 775 nv-weather-zip.php

    Test Driving the Latest Asterisk Weather Applications. To use the Asterisk Weather Station by Airport Code, pick up any phone connected to your Asterisk server and dial 611. When prompted, key in the three-character Airport Code for the weather report you wish to retrieve. Then sit back and listen to the latest weather report for your Airport Code from the National Weather Service.

    To use the Asterisk Weather Station by Zip Code, pick up any phone connected to your Asterisk server and dial Z-I-P (947). When prompted, key in the five-digit Zip Code for the weather report you wish to retrieve. Then sit back and listen to the latest weather report for your Zip Code from the National Weather Service.


    Nerd Vittles Demo Hot Line (courtesy of les.net). You now can take a number of Nerd Vittles projects for a test drive... by phone! The current demos include (1) MailCall for Asterisk with password 1111 (retrieve your email by phone), (2) NewsClips for Asterisk (latest news headlines in dozens of categories), (3) Weather Forecasts by U.S. Airport Code, and (4) Weather Forecasts by U.S. ZIP Code. You're not prompted for #4 yet, but it does work! Just call our number (shown in the left margin) and take any or all of them for a spin. The sound quality may not be perfect due to performance limitations of our ancient Intel 386 demo machine. But the price is right.

    Nerd Vittles Fan Club Map. Thanks for visiting! We hope you'll take a second and add yourself to our Frappr World Map compliments of Google. In making your entry, you can choose an icon: guy, gal, nerd, or geek. For those that don't know the difference in the last two, here's the best definition we've found: "a nerd is very similar to a geek, but with more RAM and a faster modem." We're always looking for the best BBQ joints on the planet. So, if you know of one, add it to the map while you're visiting as well.

    Click2Dial for Every(Asterisk)man… and Woman

    There have been any number of click to call applications released for Asterisk®, but none quite so simple to implement as the one we've uncovered. The original was introduced at VoIPjots.com about this time last year. Then Rafael Cortes at asteriskpbxs.com further embellished it. We took Rafael's version and added a few minor enhancements, and today you get Click2Dial for Asterisk to freely use with virtually any Asterisk PBX. It works exceptionally well with our customized versions of TrixBox 1.2.3 which you can download from the links above for Windows, Intel Macs, and Linux.

    Overview. For those new to this technology, the basic idea behind Click-to-Dial or click to call applications is that folks can visit your web site, click on a link after plugging in their phone number, and a call is placed from your Asterisk PBX connecting you and them without the visitors incurring any long distance charges. The initial call to you is placed first, and it can be to any extension on your Asterisk system or even your cellphone if you have more than one outbound (termination) trunk. If you don't answer, no second call is placed. Once you answer, the outbound call to the web site visitor is placed. We've added support in the PHP application so that callers can also enter their name, and the name entry together with the phone number to be called will be displayed on your phone before you answer the call: Web-John Doe 843-678-1234. Be aware that cellphone providers throw CallerIDName information in the bit bucket so the name display only works on calls to Asterisk extensions, but the CallerIDNumber will work with any of the providers that support adjusting your outbound CallerID, such as TelaSIP. See our Roundup of VoIP Providers for more choices. Anyway, the web site visitors get 12 characters in which to enter their name and 10 for their area code and phone number. Without much tweaking, the 10-digit limitation can be adjusted for international calling. No dialplan changes are required to get this working assuming your dialplan supports 10-digit dialing from extensions on your system. Simply drop the code into the web directory on your Asterisk server, open port 80 on your firewall to point to the web server on your Asterisk or TrixBox system, and you're off to the races. Installation and setup time: about 2 minutes.

    Click2Dial for Asterisk Installation and Setup. To download the Click2Dial for Asterisk application, click on this link. Save and unzip the archive on your Desktop. Open the Click2Dial folder and copy click2dial.php into the web folder on your Asterisk server (/var/www/html on TrixBox systems). Log into your Asterisk server as root and edit the file: nano -w /var/www/html/click2dial.php. For TrixBox systems, the only entry you need to change is the incoming call destination on line 38. For a SIP extension on your Asterisk system, the line should look like this: $strChannel = "SIP/502"; where 502 is the extension you wish to ring for incoming Click2Dial calls. If you have multiple outbound trunks and you want to route incoming web calls to your cellphone, here's the syntax:

    $strChannel = "local/1NXXNXXXXXX@from-internal" ;

    Replace 1NXXNXXXXXX with the actual phone number that you currently dial from an extension on your system to place a call to your cellphone. Save your change (Ctrl-X, Y, then Enter), and you're done! To try it out, point a web browser at the following page substituting your own fully-qualified domain name or IP address of your Asterisk server: http://192.168.0.211/click2dial.php. Feel free to cut-and-paste the code into an actual web page if you'd prefer to integrate Click2Dial for Asterisk into your existing web layout.

    Other Goodies. We've also included all of Rafael Cortes' other handiwork in the archive which you are free to use (not sell!) if you so desire. In addition, we've included our YeeHah add-on for AsteriDex. This lets you do a couple of things. First, you can use it as a Click2Dial add-on which works exactly like the code described above. Just edit the top of the file and specify your CallerID number and extension number to be called. Then move the file to your existing AsteriDex folder on your Asterisk server. While editing the file, if you set Click2Call=false, then the application lets you actually dial outbound calls to two phones of your choosing from the web page. This is handy for personal use but obviously has serious security risks unless you also uncomment the top few lines in the application and specify the actual IP addresses of the computers on which this application can be used. If you don't understand what any of this means, then do yourself and your phone bill a favor, don't use it! Otherwise, anyone with access to your AsteriDex web application can make unlimited calls on your nickel to anywhere. Enjoy!

    Nerd Reminder. Don't forget today is Valentine's Day. Give the keyboard a rest for a bit.

    Nerd Vittles Valentine's Day Giveaway. As a special thanks to our loyal readers, we have a couple of free passes to give away to the Fonality trixbox Open Communications Certification course being held on March 5-6, 2007 at the Los Angeles LAX Westin. The retail value of each pass is $1495. If you'd like to attend, post a comment to this article which begins with I WANNA GO. Just tell us why you'd like or need to go to the course. And be sure to include your real name and email address in the required fields. Email addresses do NOT get shown on the web but do give us a way to get in touch with you. Except for the winning entries, none of the other comments will actually be posted on the blog so feel free to lie your ass off beg. To be eligible, we must receive your comment before 7 a.m., Eastern time, on Thursday, February 15, 2007. We will pick two lucky winners tomorrow morning. Decision of the judges (Nerd Uno) is final. If you don't hear from us by noon (Eastern time) tomorrow, then you didn't win. Sorry. Make up a better story next time. Winners are, of course, responsible for their own transportation, lodging, food and beverage expenses. This is a perfect opportunity to get certified on the TrixBox platform at minimal expense. Offer void where prohibited by law. Good luck!


    Nerd Vittles Demo Hot Line (courtesy of les.net). You now can take a number of Nerd Vittles projects for a test drive... by phone! The current demos include (1) MailCall for Asterisk with password 1111 (retrieve your email by phone), (2) NewsClips for Asterisk (latest news headlines in dozens of categories), (3) Weather Forecasts by U.S. Airport Code, and (4) Weather Forecasts by U.S. ZIP Code. You're not prompted for #4 yet, but it does work! Just call our number (shown in the left margin) and take any or all of them for a spin. The sound quality may not be perfect due to performance limitations of our ancient Intel 386 demo machine. But the price is right.

    Nerd Vittles Fan Club Map. Thanks for visiting! We hope you'll take a second and add yourself to our Frappr World Map compliments of Google. In making your entry, you can choose an icon: guy, gal, nerd, or geek. For those that don't know the difference in the last two, here's the best definition we've found: "a nerd is very similar to a geek, but with more RAM and a faster modem." We're always looking for the best BBQ joints on the planet. So, if you know of one, add it to the map while you're visiting as well.


    Some Recent Nerd Vittles Articles of Interest...

    Weather, Weather Everywhere: Finally, Worldwide Weather Forecasts for Asterisk

    Wouldn't it be nice if you could just describe your product and folks would know what you meant? Well, thanks to the lawyers, you can't. So, for all sorts of legal reasons, today's new product will not be called the Asterisk® Weather Station: Whole Earth Edition. We're back from the bunny honeymoon, and we've finally found a source to generate Asterisk weather reports worldwide. We've now written so many weather applications for Asterisk that we're thinking of changing our name to Willard Scott. Ooops! Can't do that either. Whatever you want to call this new application, it was the #1 Request on the Nerd Vittles Wish List, and today it's soup. With all the news organizations in the world, you wouldn't think it would be so difficult to find a source for worldwide weather information, but it's been a twelve-month ordeal. For those of you that thought last week's column on the Nabaztag WiFi Rabbit was a big waste of time, think again. It was the proud owner of a Nabaztag bunny that provided the tip which led to today's worldwide weather application for Asterisk and TrixBox systems. Thanks to Channel 4 in London, the weather forecasts are freely available on the web for thousands of cities around the world. Assuming you visit their web site from time to time and take advantage of some of their "advertising opportunities," we're pretty sure they won't object to your retrieving their forecasts using a telephone from time to time. Just be sure it's for non-commercial use, and we think you're in pretty good shape with their terms of service. This is not legal advice... but you knew that.

    Update: Due to changes at Channel4.com, this application no longer works. For a current, working Worldwide Weather application for Asterisk 1.8 using the Google Talk Guru, see this article.

    Prerequisites. If you've previously installed one of the Nerd Vittles Weather Applications, then today's installation drill shouldn't take you more than 5 or 10 minutes. If you're new to all of this, then here's a quick list of what you'll need. A TrixBox 1.2.3 server for Windows, an Intel Mac, or Linux is the ideal platform because it includes all of the tools you'll need to be up and running in minutes. Almost any other Asterisk server should work so long as you've installed freePBX, PHP and the Flite voice synthesizer. But you're on your own. If you're a nuts-and-bolts Asterisk guy, then you should be able to decipher what needs to be done by reading through this tutorial. And, yes, the code could be reworked in less than six lines to support Festival or Cepstral if you'd prefer different voices for your weather reports. In fact, we use Cepstral with our Nabaztag/tag bunny, Pat the Nerd, and it works like a champ using an existing Asterisk@Home server. Our bunny tutorial will walk you through the Cepstral installation.

    Installation Overview. Assuming you have all the prerequisites in place, today's installation is about a five minute chore. You'll need to download the weather application into the agi-bin directory on your Asterisk system. Then you need to configure the 10 cities you want to support with dial-up weather forecasts. Finally, you'll drop in a little snippet of dialplan code and reload Asterisk. And, you're off to the races. If you want to retrieve weather forecasts for more than 10 cities, the easiest solution is to rework the dialplan code and the program to accept multiple digits for the city code. The number of digits is up to you. Another option is to copy the program to another filename, add another chunk of dialplan code for another extension, and expand your city count to 20, or 30, or whatever. You could even have 10 cities for each continent if that's your thing. The instructions below assume you have a TrixBox 1.2.3 system in place. It works equally well on an Asterisk@Home 1.5 system and most systems in between. If you're using an older Asterisk@Home system, just remember to put the dialplan code in extensions_custom.conf instead of extensions_trixbox.conf, and you'll be just fine.

    Installing nv-weather-world.php. Sounds like something out of a Sci-Fi movie, doesn't it. Well, it's not as hard as it sounds. Log into your TrixBox server as root and issue the following commands in order:

    cd /var/lib/asterisk/agi-bin
    wget http://nerdvittles.com/trixbox123/nv-weather-world.zip
    unzip nv-weather-world.zip
    rm -f nv-weather-world.zip
    chown asterisk:asterisk nv-weather-world.php
    chmod +x nv-weather-world.php

    Configuring Cities for Phone Access to Weather Forecasts. By default, the Worldwide Weather for Asterisk application comes preconfigured to support 10 cities around the world. Here's the list:

  • $query[0]= "http://www.channel4.com/news/weather/world_city.jsp?city=Tokyo&country=Japan&continent=Asia" ;
  • $query[1]= "http://www.channel4.com/news/weather/world_city.jsp?city=Washington&country=United+States+of+America&continent=North+America" ;
  • $query[2]= "http://www.channel4.com/news/weather/world_city.jsp?city=Berlin&country=Germany&continent=Europe" ;
  • $query[3]= "http://www.channel4.com/news/weather/world_city.jsp?city=Florence&country=Italy&continent=Europe" ;
  • $query[4]= "http://www.channel4.com/news/weather/world_city.jsp?city=Gough+Island&country=Tristan+Da+Cunha&continent=Africa" ;
  • $query[5]= "http://www.channel4.com/news/weather/uk_city.jsp?city=London" ;
  • $query[6]= "http://www.channel4.com/news/weather/world_city.jsp?city=Moscow&country=Russia&continent=Europe";
  • $query[7]= "http://www.channel4.com/news/weather/world_city.jsp?city=Sydney&country=Australia&continent=Australasia" ;
  • $query[8]= "http://www.channel4.com/news/weather/world_city.jsp?city=Toronto&country=Canada&continent=North+America" ;
  • $query[9]= "http://www.channel4.com/news/weather/world_city.jsp?city=Zurich&country=Switzerland&continent=Europe" ;

  • You'll notice that the syntax is identical for every entry except London, #5. Cities in the U.K. have a different syntax... because that's Channel 4's home base. That's why. For cities outside the U.K., the syntax is pretty straight-forward. You need a city, a country, and a continent. No spaces in any of the entries. If there's a real space in either a city or country name, then you replace the spaces with plus signs (+). How do you figure out the entries? Well, for most of them, a guess is probably good enough. Cities and countries don't switch continents that often. If you flunked geography, then you can use Channel 4's web site and call up the weather report for the city you're interested in. The answer will be in the browser's address bar.

    While you're displaying a sample weather report from Channel 4, you'll probably notice the little programming challenge that we were up against. Telephones don't (yet) display images of a weather forecast or wind direction too well. Not to worry. We solved it. The only trick was trying to figure out what all 32 weather icons meant. Your guess may be better than ours so feel free to adjust the code to your heart's content. You can make it rain on a sunny day if that's your thing.

    Now where were we? You need to make yourself a list of 10 cities with the link code to the weather reports. You'll notice that our cities happen to match the letters on the telephone except for zero and one. Once you have your city links in hand, edit nv-weather-world.php: nano -w /var/lib/asterisk/agi-bin/nv-weather-world.php. Then cursor down to line 19 and edit the ten entries with the locations you've chosen. Be very careful in editing the code! The http links need to be surrounded with quotes, and each line ends with a semi-colon. Leave everything to the left of the equals sign and the equals sign alone. If you decide to add more than 10, just follow the examples and keep numbering. Before you add any additional lines, scroll down to line 148 and change strlen($code)>1 to the maximum number of digits you plan to use. Save your changes when you're finished: Ctrl-X, Y, then Enter.

    Adding the Dialplan Code Snippet. In order to activate extension 612 to answer calls for your Worldwide Weather Forecasts, you'll need to drop the following code into your dialplan in the [from-internal-trixbox] context of /etc/asterisk/extensions_trixbox.conf. The easiest way is to access TrixBox from your browser and choose System Administration, Config Edit. Then click on the extensions_trixbox.conf file in the left column, scroll down into the [from-internal-trixbox] context and cut-and-paste the following. If you've decided to support more than 10 cities at a time, then you'll need to change the one in line 6 to a bigger number. Once you get it the way you like it, click the Update button to save your changes.

    exten => 612,1,Answer
    exten => 612,2,Wait(1)
    exten => 612,3,DigitTimeout(7)
    exten => 612,4,ResponseTimeout(10)
    exten => 612,5,Flite("At the beep enter the code for the weather report you wish to retrieve.")
    exten => 612,6,Read(APCODE,beep,1)
    exten => 612,7,Flite("Please hold a moment while we retrieve your report.")
    exten => 612,8,AGI(nv-weather-world.php|${APCODE})
    exten => 612,9,NoOp(Wave file: ${TMPWAVE})
    exten => 612,10,Playback(${TMPWAVE})
    exten => 612,11,Hangup

    Adding a Miscellaneous Destination. While you're still in TrixBox with your browser, choose freePBX and then choose Setup, Misc Destination. Add a new entry for WorldWideWeather with 612 as the Dial entry. Save your entry and then click the Red Bar to reload Asterisk.

    Taking the WorldWide Weather Forecaster for a Spin. Now we should be all set. Just pick up an extension on your system and dial 612. You'll be prompted to enter a one-digit code. Punch in 5 and check out the weather forecast for good old London. Enjoy!

    Housekeeping 101. Temporary files in /tmp get cleaned up by Linux housekeeping automatically. Temporary files stored elsewhere don't unless you're using a Nerd Vittles build of TrixBox with either the VMware edition of nv-trixbox for Windows, an Intel Mac, or PBX-in-a-Flash for Linux. The weather scripts store .wav files with your requested weather forecasts in /var/lib/asterisk/sounds/tts. So, from time to time, make a mental note to remove all of these files with a command like this:

    rm -f /var/lib/asterisk/sounds/tts/*

    Or just log into your Asterisk server as root and edit the following file: nano -w /etc/crontab. Move to the bottom of the file and insert the following code on a blank line:

    3 0 * * * /usr/bin/find /var/lib/asterisk/sounds/tts -type f -mtime +14 | /usr/bin/xargs /bin/rm -f >/dev/null 2>&1

    This code will delete all of the files in the tts folder every two weeks. If you'd prefer a shorter time, change the number 14 accordingly. Now save your changes: Ctrl-X, Y, then Enter.

    Best of Nerd Vittles Link. This application also is now available on our Best of Nerd Vittles site.


    Hosting Provider Special. Just an FYI that the Nerd Vittles hosting provider, BlueHost, has raised the bar again on hosting services. For $6.95 a month, you can host up to 6 domains with 200 gigs of disk storage and 2000 gigs (that's 2 terabytes!) of monthly bandwidth. Free domain registration is included for as long as you have an account. That almost doubles last month's deal, and it still doesn't get any better than that. Their hosting services are flawless! We oughta know. We've tried the best of them. If you haven't tried a web hosting provider, there's never been a better time. Just use our link. You get a terrific hosting service, and we get a little lunch money.

    Want More Projects? For a complete catalog of all our previous Asterisk projects, click here. For the most recent articles, click here and just scroll down the page.


    Some Recent Nerd Vittles Articles of Interest...