Skip to content

How to create a custom NDB

Benedikt Hallinger edited this page Jun 8, 2021 · 1 revision

This article will show you a small script to easily create your custom NDB with morse code replay :)

Prerequisites

Build the morsecode

We basicly use the python script to generate a morse code in wav form. Using ffmpeg we convert that to an ogg file. At the end, we just feed the ogg to the playback bot :)

Let's spawn an NDB with code ESBC located at the nepal everest base camp, dih-dah'ing at 314kHz:
beni@fgcom:~/fgcom-mumble/server$ ./makeNDB.sh ESBC --frq=0.314 --lat=28.007222 --lon=86.859444

Helper script

#!/bin/bash
#
# A small wrapper for FGCom-mumble to spawn a playback bot as NDB
#
# Call this in the location where the playback bot lives (ie in fgcom-mumble/server/)
#
# Usage:   `makeNDB.sh <ID> <--bot-options>`
# Example: `makeNDB.sh ESBC --frq=0.314 --lat=28.007222 --lon=86.859444`  # everest south base camp, 314kHz

[[ -z "$4" ]] && echo "Usage: $0 <ID> <--bot-options>" && exit 1
id=$1;shift

# check for commands
for neededProg in python ffmpeg morsewav.py luajit openssl
do
  [ -z "$(command -v $neededProg)" ] && echo "$neededProg not found" && exit 1
done
[ ! -f fgcom-radio-playback.bot.lua ] && echo "fgcom-radio-playback.bot.lua not found" && exit 1

echo "Creating NDB $id, bot options: $@"

# Generate morse code WAV file
audio_file="/tmp/fgcom-ndb-$id"
morsewav.py -a 15000 -s 64000 -w 15 -l 50 -o ${audio_file}.wav $id "   ";
[ ! -f ${audio_file}.wav ] && echo "error creating ${audio_file}.wav" && exit 1

# Convert it to ogg
ffmpeg -i ${audio_file}.wav ${audio_file}.ogg
rm ${audio_file}.wav
[ ! -f ${audio_file}.ogg ] && echo "error creating ${audio_file}.ogg" && exit 1

# Prepare the playback bot. He needs a certificate in order to connect.
openssl genrsa -out ${audio_file}-bot.key 2048 2> /dev/null
openssl req -new -sha256 -key ${audio_file}-bot.key -out ${audio_file}-bot.csr -subj "/"
openssl x509 -req -in ${audio_file}-bot.csr -signkey ${audio_file}-bot.key -out ${audio_file}-bot.pem 2> /dev/null

# Spawn the bot (additional args to the script will be passed to the bot call)
luajit fgcom-radio-playback.bot.lua --sample=${audio_file}.ogg --callsign=NDB:$id --hgt=15 --cert=${audio_file}-bot.pem --key=${audio_file}-bot.key --ttl=21600 $@


# finally cleanup
echo "cleanup"
rm -v ${audio_file}*