GPS receiver in OpenWrt

Market introduction of a wide variety of ready-made cheap hardware such as routers and debug board, as well as development of the project OpenWrt made available to anyone wishing to become a developer. The world for a developer turned to be like a constructor game, where he needs only desire and availability of free time to build something interesting from various parts.

Details of our constructor will be: as usual - a router, gps-receiver, OpenWrt. During my spare time (when I had it last time)) ), I am developing a robot, which I planned to supply also with a gps-mind. And some time ago the phrase gps-module sounded like something scary for me. It is time to dispel this myth!

On the stage of configuration OpenWrt the following modules are to be selected:
Kernel modules:
USB Support:
<M> kmod-usb-serial
<M> kmod-usb-serial-pl2303
Network:
<M> gpsd
Utilities:
<M> lcd4linux
<*> LCD2USB
<*> gps
Utilities:
<M> lcdproc

After the building is finished, we need to do the following. Let’s go to the directory OpenWrt, where the built packages are, and copy the package gpsd-2.94 into the section of the stick (MyData) which is mounted to /home. I have the following path to the:
/OpenWrt/build_dir/target-mipsel_uClibc-0.9.31.

Let’s download and install the packages.

root@OpenWrt:/# opkg update
Downloading ftp://ftp:ftp@192.168.0.9/Packages.gz.
Inflating ftp://ftp:ftp@192.168.0.9/Packages.gz.
Updated list of available packages in /var/opkg-lists/localpackages.
root@OpenWrt:/# opkg list |grep lc
lcd4linux - r1116-2 - LCD4Linux is a small program that grabs information from the kernel and
lcdproc - 0.5.2-1 - LCDProc is a daemon and client for displaying system information on various displays.
root@OpenWrt:/# opkg list |grep gp
gpsd - 2.94-1 - An interface daemon for GPS receivers
root@OpenWrt:/# opkg list |grep serial
kmod-usb-serial - 2.6.36.2-1 - Kernel support for USB-to-Serial converters
kmod-usb-serial-pl2303 - 2.6.36.2-1 - Kernel support for Prolific PL2303 USB-to-Serial converters
root@OpenWrt:/# opkg install gpsd kmod-usb-serial-pl2303 lcdproc
lcd4linux
Installing gpsd (2.94-1) to root...
Downloading ftp://ftp:ftp@192.168.0.9/gpsd_2.94-1_brcm47xx.ipk.
Installing libpthread (0.9.31-64) to root...
Downloading ftp://ftp:ftp@192.168.0.9/libpthread_0.9.31-64_brcm47xx.ipk.
Installing librt (0.9.31-64) to root...
Downloading ftp://ftp:ftp@192.168.0.9/librt_0.9.31-64_brcm47xx.ipk.
Installing kmod-usb-serial-pl2303 (2.6.36.2-1) to root...
Downloading ftp://ftp:ftp@192.168.0.9/kmod-usb-serial-pl2303_2.6.36.2-1_brcm47xx.ipk.
Installing kmod-usb-serial (2.6.36.2-1) to root...
Downloading ftp://ftp:ftp@192.168.0.9/kmod-usb-serial_2.6.36.2-1_brcm47xx.ipk.
Installing lcdproc (0.5.2-1) to root...
Downloading ftp://ftp:ftp@192.168.0.9/lcdproc_0.5.2-1_brcm47xx.ipk.
Installing libncurses (5.7-3) to root...
Downloading ftp://ftp:ftp@192.168.0.9/libncurses_5.7-3_brcm47xx.ipk.
Installing lcd4linux (r1116-2) to root...
Downloading ftp://ftp:ftp@192.168.0.9/lcd4linux_r1116-2_brcm47xx.ipk.
Configuring librt.
Configuring libpthread.
Configuring kmod-usb-serial.
Configuring kmod-usb-serial-pl2303.
Configuring libncurses.
Configuring lcdproc.
Configuring gpsd.
Configuring lcd4linux.

Let’s connect the gps-receiver and check the output dmesg:

root@OpenWrt:/# dmesg
pl2303 1-1.2:1.0: pl2303 converter detected
usb 1-1.2: pl2303 converter now attached to ttyUSB0

Let’s start the daemon which will get the data from the gps-receiver.

root@OpenWrt:/# gpsd -N -D5 /dev/ttyUSB0
gpsd: launching (Version 2.94)
gpsd: opening IPv4 socket
gpsd: opening IPv6 socket
gpsd: can't create IPv6 socket
gpsd: listening on port 2947
gpsd: NTPD shmat(32769,0,0) succeeded, segment 0
gpsd: NTPD shmat(65538,0,0) succeeded, segment 1
gpsd: NTPD shmat(98307,0,0) succeeded, segment 2
gpsd: NTPD shmat(131076,0,0) succeeded, segment 3
gpsd: running with effective group ID 0
gpsd: running with effective user ID 0
gpsd: stashing device /dev/ttyUSB0 at slot 0

If gpsd-daemon has started without any errors it can be restarted in the background mode:

root@OpenWrt:/# gpsd /dev/ttyUSB0

For getting the data from gpsd-daemon we can use different clients. Some examples are included into the package gpsd-2.94, which we have copied into the directory /home.

One of the examples is a console client cgps, which displays the quantity of satellites in use, coordinates, speed and many other data which are poorly informative for me personally now.

Let’s start cgps.

root@OpenWrt:/# /home/gpsd-2.94/.libs/cgps

