Home » Technology » Worldwide Weather Forecasts with Asterisk and Google Talk

The Most Versatile VoIP Provider: FREE PORTING

Worldwide Weather Forecasts with Asterisk and Google Talk

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. Nor will it be called the Google® Weather Station even though we'll be using Google Lab's new Google Talk Guru. 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. And, yes, we used to have a Worldwide Weather application for Asterisk, but it died when Channel4.com discontinued providing weather data. The good news is that this forced us to take a look at Google's new Google Talk Guru which is nothing short of incredible. Weather reports are just the tip of the iceberg. We'll have an app to retrieve your favorite sports scores soon. To retrieve the latest Atlanta Braves info, just issue the Chat command: score braves. Here's the answer:

Baseball:
Atlanta Braves 2 - Milwaukee Brewers 1
Next game: @ Milwaukee Brewers, 6 Apr 3:10am
mlb.mlb.com

To give you some idea of performance, retrieval of a weather forecast using the Google Talk Guru takes less than a second for almost any location in the world. In addition to playing these forecasts over the phone using Asterisk 1.8, we've also added the ability to retrieve a forecast by phone and forward it on to your email address. Here's the result from weather paris:

Weather:
Paris, France
13°C, Clear
Wind: W 8 km/h
Hum: 53%
Mon: 6°C-14°C, Partly Cloudy
Tue: 7°C-18°C, Partly Cloudy
Wed: 8°C-23°C, Partly Cloudy

HINT: If you prefer zip codes or international postal codes, those all seem to return good results as well. We've tested U.S., Canada, and U.K. codes with no problems. Mexico, unfortunately, uses 5-digit codes just like the U.S. so those don't work. Now if we could just get rid of centigrade and kilometers for the metrically challenged, it would be almost perfect.

How It Works. Here's a quick summary of how all this works. With the Google Talk Guru, you can send a query as a text message to guru@googlelabs.com. You then get a reply message in Google Talk with the answer to your query. What we've done is add this querying functionality to your Asterisk dialplan with some preassigned cities to obtain weather forecasts. You can change them in any way you like. Once the response arrives, we've got a PHP application that puts the text (as shown above) into something that's a little more TTS friendly for Flite and Cepstral. Finally, we've added the option to email you the results as well as speaking them over the phone. If you're curious about how to do all of this, take a look at the dialplan and PHP code in the links below. It's not hard, but it is tedious. One little typo and nothing works. Ask us how we know. 😉

Prerequisites. If you've previously installed one of the Nerd Vittles Weather Applications or if you're using an older version of Incredible PBX 1.8 that doesn't include this app out of the box, 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. First, you'll need a PBX in a Flash server running the very latest Asterisk 1.8. We call it PIAF-Purple. Bidirectional Google chatting only works in the most recent releases of Asterisk 1.8 so, no, you can't wing it with an earlier release and expect a working system. Next you'll need to add Google Voice and Chat support. You can install these components yourself, or you can use Incredible PBX 1.8. The latest release as of today has this application preinstalled. If you dial 612 from an extension on your Incredible PBX and are prompted to choose a city for your weather report after hearing a list of cities, then your installation is complete even though it won't work until you invite yourself to chat with guru@googlelabs.com using the same Gmail account you're using for Google Voice on your Asterisk server. If dialing 612 doesn't work or merely prompts for a number, you'll need to add this application to your existing Incredible PBX 1.8 installation by following the simple steps below in addition to enabling chats with guru@googlelabs.com. Almost any other (current) Asterisk 1.8 server should work as well so long as you've installed FreePBX, PHP and the Flite or Cepstral voice synthesizer. But then 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.

Quick Installation. Assuming you have all the prerequisites in place, today's installation is about a five minute chore. There are 3 easy steps:

(1) While signed in to Gmail with the same account credentials being used for Google Voice on your Asterisk server, activate chat temporarily and invite yourself to chat with guru@googlelabs.com. Run a test query using one of the examples above. IMPORTANT: Once it works, disable chat on your desktop, or Google Voice and Chat will no longer work with Asterisk!

(2) Download the Google Worldwide Weather application into the agi-bin directory on your Asterisk system. Here are the commands after logging into your server as root:

cd /var/lib/asterisk/agi-bin
wget http://nerd.bz/fCcdOP
tar zxvf nv-weather-google.tgz

(3) While still logged in as root, switch to the /etc/asterisk directory and edit extensions_custom.conf with this command:

nano -w extensions_custom.conf

Search for 612 and delete any existing lines with that extension. Then cut-and-paste the following code inserting it below the [from-internal-custom] context marker (but above any other context marker) or in the existing position if you deleted existing 612 lines. Use nano -w extensions_custom.conf to open the file, or word wrap will delete part of the cut-and-paste code! Once you've saved your changes, reload your Asterisk dialplan:

asterisk -rx "dialplan reload"

Customization. By default, the application is set to use Flite as the text-to-speech (TTS) engine. If you have installed Cepstral, you can change the app to Cepstral quickly. In the /var/lib/asterisk/agi-bin directory, edit nv-weather-google.php and change $ttspick = 0 to $ttspick = 1. Do not delete the trailing semicolon! If you want the weather reports also emailed to you when you dial them up, then insert your actual email address in the $email variable and set $emailforecast = 1.

