Created
February 27, 2015 16:22
-
-
Save chrismatthieu/7e5b104a634c4268dae6 to your computer and use it in GitHub Desktop.
Send Tessel GPS to Octoblu
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 gps example logs a stream of data: | |
coordinates, detected satellites, timestamps, and altitude. | |
For best results, try it while outdoors. | |
**********************************************************/ | |
var tessel = require('tessel'); | |
var gpsLib = require('gps-a2235h'); | |
var request = require('request'); | |
var querystring = require('querystring'); | |
gpsLib.debug = 0; // switch this to 1 for debug logs, 2 for printing out raw nmea messages | |
// GPS uses software UART, which is only available on Port C | |
// we use Port C because it is port most isolated from RF noise | |
var gps = gpsLib.use(tessel.port['C']); | |
// Wait until the module is connected | |
gps.on('ready', function () { | |
console.log('GPS module powered and ready. Waiting for satellites...'); | |
// Emit coordinates when we get a coordinate fix | |
gps.on('coordinates', function (coords) { | |
console.log('Lat:', coords.lat, '\tLon:', coords.lon, '\tTimestamp:', coords.timestamp); | |
var form = { | |
lat: coords.lat, | |
lon: coords.lon | |
}; | |
var formData = querystring.stringify(form); | |
var contentLength = formData.length; | |
request({ | |
headers: { | |
'Content-Length': contentLength, | |
'Content-Type': 'application/x-www-form-urlencoded', | |
'skynet_auth_uuid': '25773541-78e9-f92912f1f910', | |
'skynet_auth_token': 'e443ukaw56p8e43iatf0f6r' | |
}, | |
uri: 'http://meshblu.octoblu.com/data/25773541-78e9-f92912f1f910', | |
body: formData, | |
method: 'POST' | |
}, function (err, res, body) { | |
// console.log('err',err); | |
// console.log('body',body); | |
}); | |
}); | |
// Emit altitude when we get an altitude fix | |
gps.on('altitude', function (alt) { | |
console.log('Got an altitude of', alt.alt, 'meters (timestamp: ' + alt.timestamp + ')'); | |
}); | |
// Emitted when we have information about a fix on satellites | |
gps.on('fix', function (data) { | |
console.log(data.numSat, 'fixed.'); | |
}); | |
gps.on('dropped', function(){ | |
// we dropped the gps signal | |
console.log("gps signal dropped"); | |
}); | |
}); | |
gps.on('error', function(err){ | |
console.log("got this error", err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment