Skip to content

Instantly share code, notes, and snippets.

@benjaminrau
Created March 18, 2016 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjaminrau/a0ea133786e950deb7ee to your computer and use it in GitHub Desktop.
Save benjaminrau/a0ea133786e950deb7ee to your computer and use it in GitHub Desktop.
Read gps device with nodejs under openwrt and cp2102 ttl to usb converter
var nmea = require('nmea');
var trycatch = require('trycatch');
function watchGps() {
var spawn = require('child_process').spawn;
var child = spawn("python", [tempDir + "readGpsDevice.py"]);
child.stdout.on('data', function (buffer) {
trycatch(function() {
var gpsOut = nmea.parse(buffer.toString());
if (typeof gpsOut.lat != "undefined" && parseFloat(gpsOut.lat) > 0) {
console.log(gpsOut);
} else {
console.log("No gps signal.")
}
}, function(error) {
console.log("Error thrown: " + error);
});
});
}
watchGps();
import sys, serial
connected = False
port = '/dev/ttyUSB0'
baud = 9600
serial = serial.Serial(port, baud, timeout=1)
while not connected:
connected = True
while True:
print serial.readline().rstrip()
sys.stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment