Weather Forecast

The current FreePBX2.3.0.3, the weather forecasting is not working (*61).

I remember reading some comments that weather forecasting service was discontinued by the National Weather Service.

Just to confirm the status. Any updates on National Weather Service to restore the service for Asterisk?

FreePBX does not provide the common weather forcecast feature code that many have used. If I’m not mistaken I thought Nerd Vittles had put that together. Last I talked to Ward he was slowly working towards getting it into a proper module format (in his spare time like the rest of us…) so eventually it may show up.

Philippe Lindheimer - FreePBX Project Lead
http// - IRC #freepbx

The NWS changed some server paths around. So the text products are in different places.

They are also formated differently. So how the original script parses the text needs to be changed a bit. Google “asterisk weather” there are a lot of alternative ideas and other work arounds.

It would be nice to see it as a module…

One reason I think that the weather forecast module never took off is because it was, IMHO, never properly coded. Never mind that it used the crappy festival or flite synthesized voices, which was bad enough, but it also paused in unnatural places due to its inability to skip over line breaks in the original forecast. To me, it was always painful to listen to - I could never actually understand what was being said because I was so hung up on how bad it sounded, particularly the seemingly random pauses that were caused because it treated a new line as if it were a period or other indication that it should pause.

The one I have liked the best used the Cepstral voices, which are not free, but sound 1000% better than any of the free synthesized voices. But even if you don’t want to use the Cepstral voices, the routine could easily be modified to use the flite or festival synthesizer, and it does eliminate the unnatural pauses. You can find that code at …
(THE ABOVE IS ONE LINE, this forum mangles lines that are too long so you’ll have to join them)

… but don’t use the first weather.agi on the page (and don’t follow the link to the Trixbox forum), instead skip about halfway down the page to where it says “Alternative change (Not by the original poster:).”

One thing that has changed recently is that you can now buy an “Allison” voice from Cepstral to give your system a fairly uniform voice. One bad thing about the Cepstral voices is that there are occasional words they just don’t get right, but fortunately you can usually do a phonetic substitution to tweak that problem for commonly-used words (you can use the same technique to change odd references to local landmarks, for example if the NWS insists on using “highway 75” when everyone knows it as “Interstate 75” you can make that substitution). The code gives examples, for example the Cepstral voice couldn’t say “daybreak” properly so the code author substituted “day brake.”

Having said that, bear in mind that if you live near a major city you may be able to simply download and play an AccuWeather forecast (I don’t know about the legality of this if you do it in a commercial environment, so you may want to check with AccuWeather if you have any questions about that). A list of cities for which podcasts are available can be found here:

