Naprawa zwalniania PTT, odtwarzania sampli, kontenera i rotacji logów - #7
Open
dkoryto wants to merge 5 commits into
Open
Naprawa zwalniania PTT, odtwarzania sampli, kontenera i rotacji logów#7dkoryto wants to merge 5 commits into
dkoryto wants to merge 5 commits into
Conversation
The playback loop had no cleanup guard, so any exception between switching PTT on and off left the transmitter keyed. RPi.GPIO does not reset pins on interpreter exit, so the pin stayed HIGH until reboot. - extract PTT release into ptt_off(), idempotent, covering serial and GPIO - register it via atexit and SIGTERM/SIGINT/SIGHUP handlers - wrap the playback loop in try/finally that always calls it The loop itself could raise in several ways. voice_channel was not reset between iterations, so a failed play() either raised NameError on the first sample or silently reused the previous, already finished channel, dropping the sample without a trace. The bare except also swallowed KeyboardInterrupt, making Ctrl+C unable to stop playback. - reset voice_channel at the start of every iteration and skip the wait loop when playback failed - catch KeyError and pygame.error instead of everything, and log the failure - cover sndarray.make_sound() with the same handler
The image could not be built at all: .dockerignore excluded .env and .git while the Dockerfile copied both, so COPY failed on a missing source. On a fresh clone .env does not exist either, since it is gitignored. - drop COPY of .env, secrets go in at runtime via --env-file, they no longer end up readable in an image layer - drop COPY of .git (108 MB) and the git package, they were only there for the update check - add -y and --no-install-recommends to apt-get, drop the bare apt-get upgrade that aborts on the confirmation prompt in a non-interactive build - clean up apt lists, install requirements before copying the code so a code change does not rebuild the dependency layer - build the user with the host UID/GID, otherwise the mounted logs directory and the PulseAudio socket are not writable - switch to ENTRYPOINT so arguments can be passed through to sr0wx.py run-docker.sh mounted the PulseAudio cookie into /root, while the container runs as sr0wx, and passed no devices, so PTT silently never keyed. - mount the cookie in the container user's home - pass /dev/gpiomem and, via SR0WX_SERIAL, the serial device - require .env, init the pyliczba submodule, persist logs, forward arguments - skip -it when there is no terminal, so cron and systemd runs work Both config files refused to start without a .env file, which made --env-file useless. They now load .env when it is there, fall back to the environment, and report which variables are actually missing. This also fixes METEOSTATION_IP crashing with AttributeError when unset.
The log filename carried a timestamp evaluated at import time, so every run opened a new file and RotatingFileHandler never had anything to rotate. A station running hourly left ~8800 files a year on the SD card. - switch both configs to TimedRotatingFileHandler with a fixed filename, rotating at midnight and keeping 30 days - set encoding to utf-8, the messages contain Polish text - create the logs directory on import, it does not exist in a fresh clone - ignore rotated files too, logs/*.log missed sr0wx.log.YYYY-MM-DD - drop the now unused datetime import
…ments Rerunning the script to repair or update the virtualenv overwrote .env with the empty example, wiping the API keys and the APRS passcode. - keep an existing .env, only create it when it is missing - accept -r to install requirements-rpi.txt, which additionally pulls RPi.GPIO - cd to the script directory, so the virtualenv is not created wherever the script happened to be called from
Shorter recordings, same format (Ogg Vorbis, mono, 22050 Hz): I 0.53 s -> 0.26 s, W 0.54 s -> 0.34 s, Z 0.61 s -> 0.37 s
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pięć poprawek błędów znalezionych przy przeglądzie projektu. Bez nowych
funkcji, bez zmian w modułach pobierających dane.
Zwolnienie PTT i pętla odtwarzania (de14371)
Pętla odtwarzania nie miała żadnego zabezpieczenia, więc wyjątek pomiędzy
włączeniem a wyłączeniem PTT zostawiał zakluczony nadajnik.
RPi.GPIOnieresetuje pinów przy wyjściu z procesu, więc pin zostawał w stanie HIGH aż do
reboota — czyli zablokowana częstotliwość i emisja bez nadzoru.
ptt_off(), idempotentnego, obsługującegozarówno GPIO jak i port szeregowy
atexitoraz handlerySIGTERM/SIGINT/SIGHUPtry/finally, które zawsze je wywołujeSama pętla mogła rzucić wyjątkiem na kilka sposobów.
voice_channelnie byłoresetowane między iteracjami, więc nieudane
play()albo rzucałoNameErrorna pierwszym sample, albo po cichu czekało na poprzedni, już zakończony kanał
— sampel wypadał z komunikatu bez żadnego śladu w logach. Puste
exceptłykało też
KeyboardInterrupt, przez co Ctrl+C nie przerywał odtwarzania.voice_channelresetowane na starcie każdej iteracjiKeyErroripygame.error, z logiemsndarray.make_sound()objęty tym samym zabezpieczeniemKontener (17bfcf8)
Obraz w ogóle się nie budował:
.dockerignorewykluczał.envi.git,a
Dockerfilekopiował oba, więcCOPYpadał na brakującym źródle. Naświeżym klonie
.envi tak nie istnieje, bo jest w.gitignore.COPY .env— sekrety wchodzą przez--env-file, nie zostają czytelnew warstwie obrazu
COPY .git(108 MB) i bez pakietugit, były tam tylko dlasprawdzania aktualizacji
apt-getz-yi--no-install-recommends, usuniętyapt-get upgradebez potwierdzenia, który przerywa build nieinteraktywny
przebudowuje warstwy z
pip installlogsi gniazdo PulseAudio są niezapisywalne
ENTRYPOINTzamiastCMD, argumenty przechodzą dosr0wx.pyrun-docker.shmontował cookie PulseAudio do/root, podczas gdy kontenerchodzi jako
sr0wx, i nie przekazywał żadnych urządzeń — PTT nigdy niekluczował, po cichu.
Oba pliki konfiguracyjne odmawiały startu bez pliku
.env, co czyniło--env-filebezużytecznym. Teraz wczytują.env, gdy jest, w przeciwnymrazie biorą wartości ze środowiska, i mówią których zmiennych brakuje.
Przy okazji znika
AttributeErrorna nieustawionymMETEOSTATION_IP.Rotacja logów (b550477)
Nazwa pliku logu zawierała znacznik czasu wyliczany przy imporcie, więc każde
uruchomienie otwierało nowy plik i
RotatingFileHandlernie miał czegorotować. Stacja chodząca co godzinę zostawiała ~8800 plików rocznie na karcie.
TimedRotatingFileHandlerze stałą nazwą, rotacja o północy, 30 dnilogstworzony przy imporcie, na świeżym klonie go nie ma.gitignorełapie też pliki rotowane,logs/*.lognie obejmowałosr0wx.log.RRRR-MM-DDsetup.sh (4550111)
Ponowne uruchomienie skryptu w celu naprawy lub aktualizacji środowiska
nadpisywało
.envpustym szablonem, kasując klucze API i passcode APRS..envzostaje nietknięty-rinstalujerequirements-rpi.txt(dokładaRPi.GPIO)cddo katalogu skryptuSample (798e1e4)
Regeneracja sampli liter I, W, Z. Ten sam format (Ogg Vorbis, mono, 22050 Hz),
krótsze nagrania.
Uwaga przy wdrożeniu
logs/sr0wx.logzamiastlogs/RRRR-MM-DD_GG:MM.log. Jeśli coś zewnętrznego czyta logi po nazwie,wymaga aktualizacji.
.git, więc sprawdzanie aktualizacji zaloguje jednąlinię błędu na uruchomienie i poleci dalej. Do wyciszenia przez
check_for_updates = False.run-docker.shwymaga istniejącego.envi przekazuje argumentydo
sr0wx.py, np../run-docker.sh -t -m sun_rise_set.Weryfikacja
Kompilacja wszystkich plików
.py(core, moduły, skrypty, generator).Uruchomienie core w trybie
-tna module offline, a następnie na dziewięciumodułach pobierających dane — siedem zwróciło dane, zadziałał mechanizm
modułów awaryjnych. Ścieżka
numpy+pygame.sndarray(generowanie CTCSS)sprawdzona osobno, bo tryb testowy jej nie dotyka. Rotacja logów sprawdzona
na dwóch kolejnych uruchomieniach: jeden plik, dopisywanie zamiast tworzenia
nowego. Obie gałęzie warunku na
.envwsetup.shsprawdzone.Nie zweryfikowane:
docker build(brak działającego demona na maszynie, naktórej to powstawało) oraz faktyczne odtwarzanie audio i kluczowanie PTT
(brak sprzętu, tryb
-tkończy się przed tą sekcją). Przed wdrożeniem nastacji warto puścić
python3 sr0wx.py -m sun_rise_setbez-ti sprawdzićraspi-gpio get 40po zakończeniu oraz po przerwaniu Ctrl+C.