#!/usr/bin/perl # # Copyright (C) 2003 Tyler Allison # Version 1.2 : Released August 18, 2003 # # John Gilbert # version 1.3 : Released November 17, 2004 # updated to log server success/failures. # updated to allow backup server usage after primary server failure. # # Wiley Sanders # Shad Rydalch # version 1.4 : Released March 13, 2005 # updated to follow APRS SPEC for date formation # allows for a forced altitude offset # # version 1.5 : Released January 24, 2006 # updated $cwop_host variables to align with APRS-IS changes # # (see the files README and COPYING in the wx200d distro for more details.) # (wx200d can be obtained from http://wx200d.sourceforge.net) # # This script sends data to the Civilian Weather Observers Program by # using the --aprs option to the wx200 client located in the wx200d server # software (http://wx200d.sourceforge.net) # # What you need: # 1. Internet connectivity # 2. A working weather station that is plugged into a wx200d server. # 3. A CWOP callsign (http://www.findu.com/citizenweather/signup.html) # To signup you need # 3a. Your name # 3b. Your email # 3c. Nearby Town # 3d. Your address (including zip) # 3e. Elevation in meters above sea level # 4. Your Lon/Lat in DDMM.HH format # If you dont know your Lon/Lat, or you want to double check, use # http://www.geocode.com/modules.php?name=TestDrive_Eagle # You type in your street address and it gives you your Lon/Lat in # DD:MM:SS format. You can convert this to DDMM.HH format like so... # geocode.com says: 39:01:10.006N # it becomes: 3901.??N # since geocode provides SS not HH we need to convert seconds to # hundreds of seconds by 1.66*SS (so 1.66*10.006=16) # it becomes: 3901.16N # You should have converted two numbers. The Lat and Lon. # 5. Your system time syncing off a known good NTP service. If your # system has the wrong time when it submits data the data will # reported for the wrong time period. Bad! # # This script takes the information you provide (Lon/lat/callsign/etc), # combines that with what wx200 prints out and then ships it off to # the CWOP by connecting to the telnet port of the $cwop_host and spewing # out lines in a specified format. # # APRS packet format # http://pond1.gladstonefamily.net:8080/aprswxnet.html # # Run this program as a cron entry like so: # # 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/cwop > /dev/null # # # !!!EDIT THE FOLLOWING TO MATCH YOUR INSTALLTION AND INFORMATION!!! # my $log_path = '/root/weatherlog.txt'; #path for log file. Check permissions. my $cmd = '/usr/local/bin/wx200 --aprs'; my $baro_offset = 0; # use this if you need to offset the barometric pressure # Use tenths of millibars (eg: 1650) my $lat ="3901.16N"; my $lon ="08443.15W"; my $callsign = "CWBOGUS"; my $passwd = '-1'; # enter your verification code or if you dont have one # leave it -1 my $cwop_host = "rotate.aprs.net"; #primary server my $cwop_host2 = "first.aprs.net"; #backup server my $cwop_host3 = "second.aprs.net"; #backup server my $port = "23"; my $date_format = 0; # set this to 1 if you are having date format problems # # !!! NO EDIT BELOW THIS LINE REQUIRED !!! # my $aprs_net; my $aprs_data; my $iaddr; my $paddr; my $proto; my $returnvalue; use POSIX qw(strftime); use Socket; use strict; my $dateutc = strftime "%d%H%Mz", gmtime time; open(LOG," >> $log_path") or die ('Could not open log'); open PIPE, "$cmd |" or die "$0: can't pipe from $cmd: $!\n"; while () { # each line of data chomp; $aprs_net = "user $callsign pass $passwd vers wx200d .01\n"; if ($baro_offset) { $aprs_data = "$callsign\>APRS,TCPIP*:\@$dateutc$lat/$lon\_"; $aprs_data = $aprs_data . substr($_ ,0 ,27); $aprs_data = $aprs_data . substr ("000" . (substr($_ ,27 ,5 ) + $baro_offset ), -5 ); $aprs_data = $aprs_data . "XRSW"; } else { $aprs_data = "$callsign\>APRS,TCPIP*:\@$dateutc$lat/$lon\_$_"; } print "$aprs_net"; print "$aprs_data\n"; } $returnvalue=wxsend($cwop_host); timestamplog(); printf LOG ("$returnvalue $cwop_host\r\n"); #print success or failure msg from first server. if($returnvalue ne "success") { $returnvalue=wxsend($cwop_host2); #try backup server timestamplog(); #timestamp log printf LOG ("$returnvalue $cwop_host2\r\n"); #print return value from second server. } if($returnvalue ne "success") { $returnvalue=wxsend($cwop_host3); #try another backup server timestamplog(); #timestamp log printf LOG ("$returnvalue $cwop_host3\r\n"); #print return value from third server. } if($returnvalue ne "success") { timestamplog(); printf LOG ("All servers reported errors. Wx not updated.\r\n"); close(LOG); die ('All servers reported errors. Wx not updated. See weatherlog.txt'); } close(LOG); exit; sub wxsend { my($cwop_host)= @_; my $a; $iaddr = inet_aton($cwop_host) or return("no host (dns resolution failed):"); $paddr = sockaddr_in($port,$iaddr); $proto = getprotobyname('tcp'); socket(S, PF_INET,SOCK_STREAM,$proto) or return("socket: $!"); connect(S,$paddr) or return("connect: $!"); select(S); $| = 1; select(STDOUT); $a=;print "$a"; print S "$aprs_net\r\n$aprs_data\r\n"; $a=;print "$a"; close(S); return("success"); } sub timestamplog { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(); $year-=100; $mon+=1; printf LOG ("%2.2d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d ",$mon,$mday,$year,$hour,$min,$sec); #gives a format like 03/17/02 01:18:26 }