Created
March 18, 2016 23:22
-
-
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
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
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(); |
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
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