Tuesday, December 18, 2018

Packet Radio - BBS generate Automatic Bulletin

Packet radio is fun and all but if you want to be serious about generating useful bulletins it is rather a chore to type them up.  What is required is a way to post an automatically generated bulletin from a text file source.  Sounds easy right?  It actually is.  This is designed around a Linux operating system, and some pre-requisite software is required.
BPQ32, expect, and telnet
Install these packages on your Linux computer like you normally would.  In this example I will show how to use any text file that you might generate, and post it as a BBS Bulletin.

Let's start with a text file.  It can be any text file, the internet of things and a home automation system allow us to capture data around us and put it in a text file reporting values for a day.

The Telnet access to BPQ32 (or linbpq) in this case must be set up correctly.  This will give us command line access to the packet BBS, and therefore the world if we want.  The expect command in Linux is clever.  It expects some output from stdout and replies with a response on stdin.  It will just be like typing the information into the command line yourself, only the .exp script will do it for you.  The text file is read in and translated into binary, this is key otherwise the file will not maintain the formatting it originally had.  No one likes long lines on a BBS system.  Keep it to less than 80 characters across when you generate your text file.  Then the expect command can spawn a telnet connection and step through logging into your BBS to send a bulletin.  You might want to just verify your login prompts on your own BBS.  They may differ, change any text in quotes after the expect command to match your system.  Finally the bulletin text can be inserted and the expect script can just log itself out of the telnet connection.

You will notice a \r at the end of some of the commands.  This is a carriage return, just like hitting enter on the keyboard.  Without it the command won't hit enter and won't go to the next step, so don't forget them.

In your home directory (in this case I'm running this on a Raspberry Pi), so the /home/pi directory I've made a folder called BBSScript.  My telnet host actually runs on a non-standard port 8010, so you'll have to change that and any other text in bold to suit your needs.  My standard outgoing message file is msgout.txt, and in the example it is being sent to SUBJECT@WW.  You can categorize your bulletin however you like.  Save the file as sendbulletin.exp and make it executable with a chmod u+x command.
#!/usr/bin/expect
set timeout 20
set msgfile [open "/home/pi/BBSScript/msgout.txt" r]
fconfigure $msgfile -translation binary
set msgout [read $msgfile]
close $msgfile
spawn telnet localhost 8010
expect "user:" { send "MYCALLSIGN\r" }
expect "password:" { send "MYPASSWORD\r" }
expect "MYALIAS:MYCALLSIGN} Nodes" { send "bbs\r" }
expect "BBS>" { send "sb SUBJECT@WW\r" }
expect "Enter Title (only):" { send "BULLETIN SUBJECT\r" }
expect "Enter Message Text (end with /ex or ctrl/z)" { send "$msgout\r" }
expect "EOF" { send "/ex\r" }
expect "BBS (Expert)>" { send "b\r" }
That's the extent of it.  It is really that easy.  Have another shell script overwrite your msgout.txt file daily, weekly, or any time via a crontab job.  Then call this exp script for automatic bulletin generation.  You can even call this script from inside your other script.

The last post I made about the weather report on AllStarLink can be modified to gather your weather from the internet and generate the msgout.txt file.  Think up your own clever bulletin topic.



73 and good DX
de N3FIX

Sunday, December 16, 2018

HamVOIP AllStarLink node weather script

I wrote this script early in the year, and it works rather well.
The script uses the national weather service to get a text transcription of the weather forecast.
It re-formats the text taking out the header and footer.
It then uses a text to speech translator to create a .ul file which can be read over the air by Asterisk.
(the Linux computer must have tts_audio installed)
Another crontab deletes the .ul file at midnight.

This is implemented on a hamvoip node on a Raspberry Pi.
It can be triggered by DTMF tones or on a time schedule.

The script is written below

73

N3FIX

----------------------------------------------
# script written by N3FIX
# date 2018-JAN-13
# this script downloads the weather forecast
# strips the header and footer
# converts it from a txt file to a .ul file
# and plays the .ul file on the air.
# play the forecast at 8:00 am and edit the crontab
# crontab -e
# 00 8 * * * /etc/asterisk/local/Forecast.sh

# use the lynx dump command to get the current weather forecast
# determine zone from alerts.weather.gov
# zone is PAZ065
lynx --dump "http://forecast.weather.gov/MapClick.php?zoneid=PAZ065&FcstType=text&TextType=2" > Forecast.txt

# take the header out by removing lines 2 through 4.
sed '2,4d' /etc/asterisk/local/Forecast.txt > /etc/asterisk/local/Forecast1.txt

# take the footer out by listing the file backwards with tac and taking out lines 1 to 10.
tac /etc/asterisk/local/Forecast1.txt | sed '1,10d' | tac > /etc/asterisk/local/Forecast.txt

# remove all the underscores from the file
sed 's/_//g' /etc/asterisk/local/Forecast.txt > /etc/asterisk/local/Forecast1.txt

# tts_audio doesn't say winds correctly. Make her say "wend" instead.
sed 's/winds/wend/g' /etc/asterisk/local/Forecast1.txt > /etc/asterisk/local/Forecast.txt

# convert the file to a ul file using tts_audio.sh
tts_audio.sh /etc/asterisk/local/Forecast.txt

# play the resulting file on the air by calling asterisk
# for 46891 ... insert your own node number
asterisk -rx "rpt localplay 46891 /etc/asterisk/local/Forecast"

# remove the temporary files after debugging
rm /etc/asterisk/local/Forecast1.txt
rm /etc/asterisk/local/Forecast.txt
------------------------------------------------