Beacon APRS via TCP/IP con Python

Negli articoli di qualche tempo fa abbiamo visto come creare uno Script Linux per APRS Beacon tramite TCP/IP in PERL e anche la versione Script PHP per l’invio di dati meteo in APRS, oggi invece vi presento la versione in Python, molto comoda da implementare nei Raspberry che ci circondano nella vita quotidiana, lo script è già stato pensato per Python3 ma è anche retrocompatibile con la versione 2.7

Per eseguirlo è sufficiente creare un file con estensione “.py”, nel nostro esempio

nano /home/pi/beacon.py

Poi copiamo

#!/bin/python
#
# Copyright 2010 IU2FRL <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from socket import *
from datetime import datetime
import psutil
from gpiozero import CPUTemperature
from pathlib import Path

# APRS-IS login info
serverHost = ‘rotate.aprs2.net’
serverPort = 14580
aprsUser = ‘XXYZZZ’
aprsSSID = ‘1’
aprsPass = ‘00000’
aprsLongitude = ‘0000.00N’
aprsLatitude = ‘00000.00E’
symbol = ‘?’
comment = ”

# Get current time and date
dateTimeObj = datetime.now()
aprsTime = dateTimeObj.strftime(“%H%M%S”)

# Get CPU usage
cpuUsage = str(psutil.cpu_percent(4))

# Get CPU Temperature
cpuTemp = str(CPUTemperature().temperature)

# APRS packet
payload = ‘@’ + aprsTime + ‘z’ + aprsLongitude + ‘/’ + aprsLatitude + symbol + comment + ‘CPU: ‘ + cpuUsage + ‘%’ + ‘Temp: ‘ + cpuTemp + ‘C’

# create socket & connect to server
sSock = socket(AF_INET, SOCK_STREAM)
sSock.connect((serverHost, serverPort))
aprsUser = aprsUser + ‘-‘ + aprsSSID
# logon
logonString = ‘user ‘ + aprsUser + ‘ pass ‘ + aprsPass + ‘ vers KD7LXL-Python 0.1\n’
sSock.sendall(logonString.encode(‘utf-8’))
# send packet
packetString = aprsUser + ‘>APRS,TCPIP*:’ + payload + ‘\n’
sSock.sendall(packetString.encode(‘utf-8’))
# close socket
sSock.shutdown(0)
sSock.close()

 

Lo script si può inserire su cron e fare in modo che ad intervalli personalizzati si possa inviare il pacchetto sulla mappa APRS contenente l’utilizzo CPU e la temperatura attuale

Per eseguirlo dobbiamo aggiungere le librerie

pip3 install psutil

pip3 install gpiozero

poi impostiamo “nano” come editor di CRON

export EDITOR=nano

e successivamente apriamo le pianificazioni esistenti ed aggiungiamo una nuova riga

*/5 * * * * /home/pi/beacon.py >> /dev/null 2>&1

Premiamo CTRL+O e CTRL+X per salvare e via!

Per creare la pianificazione a nostro piacimento possiamo farci aiutare dal sito: https://crontab.guru/every-5-minutes

Post Disclaimer

Creative common license BY-NC_SA

Informazioni Importanti

Note generali: Le informazioni contenute in questo articolo sono di carattere informativo e rispecchiano le opinioni personali del autore. Tutte le guide nel sito vengono proposte "as it is" puramente a scopo didattico. L'utente che accetta di seguirne i passaggi si assume ogni responsabilità in caso di guasto/malfunzionamento o altro problema come conseguenza della modifica.

Link di affiliazione e contenuti promozionali: Nei post di iu2frl.it posso includere collegamenti a rivenditori. Posso ricevere una piccola commissione dal rivenditore se effettui un acquisto dopo aver fatto clic su uno di questi link. I post non sono espressamente sponsorizzati da rivenditori, editori, promotori o produttori, se non diversamente specificato chiaramente e tutte le decisioni editoriali sono prese esclusivamente dagli autori dei singoli articoli.

Contenuti riguardanti regolamenti e/o normative: Eventuali riferimenti a normative non costituiscono valore legale, si tratta di libere interpretazioni ed estratti di circolari corredate da eventuali commenti, si invitano tutti gli utenti a verificare la veridicità di tali informazioni sugli organi ufficiali di riferimento, nessuna colpa o responsabilità può essere data agli autori degli articoli.

Licenza di utilizzo: Tutti i contenuti vengono condivisi con licenza CC BY-NC-SA 4.0: Questa licenza consente ad altri di remixare, adattare e sviluppare i contenuti in modo non commerciale, purché accreditino l'autore originale e concedano in licenza le loro nuove creazioni con gli stessi termini. Per maggiori informazioni visitare il sito Creative Commons.

Important Informations

General notes: The information contained in this article is of an informative nature and reflects the personal opinions of the author. All the guides/tutorial on the website are offered "as it is" for educational purposes only. The user who agrees to follow the steps assumes all responsibility in case of failure/malfunctioning or other problem as a result of the modification.

Affiliate links and promotional products: In some posts of iu2frl.it I can include links to resellers. I can get a small commission from the reseller if you make a purchase after clicking on one of these links. The posts are not expressly sponsored by resellers, publishers, promoters or producers, unless otherwise clearly specified and all editorial decisions are made solely by the authors of the individual articles.

Contents about rules and laws: Some articles may contain portions or whole laws or rules regarding specific areas, these kind of content are meant to be indicative only, no responsability can be given to the authors. Always refer to official sources when looking for rules or laws.

Contents licenses: All the contents are published as CC BY-NC-SA 4.0: This license lets others remix, adapt, and build upon your work non-commercially, as long as they credit you and license their new creations under the identical terms.. For more informations please visit Creative Commons website.

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *