Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Define login info
- user=yourHAMSIGN
- password=passcode
- #Define object user info
- senduser=yourHAMSIGN
- #Define APRS-IS server
- server=poland.aprs2.net
- port=14580
- #Define station location
- lat=4146.72N
- lon=01213.80E
- #Define data
- comment="QTH"
- data="$usersend>APN100,TCPIP*:=${lat}/${lon}-${comment}"
- #Authentication variable
- aprsauth="user $user pass $password"
- #Read raspberry-pi CPU temperature
- tempraw=/opt/vc/bin/vcgencmd measure_temp #Read pi temperature
- tempfloat="$(echo "$tempraw" | awk -F= '{print $2}' | awk -F\' '{print $1}')" #Filter result to numbers only
- #Aprs telemetry protocol accepts 3 whole (int) numbers only so we need
- #to convert the result (tempfloat) into 3 whole numbers. So if tempraw=40.3, it will
- #convert it to 403. If tempraw=8.5, it will convert it to 85 and we'll add the leading zero
- #to create 3 number format 085 later bellow.
- temp="$(echo "$tempfloat * 10" | bc | awk -F. '{print $1}')"
- #Project comment
- projectcomment=Rpi temperature
- #Generate telemetry strings
- #Read data and put it into variable
- #%s means string
- #%03d means prepend up to 3 zeroes, so if the value is 8, you'll get 008, if the value is 80, you'll get 080 etc.
- #This needs to be done or APRS will deny the packets as invalid. The other things is, everytime you send the telemetry
- #a sequence number has to change, it's defined as T# in a APRS protocol. We will automate this next.
- #Check if file exist
- if [ ! -f "/tmp/sequence_number.txt" ]; then
- touch /tmp/sequence_number.txt
- fi
- #Read sequence number. Everytime the scripts runs, the number will rise by 1 until it comes
- #to 1000 and then returns back to 0. Everytime the script will run, a sequence number will change.
- read num < /tmp/sequence_number.txt
- num=$((num + 1))
- if (( num == 1000 )); then
- num=0
- fi
- #Finally, we can start assembling the data.
- #$usersend goes to %s, $num goes to first %03d and $temp goes to the last %03d in the string.
- printf -v t1 "%s>APN001,TCPIP*:T#%03d,%03d,000,000,000,000,00000000" "$senduser" "$num" "$temp"
- #Define telemetry parameters
- t2="$user>APN001,TCPIP*::$senduser :PARM.CPU Temp"
- #Define telemetry units
- t3="$user>APN001,TCPIP*::$senduser :UNIT.Deg.C"
- #Add telemetry coefficient so the APRS protocol can convert your raw values into real value.
- #We get the value in 3 whole numbers and we need to define coefficient so the APRS protocol
- #will know how to display the value. We add 0.1 to the second field, means
- #if the value is 452, the temperature will be displayed as 45.2
- t4="$user>APN001,TCPIP*::$senduser :EQNS.0,0.1,0,0,0,0,0,0,0,0,0,0,0,0,0"
- #Send bits and project comment
- t5="$user>APN001,TCPIP*::$senduser :BITS.00000000,$projectcomment"
- #Another tricky part is, $senduser total lenght has to be 9 characters. For example
- #If my $senduser=S55MA-10 means it's only 8 characters long and we need to add 1 space to it. S55MA-10 :PARM
- #If my $senduser=S55MA means it's only 5 characters long and we need to add 4 spaces to it S55MA :PARM
- #The same goes for UNIT, EQNS and BITS
- #Send data to the server
- #For telemetry to work we need to have an object before, from previous script.
- #We'll only send an object and telemetry non value data every hour so we don't spam the network.
- #We need to compare dates to see if 1 hour is past.
- #Check if file exist
- if [ ! -f "/tmp/date.txt" ]; then
- echo 0 > /tmp/date.txt
- fi
- #calculate time difference
- read olddate < /tmp/date.txt
- date="$(date +%s)"
- diff="$(echo "$date - $olddate" | bc)"
- #If 3600 is past, execute the first command, else other
- if [ "$diff" -gt 3600 ]; then
- printf "%s\n" "$aprsauth" "$data" | ncat --send-only $server $port #this is your QTH object from the first script
- printf "%s\n" "$aprsauth" "$t1" "$t2" "$t3" "$t4" "$t5" | ncat --send-only $server $port
- echo "$date" > /tmp/date.txt
- else
- printf "%s\n" "$aprsauth" "$t1" | ncat --send-only $server $port
- fi
- #Write the last sequence number.
- echo "$num" > /tmp/sequence_number.txt
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement