[ASTERISK] Weather Service

Following my talking clock service from [ here ], let’s go further and create a Weather service you can access when dialing 959!

Same, we’ll use an Ubuntu 26.04 VM on ARM.

Let’s install the required software on Ubuntu:

apt update
apt install -y asterisk curl jq sox libttspico-utils

Then you will need an OpenWeatherMap API key that you can get from: https://openweathermap.org/api

So now, let’s create our Weather Script:

nano /usr/local/bin/weather-chiajna.sh

that should contain:

Make it executable: chmod +x /usr/local/bin/weather-chiajna.sh

I won’t go to the creation of extensions and dialplans, since this was covered in my old post.

Here’s a sample final dialplan:

[from-yeastar]

exten => 959,1,NoOp(Weather service loop)
same => n,Answer()

; Generate initial weather prompt
same => n,System(/usr/local/bin/weather-chiajna.sh)

; Initialize counter
same => n,Set(COUNT=0)

; Playback loop
same => n(loop),Playback(/var/lib/asterisk/sounds/en/weather)
same => n,Wait(5)

; Increase counter
same => n,Set(COUNT=$[${COUNT} + 1])

; Refresh weather every 60 loops (~5 minutes)
same => n,GotoIf($[${COUNT} < 60]?loop)

; Reset counter and refresh weather
same => n,Set(COUNT=0)
same => n,System(/usr/local/bin/weather-chiajna.sh)

; Continue looping
same => n,Goto(loop)

 

Enjoy!

 

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.