Skip to content

Instantly share code, notes, and snippets.

@benjaminrau benjaminrau/main.js
Created Mar 18, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.