Python WIFI NMEA server on TomatoUSB router with Nook Display
- Created on Sunday, 15 July 2012 23:39
- Last Updated on Tuesday, 29 April 2014 20:58
- Written by Mike Holden
- Hits: 19888
- I wrote a python script that acts as a web-server to display any incoming NMEA 0183 data on (almost) any browser, and some example web pages to show how it can work. This can run on many different types of computers.
- I modified an off-the-shelf wireless router (ASUS RT-N16) to run the NMEA data server while maintaining all router functions (if you want them)
- I rooted a Nook Simple Touch to make an awesome daylight display of NMEA data while still using it as an e-reader when not sailing.
- I also wrote an arduino program to create fake NMEA 0183 data for testing (and to conform to www.hackaday.com standards)
- Very little hardware modifications, mostly software hacks.
I was motivated to put NMEA 0183 info on a wifi web server to use an E-Ink display as a data repeater sailboat instrument.
E-ink displays are really nice for viewing in the sun, as anyone with a black and white kindle or nook can confirm. As a low-power screen, I thought they might be good for boat instrumentation displays. The only drawback is that the refresh-rate for E-Ink displays is pretty slow. But too slow? I cooked up a web page to test using the browser in a kindle I had. I adjusted the refresh-rate and was able to confirm that once per second was fine. Try it yourself: open this link on your e-reader's browser (doesn't work with MS Internet Explorer, but firefox is good).
So, I want one. But how? E-Ink modules are around, but expensive and hard to prototype with. E-Ink readers are cheap and available, but perhaps hard to hack. Taking a cue from my experiment with screen refresh rate, I decided to implement a wireless NMEA server. My first goal was to display boat speed and depth on a mast-mounted display for my boat Firebolt. As a bonus, anyone with a wifi browser (iphone, etc) can read the instruments too.
My first attempt at a NMEA server used wifi modules and microcontrollers, but I broke the wifi module. While waiting for more parts to come, I wrote a python script to do the job, and tested it on my laptop. I then hacked a wifi router I had in my parts box to serve the data. It still runs all the wifi functions too, so if you need a router on your boat you might as well add the NMEA server to it, right? This is an all-software project, so no tools are required, but I will admit that some of the modifications are pretty confusing. Use your google skills and learn some linux basics and you will be fine.
The nook simple touch just needs to be rooted so you can run opera mobile on it to get to the server.
If any of this turns out to be too difficult for you, I'm available for consulting on your installation at very reasonable rates!
Here is a picture of the whole system:
AUS rt-n16 Router running the webserver,
Arduino providing simulated NMEA 0183 data over USB-RS232 cable
Browsers displaying data
- ASUS RT-N16 router.
- USB memory stick
- FTDI USB-Serial cable (I used this one: USB-RS232-WE-1800-BT_5.0).
- Nook Simple Touch
Python is freely available for many platforms, try here.
You will also need the pyserial library.
Download the script and associated files, put them in the same directory somewhere.
Arduino code to fake data for testing
You can then run my script on a computer; if it has NMEA data coming in it will serve it up. Go to the computers address and port 8080. For example, to run it on the same computer as the web browser start with http://127.0.0.1:8080/ If you're running it on the router like I do the router's address is http://192.168.1.1:8080/ If you know the web server's IP address just put it in front of the :8080 part and you should be able to reach it from anywhere on your local network at least.
The webserver saves each NMEA sentence to a data object. You can get the NMEA string over the web by using its header (for example, GPRMC would be http://127.0.0.1:8080/GPRMC if you run the script on the same computer the web browser is working on). You can see all the sentences received by the server using the web address /NMEA. The server shows a help page and some links if it gets a bad address or the root page is requested. Any and all sentences are saved, but as they are repeated only the most recent sentence is available.
The python script needs to be changed for your serial port, the code is set up to try COM3 first then ttyUSB0. If you use a different port edit the code.
You can change the ethernet port from 8080 but don't use 80 (the standard) if you will use a router installation, because that will conflict with the router's configuration web pages.
If you want to play around and you don't have NMEA data handy, I wrote an arduino program that will simulate it and serve it over the FTDI USB-serial port that is built in to arduino UNO and Duemilanove boards. If you haven't used the arduino before start googling, I've got enough to explain here. The arduino code sends sinusoidally varying speed and depth numbers and a bunch of other static sentences that I copied from my boat's NMEA stream.
ASUS RT-N16 Web Server
I will try to write more later, but here are the basic steps I took notes on. This was a frustrating experience for me: getting the router configured with the USB drive (to have enough space for python) and to use the USB-Serial connector.
The neat thing is that all the router functions still work, this just adds a background process to serve the data.
- Tomato USB: install on the router.
- Install optware (partitioning the USB disk was the hardest part)
- Have optware get python2.6 & pyserial
- Get USB serial to mount: Google "Github community sign" with the following notes:
- Enable USB 2.0 and 1.1
- insmod usbserial.ko
- insmod ftdi_sio.ko
- dmesg | grep tty
Nook Simple Touch Display
- Root Nook Touch
- Install Opera MOBILE (not small or light or any other version, they won't work)
- Waterproof? Ziplock?
- Power supply? I intend to plug into a bigger battery on the boat.
- Keep alive? Don't let it go to sleep...