ec2
 

Ben
Sinclair

03/23

APRS to Twitter Gateway

require 'socket'

begin
    t = TCPSocket.new('rotate.aprs.net', 1314)
rescue
    puts "error: #{$!}"
else

    puts "Listening for messages!"

    last_message = ""

    while(true)
      line = t.recvfrom(255)[0]

      if line.include?(">") and line.include?(":")
        begin
          from_call = line.split(">")[0]
          to_call = line.split(":")[2]
          message = line[line.rindex(":")+1..line.rindex("{")-1] + " [APRS]"

          if to_call.include?("TWITT") and from_call.include?("KC0ZMX") and last_message != message
            system "/usr/bin/curl -u bensinc:password -d status=\"#{message}\" http://twitter.com/statuses/update.json"
            puts
            puts "Posted to twitter: #{message}"
            last_message = message
          end
        rescue
          puts "error"
        end

      end
    end

    t.close
end

People have been wanting to see the source code for my APRS to Twitter gateway, so here it is!

I wrote this really quickly just to try it out, and it has some flaws. Give it a try though!

I was using TWITTER as the callsign, but the VX-8R limits you to “real” callsigns, so It’s now just TWITT.