Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
xss committed Jan 27, 2022
1 parent 7b5b2dc commit d1ac930
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 31 deletions.
30 changes: 25 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
FROM ubuntu:21.04

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y libfftw3-dev libfftw3-3 xvfb qsstv pulseaudio build-essential git libsamplerate0-dev alsa-utils xvfb python3 python3-pip cmake && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y libfftw3-dev libfftw3-3 ffmpeg \
xvfb qsstv pulseaudio build-essential git libsamplerate0-dev alsa-utils \
xvfb python3 python3-pip cmake portaudio19-dev python-dev \
alsa-utils && rm -rf /var/lib/apt/lists/*

# spy server
RUN git clone https://github.com/miweber67/spyserver_client.git && cd spyserver_client && make && cp ss_client /usr/bin/ss_iq
#csdr
RUN cd / && git clone https://github.com/jketterl/csdr.git && mkdir -p csdr/build && cd csdr/build && cmake .. && make && make install && ldconfig
# python dependencies
RUN pip3 install Mastodon.py watchdog soundmeter
#pulse server requiremeent
RUN adduser root pulse-access

# qsstv config
RUN mkdir -p /root/.config/ON4QZ/
COPY qsstv_9.0.conf /root/.config/ON4QZ/qsstv_9.0.conf

# poster script
COPY poster.py /poster.py

#copy monitor scripts
COPY shutdown.sh /shutdown.sh
RUN chmod a+x /shutdown.sh

# startup script
COPY run.sh /run.sh
RUN chmod a+x /run.sh
RUN adduser root pulse-access
RUN pip3 install Mastodon.py watchdog
COPY poster.py /poster.py
ENTRYPOINT /run.sh

ENTRYPOINT ["/bin/sh", "-c", "/run.sh"]
VOLUME /images
46 changes: 33 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
Skims SSTV off spyservers and uploads to mastodon. This setup is a POC and currently has no handling of qsstv failure, spyserver failure or mastodon script failure. Your milage may vary. I'd recommend reboot the container every 24 hours.
Skims SSTV off spyservers using QSSTV and uploads to mastodon. This is a WIP and shouldn't be considered as stable.

```sh
docker run \
-e HOST= \
-e PORT= \
-e FREQ=14230000 \
-e M_USERNAME="" \
-e M_PASSWORD='' \
-e M_URL="https://botsin.space" \
-e M_CLIENT_ID='' \
-e M_CLIENT_SECRET='' \
-e MODE=USB \
--restart always \
--name sstv-20 \
ghcr.io/xssfox/sstv-skimmer:latest
```
docker run -e HOST=blah -e PORT=1234 -e FREQ=14230000 --mount type=bind,source=/path/images,target=/images sstv
```
env variables that need to be set:

HOST : spy server hostname
PORT : spy server port port
FREQ : frequency for USB in HZ
M_USERNAME : User name for mastodon instance
M_PASSWORD : Password for mastodon instance
M_URL : Mastodon url eg : "https://botsin.space"
M_CLIENT_ID : Client ID
M_CLIENT_SECRET : Client secret (see https://mastodonpy.readthedocs.io/en/stable/# for details on creating an app)



Environment variables
==
These need to be in order for the skimmer to work

| Name | Description |
| ---- | ------------------------------------------------------------------------------------------------------------ |
| HOST | spy server hostname |
| PORT | spy server port port |
| FREQ | frequency for USB in HZ |
| MODE | USB or LSB |
| M_USERNAME | User name for mastodon instance |
| M_PASSWORD | Password for mastodon instance |
| M_URL | Mastodon url eg : "https://botsin.space" |
| M_CLIENT_ID | Client ID |
| M_CLIENT_SECRET | Client secret (see https://mastodonpy.readthedocs.io/en/stable/# for details on creating an app) |
18 changes: 11 additions & 7 deletions poster.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
print("Starting mastodon watcher")
from mastodon import Mastodon
import os
import traceback

import time
from watchdog.observers.polling import PollingObserver
from watchdog.events import FileSystemEventHandler


import os

mastodon = Mastodon(
client_id = os.environ["M_CLIENT_ID"],
Expand All @@ -25,12 +26,15 @@
my_event_handler = FileSystemEventHandler()

def on_created(event):
# create post
print(f"new Image: {event.src_path}")
time.sleep(2)
media = mastodon.media_post(event.src_path, "image/png")
mastodon.status_post('SSTV Image received:', media_ids=[media["id"]])

try:
# create post
print(f"new Image: {event.src_path}")
time.sleep(2)
media = mastodon.media_post(event.src_path, "image/png")
mastodon.status_post('SSTV Image received:', media_ids=[media["id"]])
os.remove(event.src_path)
except:
print(traceback.format_exc())

my_event_handler.on_created = on_created

Expand Down
39 changes: 33 additions & 6 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,51 @@ set -u
set -o pipefail
set -x

# allow exiting on SIGTERM
trap "exit" SIGINT SIGTERM

# pulse audio loopback hacks.
mkdir -p /var/run/dbus
dbus-uuidgen > /var/lib/dbus/machine-id
dbus-daemon --config-file=/usr/share/dbus-1/system.conf --print-address

rm -rf /var/run/pulse /var/lib/pulse /root/.config/pulse
pulseaudio -D --verbose --exit-idle-time=-1 --system --disallow-exit

# create loopback sink
pactl load-module module-null-sink sink_name=loopback
pactl set-default-sink loopback

# run qsstv
xvfb-run qsstv &

# run python masodon posting script
export PYTHONUNBUFFERED=1
echo "Starting poster"
python3 /poster.py &

echo "Connecting to $HOST"
ss_iq -a 1200 -r $HOST -q $PORT -f $FREQ -s 12000 -b 16 - | \
csdr convert_s16_f |\
csdr bandpass_fir_fft_cc 0 0.3 0.05 | csdr realpart_cf | csdr agc_ff | csdr limit_ff | \
csdr convert_f_s16 | aplay -r 12000 -f s16 -t raw -c 1 -
#run spy client
if [ "$MODE" == "LSB" ]
then
echo "Connecting to $HOST LSB"
ss_iq -a 1200 -r $HOST -q $PORT -f $FREQ -s 12000 -b 16 - | \
csdr convert_s16_f |\
csdr bandpass_fir_fft_cc -0.3 0.0 0.05 | csdr realpart_cf | csdr agc_ff | csdr limit_ff | \
csdr convert_f_s16 | aplay -r 12000 -f s16 -t raw -c 1 - &
else
echo "Connecting to $HOST USB"
ss_iq -a 1200 -r $HOST -q $PORT -f $FREQ -s 12000 -b 16 - | \
csdr convert_s16_f |\
csdr bandpass_fir_fft_cc 0 0.3 0.05 | csdr realpart_cf | csdr agc_ff | csdr limit_ff | \
csdr convert_f_s16 | aplay -r 12000 -f s16 -t raw -c 1 - &
fi

# wait for spy client to connect
sleep 2

# start sound monitoring script - shuts down container if no sound detected.
soundmeter --trigger -1 10 --action exec --exec /shutdown.sh --daemon

echo "Started everything, waiting for any failed processes"

wait -n # wait for any process to fail
./shutdown.sh
3 changes: 3 additions & 0 deletions shutdown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
echo "Shutting down"
pkill -f bash

0 comments on commit d1ac930

Please sign in to comment.