Last active
February 2, 2016 01:22
-
-
Save keisisqrl/944f9083f42fec9d24b8 to your computer and use it in GitHub Desktop.
Aprs checkin via Yo and hook.io
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is designed to run on hook.io but you could probably customize it | |
module['exports'] = function yo_aprs (hook) { | |
var request = require('request'); | |
//var numeral = require('numeral'); | |
// IF you want to use this, change this | |
if ( hook.params["username"] != "KEISISQRL" ) { | |
console.log("bad user"); | |
hook.res.end("nah go away"); | |
return false; | |
} | |
var yo_location = hook.params["location"]; | |
if ( !yo_location ) { | |
console.log("no loc"); | |
hook.res.end("no location"); | |
return false; | |
} | |
console.log(yo_location); | |
// change this | |
var callsign = "N0NE"; | |
var ssid = 10; | |
// and this | |
var passcode = -1; | |
var symbol = ["/","$"]; | |
var login_line = "user " + callsign + "-YO pass " + passcode + " vers YoPRS 0.42"; | |
var yo_latlong = yo_location.split(';'); | |
var yo_lat_f = parseFloat(yo_latlong[0]); | |
var yo_long_f = parseFloat(yo_latlong[1]); | |
var lat_dir, long_dir; | |
//Set direction and get abs | |
if (yo_lat_f < 0) { | |
lat_dir = "S"; | |
}else{ | |
lat_dir = "N"; | |
} | |
yo_lat_f = Math.abs(yo_lat_f); | |
if (yo_long_f < 0) { | |
long_dir = "W"; | |
}else{ | |
long_dir = "E"; | |
} | |
yo_long_f = Math.abs(yo_long_f); | |
var yo_lat_deg = Math.floor(yo_lat_f); | |
var yo_long_deg = Math.floor(yo_long_f); | |
var yo_lat = (yo_lat_deg * 100 + (yo_lat_f % 1 * 60)).toFixed(2); | |
var yo_long = (yo_long_deg * 100 + (yo_long_f % 1 * 60)).toFixed(2); | |
var lat_pad = "", long_pad = "", lat_after = "", long_after = ""; | |
// Set needed padding (I hate Javascript, where's my damn sprintf) | |
if (yo_lat < 1000) { | |
lat_pad = "0"; | |
} | |
if (yo_long < 1000) { | |
long_pad = "00"; | |
} else if (yo_long < 10000) { | |
long_pad = "0"; | |
} | |
if (yo_lat % 1 == 0) { | |
lat_after = ".00"; | |
}else if (yo_lat % .1 == 0) { | |
lat_after = "0"; | |
} | |
if (yo_long % 1 == 0) { | |
long_after = ".00"; | |
}else if (yo_long % .1 == 0) { | |
long_after = "0"; | |
} | |
// Format the AX.25 packet | |
// var ax25 = callsign + "-" + ssid + ">APX042,TCPIP*:!" + numeral(yo_lat).format("0000.00") + lat_dir + symbol[0] + numeral(yo_long).format("00000.00") + long_dir + symbol[1] + " checkin via Yo"; | |
var ax25 = callsign + "-" + ssid + ">APX042,TCPIP*:!" + lat_pad + yo_lat + lat_after + lat_dir + symbol[0] + long_pad + yo_long + long_after + long_dir + symbol[1] + " checkin via Yo"; | |
var to_send = login_line + "\n" + ax25; | |
// send the thing to the thing | |
request({ | |
method: 'POST', | |
uri: 'http://srvr.aprs-is.net:8080/', | |
headers: { | |
'Accept-Type': 'text/plain', | |
'Content-Type': 'application/octet-stream', | |
'Content-Length': to_send.length | |
}, | |
body: to_send}, | |
function (e,r,b) { console.log("request done"); hook.res.end("cool"); }); | |
// Ultimately unnecessary but y'know nice for debugging I thought | |
console.log("Submitted: " + to_send); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The string you call ax25 is more commonly known as tnc2 format. AX.25 is the format used to modulate the data over FM.