Worldwide Weather Forecasts for Asterisk

Featuring London's Channel 4 Weather Forecasts

The Worldwide Weather Forecasts for Asterisk application lets you to retrieve current five-day weather forecasts from London's Channel 4 web site for thousands of cities around the globe. Just pick up any touchtone phone connected to your Asterisk PBX, and you can retrieve for personal, non-business use current weather forecasts for most major cities worldwide at the touch of a button.

Prerequisites

For the Worldwide Weather Forecasts for Asterisk application to work, you'll need an Internet connection to your Asterisk server so that your server can access Channel 4's weather forecasts. We recommend either a TrixBox Asterisk server or an Asterisk@Home 2.x server and the new Flite voice synthesizer for Asterisk. Instead of a dedicated Asterisk server, you also could use our VMware version of TrixBox if you just want to experiment a bit. It runs in a window on your Windows XP/2000 desktop. There's also a version for Intel Macs. If it's not already part of your Asterisk system, our Flite tutorial and the Flite application software are available here. This tutorial assumes you are using a TrixBox server which already includes Flite.

Asterisk Server Download

[zip] Worldwide Weather Forecasts for Asterisk (4KB)

Dialplan Setup

Your Asterisk Dialplan needs to be modified to support the Worldwide Weather Forecasts for Asterisk application. If you're running TrixBox, point your web browser at your Asterisk server again. Then choose System Administration->Config Edit and choose extensions_trixbox.conf from the file listing. When the file opens, scroll down to the [from-internal-trixbox] context. Cut-and-paste the following code into the file. Then 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

NOTE: If you're running this application on an Asterisk 1.4.x server, replace lines 3 and 4 above with the following:

exten => 612,3,Set(TIMEOUT(digit)=7)
exten => 612,4,Set(TIMEOUT(response)=10)

freePBX Setup

While still connected to your TrixBox server with your browser, choose freePBX and then choose Setup, Misc Destination. Add a new entry for WorldWideWeather with 612 as the Dial entry.

 Add Misc Destination
description:
dial:   

Save your entry and then click the Red Bar to reload your Asterisk dialplan settings.

AGI Script Setup

Log into your Asterisk system as root. We need to copy the Weather PHP script to the AGI directory:

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 the Worldwide Weather Forecasts for Asterisk Script

By default, the Worldwide Weather Forecasts 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" ;
  • Make a list of 10 cities around the world that should be included in your implementation of the Worldwide Weather application. The syntax is identical for every entry except U.K. cities (see London, #5 above). For cities outside the U.K., the syntax is straight-forward. Identify the city, country, and continent. No spaces in any of the entries. If there's a real space in either a city or country name, then replace the spaces with plus signs (+). Use Channel 4's web site to call up the weather reports for the cities of interest. The correct entry for each city will be displayed in the browser's address bar. Once you have your 10 city links in hand, log into your Asterisk server as root and edit nv-weather-world.php: nano -w /var/lib/asterisk/agi-bin/nv-weather-world.php. 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. Save your changes when you're finished: Ctrl-X, Y, then Enter. Then restart Asterisk: amportal restart.

    System Setup

    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, or Intel Macs, 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, these temporary files need to be cleaned out. The easiest way is to add a crontab entry which automatically deletes the file. Log into your Asterisk server as root and issue the following command: 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.

    Using Worldwide Weather Forecasts for Asterisk

    To use the Worldwide Weather Forecasts for Asterisk application, pick up any phone connected to your Asterisk server and dial 612. When prompted, key in the one-digit code for the weather forecast you wish to retrieve. Then sit back and listen to the latest weather report courtesy of Channel 4 in London.

    Nerd Vittles Original Article (2/7/2007): Weather, Weather Everywhere: Finally, Worldwide Weather Forecasts for Asterisk