On the display there should be shown the following form with the current data:

It is interesting to check if these data are real... Let’s open maps in Google and paste the current coordinates. ))

I wish these data to be shown on the LCD display. It is very easy to do this using gps-client from Lcd4linux. For this we should just correct the file lcd4linux.conf, adding to it for example the following gps-widget:
Widget gps-test1 {
class 'Text'
expression gps::parse('0x0000111','0')
width 20
update tack
align 'C'
}

You can see how I have done it lcd4linux.conf. It is also good described on the web site of Lcd4linux https://www.bulix.org/projects/lcd4linux/wiki/plugin_gps.

Before starting Lcd4linux we should declare the variable GPS_PORT, as it is described on the web site. And for the gps-client there is no need in the daemon gpsd. Therefore we should execute the command killall gpsd

killall gpsd

Let’s start the Lcd4linux:

root@OpenWrt:/# export GPS_PORT=/dev/ttyUSB0
root@OpenWrt:/# lcd4linux -vv -F
LCD4Linux 0.11.0-SVN-1092 starting
Dump of /etc/lcd4linux.conf:
Display 'LCD2USB'
Display:LCD2USB.Backlight 1
Display:LCD2USB.Driver 'LCD2USB'
Display:LCD2USB.Icons 1
Display:LCD2USB.Size '16x2'
Layout 'Default'
Layout:Default.Row1.Col1 'gps-test1'
Layout:Default.Row2.Col1 'gps-test2'
Variables.tack 100
Variables.tick 500
Widget:gps-test1.align 'L'
Widget:gps-test1.class 'Text'
Widget:gps-test1.expression gps::parse('0x10000110','0')
Widget:gps-test1.update tack
Widget:gps-test1.width 16
Widget:gps-test2.align 'L'
Widget:gps-test2.class 'Text'
Widget:gps-test2.expression gps::parse('0x10001001','0')
Widget:gps-test2.update tack
Widget:gps-test2.width 16
plugin_cfg.c: Variable tack = '100' (100)
plugin_cfg.c: Variable tick = '500' (500)
plugin_gps.c: v0.2
lcd4linux.c: initializing driver LCD2USB
LCD2USB: $Rev: 975 $
LCD2USB: scanning USB for LCD2USB interface ...
LCD2USB: found LCD2USB interface on bus 001 device 010
LCD2USB: echo test successful
LCD2USB: firmware version 1.09
LCD2USB: installed controllers: CTRL0
LCD2USB: reserving 1 of 8 user-defined characters for icons
initializing layout 'Default'
layout.c: Layout:Default: migrating 'row1.col1' to 'Layer:1.row1.col1'
layout.c: Layout:Default: migrating 'row2.col1' to 'Layer:1.row2.col1'
Creating new timer group (100 ms)
widget 'gps-test1': Class 'text', Parent '', Layer 1, Row 0, Col 0 (to 0,16)
widget 'gps-test2': Class 'text', Parent '', Layer 1, Row 1, Col 0 (to 1,16)
lcd4linux.c: starting main loop

If by starting you got the following message:

LCD4Linux 0.11.0-SVN-1092 starting
security error: owner and/or group of '/etc/lcd4linux.conf' don't match
security error: group or other have access to '/etc/lcd4linux.conf'

You should change the properties of the file lcd4linux.conf in the following way:

root@OpenWrt:/# chmod 600 /etc/lcd4linux.conf
root@OpenWrt:/# chown root:root /etc/lcd4linux.conf

I had on the display all the values equal to zero. Although just now we have seen by starting that it works. Well, at least we have to use our cogitative part of the brain ))). Let’s open the source file of gps client— plugin_gps.c. And find the following line in it:
GPS_9600<------>serial port speed, default is 4800 baud, if you define this var speed will be 9600 (export GPS_9600=dummy)

My gps-receiver is working on the speed of 9600, while the speed of 4800 is on default. Let’s change the speed and start lcd4linux again:

root@OpenWrt:/# export GPS_9600=dummy

Now let’s look to the display. It should looks like this:

Before we consider another graphical client, we make a little digression and consider the utility lcdproc, which outputs the system information like the modules lcd4linux. Before starting of lcdproc we should start the daemon LCDd, which is a server part of lcdproc.

In the configuration file of the daemon LCDd we should add the information about our display:
[hd44780]
ConnectionType=lcd2usb
Contrast=850
Brightness=800
OffBrightness=0
Keypad=yes
Backlight=yes
Size=20x2

Add the path:
DriverPath=/usr/lib/lcdproc/

Change the type of the driver:
Driver=hd44780

You can see how I have done it LCDd.conf. It is also good described on the web site of lcdproc http://lcdproc.sourceforge.net/docs/current-user.html#hd44780-lcd2usb

Let’s start the daemon LCDd:

root@OpenWrt:/# LCDd

On the display there should be shown the following. The server has started and now is waiting for the clients’ connection.

Further we start the client — lcdproc.

root@OpenWrt:/# lcdproc

On the display there should be shown the following:

And now let’s come back to our gps-receiver. In the examples to gpsd there is also a client for lcd-display — lcdgps. For it’s working we need the daemon LCDd. Let’s check how lcdgps works. Starting:

root@OpenWrt:/# gpsd /dev/ttyUSB0
root@OpenWrt:/# LCDd
root@OpenWrt:/# /home/gpsd-2.94/.libs/lcdgps

On the display there should be shown the following:

gps receiver