Let’s say you want a forecast for the Twin Cities of Minneapolis/St. Paul (just as an example, you could add something like this as a Dialplan Injection or in extensions_custom.conf (this is how it appears as a Dialplan Injection, using Naftali5’s module):

GotoIf($[“x${IVR_CONTEXT}” = “x”]?app-blackhole,hangup,1:${IVR_CONTEXT},return,1)

The last line means that if you called the forecast directly it should hang up afterwards, but if you goth here via an IVR it should return to the IVR and let you make another selection. Anyway, here’s what mspweather.agi looks like - note that for it to work you must have all of the Perl modules called by the script installed (Asterisk::AGI is probably already installed, but XML::Simple and/or LWP::Simple may not be, so you may have to install whatever is missing), and you must have have lame installed in /usr/bin/lame (change the path in the script if lame is somewhere else on your system):


use XML::Simple;
use Asterisk::AGI;
use LWP::Simple;

$AGI = new Asterisk::AGI;
$xml = new XML::Simple;
$noext = "/tmp/mspweather";
$resampled = $noext . ".mp3";

$AGI->verbose("Getting XML file\n",1);
$data = $xml->XMLin(get(""));
$url = $data->{channel}->{item}->{enclosure}->{url};
$AGI->verbose("Extracted URL $url from XML file",1);
$url =~ m#(?:.*/)(.*)$#;
$podcast = "/tmp/" . $1;
if (-s $podcast)
  $AGI->verbose("$podcast already exists - skipping download\n",1);
  system ('rm /tmp/MSP*.mp3');
  $AGI->verbose("Getting $url\n",1);
  getstore("$url", "$podcast") or die "Could not retrieve podcast";
  $AGI->verbose("$podcast retrived\n",1);
  system("/usr/bin/lame --silent --mp3input --scale 20 --abr 32 -m m -h $podcast $resampled")==0 or die "Could not convert file";
  $AGI->verbose("$pd converted to $resampled\n",1);
# $podcast =~ s/\.\w*$//;

A couple notes on the above: The system call to lame is to change the volume so it’s at a comfortable listening level. And the use of ControlPlayback lets you skip through the forecast (or back up) if you like.

The AccuWeather forecasts are free to download and sound a lot better than anything you can generate locally, but since Accuweather is a commercial product I’d only use them on a home or noncommercial system, and not expose them to outside callers. To avoid copyright issues and still have a reasonably good sounding forecast, I’d go with the Cepstral voices and the NWS forecasts.

[Rant about the forum software removed - the issues I was having back then have mostly been fixed.]

there is an issue with long long URL’s being cut off that we need to isolate and address. In the mean time I took the liberty of putting BBCode style url encoding around it. I also took the liberty of putting a code block around your script. I have not modified anything at all beyond that. If you prefer you can choose the ‘Filtered HTML’ format for your posts and use a limited set of html tags.

Philippe Lindheimer - FreePBX Project Lead
http// - IRC #freepbx

Thanks for cleaning up the post. However the real problem is that if you see an error and try to edit it, the text that appears in the edit box is devoid of all formatting. Even the paragraphs are run together.
This is a second paragraph. Just as an example, after posting this post, I’m going to edit it and then re-save it without changing anything. If it does what it did before, the paragraphs will be run together and/or you will see the HTML code displayed.
This is the third paragraph. The point is, in order to simply post and then make a correction (fix a spelling error, for example) I shouldn’t have to play with filters or such things. I’ve never run across any other forum software that requires that. Sometimes a programmer will say “the software is buggy, but the users can work around it” instead of fixing the bugs. But there are thousands of forums on the Internet and while I haven’t used all of them, I can’t honestly recall if or when I’ve seen another that mangles plain text posts if you simply attempt to do a minor edit.
This is the fourth paragraph. Also, note what happens if you post single lines (as in program code segments):
Sample Line 1
Sample Line 2
Sample Line 3
Sample Line 4
This is the fifth paragraph. (not counting the sample lines). This entire message is plain text. Let’s see what happens when I save it and then try and edit it (with my luck nothing will happen now that I’m trying to demonstrate the problem, but we will see.


I didn’t change a thing, just clicked edit and then posted it again. The only thing that happened this time was it removed the double spaces between paragraphs. Even that shouldn’t happen, but it’s not nearly as bad as what it did before. Did you maybe fix something?

I have not changed a thing. I also know that there are some issues that I want to resolve. I am not defending the system, I have my own pains as well (try creating some of the formatted articles I put together and you will understand). However we have this system and it is not going to go away, but it can be changed and fixed so things are not that much of an issue.

For starters, what are you using to do your posts? Are you using the TinyMCE wisywig editor which can sometimes be a real problem? Or are you typing in either straight text/bbcode or straight text/html?

Philippe Lindheimer - FreePBX Project Lead
http// - IRC #freepbx

I’m typing plain text into the comment box on the page. Of course, when I pasted the code in earlier, that was a cut-and-paste but it was from a plain text editor, not a word processing program.

As I say, the real problem is when I go to edit text after posting. And the strange thing about that is that THEN it seems to bring up a totally different editor, not the same type of plain text-entry box that I’m typing into now. And stranger still, when it first loads the text to be edited, for about maybe half a second it looks normal (I can see the paragraph breaks) and then it suddenly changes, the text gets smaller and the paragraph breaks disappear - it’s like it’s changing from plain text editing to word-processing style editing, or something like that. But this is something that the site is doing, perhaps using a script or something.

I’m sorry that you can’t replace this system with something a bit less troublesome. If we’re all having problems with it, is it really worth fighting with it? Anyway, I do hope the issues can be resolved.

Edit: Just as an experiment, I used NoScript to deny freepbx,org the ability to run scripts, and guess what? Now when I click on edit, I get the plain text edit box and it does not change (I still see the larger text and the paragraph breaks). So I’m going to try saving this now and if you still see the paragraph breaks, then it’s something that a script is doing!

Well, I thought maybe I could paste an image here to show the difference in the two editors, but I can’t find a way to do that without uploading an image to another site and then linking to it.  Anyway, try creating a message and then editing it - try to edit with javascript enabled and then with it disabled and you will see that there is quite a difference in the editor that is presented.  One interesting thing is that in the javascript editor, the cut/copy/paste buttons do not work in both Firefox and Opera.

I’ll try to have a closer look to see what might be happening wrt to the editor and formatting. On simple posts in the Forum and what not, I don’t seem to have an issue. When I write more involved articles with diagrams and pictures that is when it gets a little tedious (where wordpress was definitely more friendly - although it had its issues as well).

Philippe Lindheimer - FreePBX Project Lead
http// - IRC #freepbx

Tried your script and received the following error running AGI debug:

-- Executing [[email protected]:1] Answer("SIP/6331-090be1e0", "") in new stack
-- Executing [[email protected]:2] Wait("SIP/6331-090be1e0", "1") in new stack
-- Executing [[email protected]:3] AGI("SIP/6331-090be1e0", "NewWeather.agi") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/NewWeather.agi

AGI Tx >> agi_request: mspweather.agi
AGI Tx >> agi_channel: SIP/6331-090be1e0
AGI Tx >> agi_language: en
AGI Tx >> agi_type: SIP
AGI Tx >> agi_uniqueid: 1198962042.23
AGI Tx >> agi_callerid: 6331
AGI Tx >> agi_calleridname: device
AGI Tx >> agi_callingpres: 0
AGI Tx >> agi_callingani2: 0
AGI Tx >> agi_callington: 0
AGI Tx >> agi_callingtns: 0
AGI Tx >> agi_dnid: 612
AGI Tx >> agi_rdnis: unknown
AGI Tx >> agi_context: from-internal
AGI Tx >> agi_extension: 612
AGI Tx >> agi_priority: 3
AGI Tx >> agi_enhanced: 0.0
AGI Tx >> agi_accountcode:
AGI Tx >>
AGI Rx << VERBOSE "Getting XML file
mspweather.agi: Getting XML file
AGI Tx >> 200 result=1
AGI Rx << " 1I>
AGI Tx >> 510 Invalid or unknown command
– AGI Script NewWeather.agi completed, returning 0
– Executing [[email protected]:4] Playback(“SIP/6331-090be1e0”, “silence/1&cannot-complete-as-dialed&check-number-dial-again|noanswer”) in new stack
– <SIP/6331-090be1e0> Playing ‘silence/1’ (language ‘en’)
– <SIP/6331-090be1e0> Playing ‘cannot-complete-as-dialed’ (language ‘en’)

My script in extensions.conf:

exten => 612,1,Answer
exten => 612,2,Wait(1)
exten => 612,3,AGI(mspweathet.agi)
exten => 612,4,hangup