Worldwide Weather Forecasts for Asterisk is preconfigured for the following cities:

0 - Tokyo
1 - Washington
2 - Berlin
3 - Paris
4 - Honolulu
5 - London
6 - Moscow
7 - Sydney
8 - Toronto
9 - Zurich

You need not use the 10 cities that are preconfigured in the application. You can choose your own. First, write down the names of the 10 cities you wish to use. Do NOT add states or countries! Make a backup of extensions_custom.conf: cp extensions_custom.conf ext_custom.bak. Then carefully edit /etc/asterisk/extensions_custom.conf using nano -w filename. Move down to the 612,3 and 612,5 lines and make the necessary changes using the city names you have chosen. Finally, move down to 612,50 and replace Tokyo with your 0 choice, 612,52 with your 1 choice, etc. Save your changes and reload your dialplan. NOTE: For multi-word cities such as New York and San Diego, be sure to use an underscore between the words, NOT A SPACE, e.g. new_york.

If you want to retrieve weather forecasts for more than 10 cities, the easiest solution is to clone all of the 612 dialplan code and renumber each occurrence of 612 to 613. HINT: Some 612 entries are actually embedded in the code as well as in the extension numbers. Be sure to renumber those entries as well. Use Ctrl-W to find each 612 occurrence in the new context, and you won't inadvertently miss one. That gets you 10 more cities. Repeat as desired. Note also that you need not announce 10 cities in the voice prompt unless you want to. If you only plan to use 3 cities, then alter the initial voice prompt to only announce those cities. You do NOT need to delete the dialplan code that actually picks other cities.

Adding a Miscellaneous Destination. Access FreePBX with your browser, and choose Setup, Misc Destination. If it's not already there, 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 Incredible PBX. 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/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:

01 0 * * * root rm -f /var/lib/asterisk/sounds/tts/tts* > /dev/null

This code will delete all of the TTS files in the tts folder every night. Now save your changes: Ctrl-X, Y, then Enter.

Best of Nerd Vittles Link. This application also will be available on our Best of Nerd Vittles site shortly. Enjoy!

Originally published: Tuesday, April 5, 2011


Need help with Asterisk? Visit the PBX in a Flash Forum or Wiki.
Or Try the New, Free PBX in a Flash Conference Bridge.



whos.amung.us If you're wondering what your fellow man is reading on Nerd Vittles these days, wonder no more. Visit our new whos.amung.us statistical web site and check out what's happening. It's a terrific resource both for us and for you.


 

Special Thanks to Our Generous Sponsors


FULL DISCLOSURE: ClearlyIP, Skyetel, Vitelity, DigitalOcean, Vultr, VoIP.ms, 3CX, Sangoma, TelecomsXchange and VitalPBX have provided financial support to Nerd Vittles and our open source projects through advertising, referral revenue, and/or merchandise. As an Amazon Associate and Best Buy Affiliate, we also earn from qualifying purchases. We’ve chosen these providers not the other way around. Our decisions are based upon their corporate reputation and the quality of their offerings and pricing. Our recommendations regarding technology are reached without regard to financial compensation except in situations in which comparable products at comparable pricing are available from multiple sources. In this limited case, we support our sponsors because our sponsors support us.

BOGO Bonaza: Enjoy state-of-the-art VoIP service with a $10 credit and half-price SIP service on up to $500 of Skyetel trunking with free number porting when you fund your Skyetel account. No limits on number of simultaneous calls. Quadruple data center redundancy. $25 monthly minimum spend required. Tutorial and sign up details are here.

The lynchpin of Incredible PBX 2020 and beyond is ClearlyIP components which bring management of FreePBX modules and SIP phone integration to a level never before available with any other Asterisk distribution. And now you can configure and reconfigure your new Incredible PBX phones from the convenience of the Incredible PBX GUI.

VitalPBX is perhaps the fastest-growing PBX offering based upon Asterisk with an installed presence in more than 100 countries worldwide. VitalPBX has generously provided a customized White Label version of Incredible PBX tailored for use with all Incredible PBX and VitalPBX custom applications. Follow this link for a free test drive!
 

Special Thanks to Vitelity. Vitelity is now Voyant Communications and has halted new registrations for the time being. Our special thanks to Vitelity for their unwavering financial support over many years and to the many Nerd Vittles readers who continue to enjoy the benefits of their service offerings. We will keep everyone posted on further developments.
 


Some Recent Nerd Vittles Articles of Interest...


1 Comment

  1. Could you please explain what you mean by "disable chat on your desktop, or Google Voice and Chat will no longer work"?

    Is this for anyone who have downloaded chat to the computer desktop or is it by remove the enable outbound/inbound in gmail settings?

    Please advise.

    [WM: You can’t have chat running inside GMail and also use the same Gmail account on your Asterisk server, or inbound calls to your Google number won’t ring inside Asterisk. You can disable Chat in Gmail by clicking on the Down Arrow to the right of the word "Chat" which exposes the chat options window. Then choose "Sign out of Chat."]

Comments are closed.