Script PHP per l’invio di dati meteo in APRS

Dopo aver visto in questo articolo come inviare dati meteo sulla rete APRS, vi propongo l’eccezionale lavoro di Antonio IS0HHA che in php estrae questi dati da un database SQL (ad esempio creato da meteotemplate), crea un file CSV e poi lo invia al mio script per l’elaborazione ed il caricamento sulle mappe APRS

<?php
//
// Author Tony IS0HHA
$dbf="DATABASE_NAME"; // Database name ***
$table="TABLE"; // Table name ***
$myserver="SERVER_NAME";// Server with MySQL ***
$myuser="USER_NAME"; // MySQL access user ***
$mypassword="USER_PASSWD"; // MySQL user password ***
$myTown="YOUR_Town"; // Town used for query
//
// Connect to the database server
$linkID = @mysql_connect($myserver,$myuser,$mypassword);
if (!$linkID) {
 echo("<P>Unable to connect to the " .$myserver.
 " database server at this time.</P>" );
 die();
}

// Select the database
if (! @mysql_select_db($dbf,$linkID) ) {
 echo( "<P>Unable to open the " .$dbf .
 " database at this time.</P>" );
 die();
}
//
// Read from DB
 // Connect to the database server
 $linkID = @mysql_connect($myserver,$myuser,$mypassword);
 if (!$linkID) {
 echo("<P>Unable to connect to the " .$myserver.
 " database server at this time.</P>" );
 die();
 }

 // Select the database
 if (! @mysql_select_db($dbf,$linkID) ) {
 echo( "<P>Unable to open the " .$dbf .
 " database at this time.</P>" );
 die();
 }

 #
 $query_$myTown = "SELECT * FROM alldata";
 $result_$myTown = mysql_query($query_$myTown,$linkID);

 while ($row = mysql_fetch_array($result_$myTown))
 {

$WindDirDB=$row['B'];
$WindSpeedDB=$row['W'];
$WindGustDB=$row['G'];
$TempDB=$row['T'];
$RainTodayDB=$row['R'];
$RainRateDB=$row['RR'];
$HumDB=$row['H'];
$BaroDB=$row['P'];

 }
//
// Variables Definitions
$WindDir = ceil($WindDirDB);
if (strlen($WindDir) == 1) { ($WindDir = "00".$WindDir); }
if (strlen($WindDir) == 2) { ($WindDir = "0".$WindDir); }
//
$WindSpeed = substr($WindSpeedDB*5/18,0,3);
$WindSpeed = ceil($WindSpeed);
if (strlen($WindSpeed) == 1) { ($WindSpeed = "00".$WindSpeed); }
if (strlen($WindSpeed) == 2) { ($WindSpeed = "0".$WindSpeed); }
//
//
// $WindGust = substr($WindGust*5/18,0,3);
$WindGust = ceil($WindGustDB*5/18);
if (strlen($WindGust) == 1) { ($WindGust = "00".$WindGust); }
if (strlen($WindGust) == 2) { ($WindGust = "0".$WindGust); }
//
$TempF = substr($TempDB*9/5+32,0,2);
//
if ($RainTodayDB == "0.000") { ($RainToday = "000"); }
else {
$RainToday = ceil($RainToday);
if (strlen($RainToday) == 1) { ($RainToday = "00".$RainToday); }
if (strlen($RainToday) == 2) { ($RainToday = "0".$RainToday); }
}
//
if ($RainRateDB == "0.000") { ($RainRate = "000"); }
else {
$RainRate = ceil($RainRate);
if (strlen($RainRate) == 1) { ($RainRate = "00".$RainRate); }
if (strlen($RainRate) == 2) { ($RainRate = "0".$RainRate); }
}
//
$Rain24 = $RainToday;
//
$Hum = ceil($HumDB);
//
$Baro = substr($BaroDB*100,0,5);
//
$list = array (
array( $WindDir,$WindSpeed,$WindGust,$TempF,$RainToday,$RainRate,$Rain24,$Hum,$Baro)
);

$fp = fopen("/home/pi/scripts/weather/datimeteo.txt", "w") or die("Unable to open file!");
foreach ($list as $fields)
{
fputcsv($fp, $fields);
}
fclose($fp);
// Call IU2FRL Perl Script
echo exec('/usr/bin/perl /home/pi/scripts/weather/aprs-wx.pl');
?>

Questo script PHP è stato scritto per poter inviare in rete APRS i dati ricevuti dalla nostra Stazione Meteo. Lo script preleva i dati dal Database MySQL della Raspberry che sono stati inseriti dal Software meteotemplate (http://meteotemplate.com) e li invia in rete usando lo script aprs-wx.pl creato da IU2FRL. Se si desidera inviare i dati ogni 5 minuti, bisogna inserire in CRON (crontab -e) la seguente riga:

*/5 * * * * /usr/bin/php /home/pi/scripts/weather/aprs_wx.php > /dev/null

Per una maggior precisione dello script si consiglia di commentare la riga di lancio del beacon nel seguente modo:

// echo exec(‘/usr/bin/perl /home/pi/scripts/weather/aprs-wx.pl’);

ed inserire in CRON i seguenti 2 processi:

* * * * * /usr/bin/perl /home/pi/scripts/weather/aprs-wx.pl > /dev/null
*/5 * * * * /usr/bin/php /home/pi/scripts/weather/aprs_wx.php > /dev/null

In questo modo i dati della stazione meteo verranno salvati ogni minuto sul file datimeteo.txt ed inviati ogni 5 minuti sui server APRS.

Tutti i file (aprs_wx.php, datimeteo.txt e aprs-wx.pl) devono risiedere nella stessa directory oppure modificarli a piacere.
Lo script può essere utilizzato, modificato e pubblicato liberamente da tutti i RadioAmatori , purché ne vengano citati gli autori ( IS0HHA & IU2FRL )

Qui trovate il calcolatore per il PASSCODE APRS

È possibile visualizzare i dati della stazione meteo all’indirizzo: http://tonyp62.ddns.net/meteo/

ilhsdflgjk

Link al download dei files: aprs_wx – aprs_wx_V2 – aprs_wx_V3 – aprs_wx_V4

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 *