maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Nokia N810 (https://talk.maemo.org/forumdisplay.php?f=28)
-   -   Using N810 as a bluetooth GPS module (https://talk.maemo.org/showthread.php?t=20907)

ledimies 2008-06-12 13:42

Using N810 as a bluetooth GPS module
 
Hello,

I was wondering if it is possible to use the n810 as a bluetooth gps module. I just bought Nokia E51 phone and it has some interesting apllications that would benefit from gps connection (such as sports tracker). I would like to use n810's gps so I wouldn't have to buy a separate bluetooth gps module. Does anyone know if this is possible and, if it is, how?

jakubd 2008-06-12 15:49

Re: Using N810 as a bluetooth GPS module
 
It is definitely doable, but probably not out of the box - you need to make n810 to open service over SPP profile on BT and feed there internal GPS data. Probably it can be done in a simple bash script, but you have two problems:
1. n810 GPS device is just... not the best (especially taking into account time-to-fix)
2. n810 battery might die quite fast
I really think, that buying ANY bluetooth GPS receiver (they are really cheap now) might be just better choice.

ledimies 2008-06-13 05:29

Re: Using N810 as a bluetooth GPS module
 
Great! I don't care about the long time-to-fix, once the fix is aquired it is reliable. I also don't care about the possible battery life problems.

I am sure someone has already done this so I am sure that that someone could shed some details about how this was done.

Thanks!

speculatrix 2008-06-14 23:32

Re: Using N810 as a bluetooth GPS module
 
I would guess that you need to do the following (I don't have an n810 or anything similar)

basically, make a script that "listens" to rfcomm on the tablet and then reads from /dev/gps writing to the bluetooth virtual serial device.. something like this

rfcomm listen 0 "cat /dev/gps > /dev/rfcomm0"


you might need to put the "cat" command into a shell script, e.g.
Code:

$ cat > gps_to_rfcomm
#!/bin/bash
cat /dev/gps > /dev/rfcomm0
^D
$ chmod ugo+x gps_to_rfcomm
$ rfcomm listen 0 gps_to_rfcomm


MOC 2008-06-16 19:44

Re: Using N810 as a bluetooth GPS module
 
I would absolutly love to have this ability too.

So, my fingers are crossed that someone skillful will come up with a solution.

Cheers!

locusf 2008-06-16 20:03

Re: Using N810 as a bluetooth GPS module
 
Quote:

Originally Posted by speculatrix (Post 192158)
I would guess that you need to do the following (I don't have an n810 or anything similar)

basically, make a script that "listens" to rfcomm on the tablet and then reads from /dev/gps writing to the bluetooth virtual serial device.. something like this

rfcomm listen 0 "cat /dev/gps > /dev/rfcomm0"


you might need to put the "cat" command into a shell script, e.g.
Code:

$ cat > gps_to_rfcomm
#!/bin/bash
cat /dev/gps > /dev/rfcomm0
^D
$ chmod ugo+x gps_to_rfcomm
$ rfcomm listen 0 gps_to_rfcomm


Device /dev/gps doesn't exist but /dev/pgps does, I changed it and tried Nokia Maps 2.0 on my E51 but no avail :(.

It seems that the channel needs to be specified as well, does anyone know what is the common channel for this service?

Better yet if someone would post the SDP record for the GPS service on some device so that the UUID of this service could be registered on a certain port and a phone or whatever would find it :).

So theoretically its possible.

tz1 2008-06-18 15:54

Re: Using N810 as a bluetooth GPS module
 
The internal GPS is off by default. You need to send a "P 3" to the control socket to power it up.

The following code (sending "P 3\n") turns it on, P 0 turns it off

Code:

static void sendnokgps(char *cmd)
{
    int n, len;
    struct sockaddr_un igps;
    n = socket(AF_UNIX, SOCK_STREAM, 0);
    if (n >= 0) {
        igps.sun_family = AF_UNIX;
        strcpy(igps.sun_path, "/var/lib/gps/gps_driver_ctrl");
        len = strlen(igps.sun_path) + sizeof(igps.sun_family);
        if (connect(n, (struct sockaddr *) &igps, len) != -1) {
            char buf[4];
            if (!fork()) {      // this can take a while
                write(n, cmd, strlen(cmd));
                read(n, buf, 4);
                close(n);
                exit(0);
            }
            close(n);
        }
    }
}

That will turn the GPS on. You can do it manually with echo "P 3" | socat unix:/var/lib... stdio ## if you have socat.

The next problem is the far endpoint probably doesn't have a serial port, so the "rfcomm connect rfcomm0 11:22:33:44:55:66" will fail, and I don't know how to make the Nokia use an inbound rfcomm off the top of my head (time for google).

If the second obstacle is overcome, "cat /dev/pgps >/dev/rfcomm0" will work.

tz1 2008-06-18 17:10

Re: Using N810 as a bluetooth GPS module
 
Note: I tried a few things, mainly rfcomm from another linux box and they seemed to require a /etc/bluetooth/pin, but it still would not open a serial port across bluetooth. If someone can get rfcomm going so I can do ls >/dev/rfcomm0 on one computer (or the windows/mac equivalent) and cat /dev/rfcomm0 on the tablet (or vice versa) it would help greatly.

I suspect there is no serial port profile (SPP) at one or both ends.

tz1 2008-06-18 17:47

Re: Using N810 as a bluetooth GPS module
 
progress of a sort, on the Nokia:

rfcomm -i hci0 listen 0 "cat /dev/pgps >/dev/rfcomm0"

It listens and connects (and I've paired the devices), but I think I need to change the "cat..." into a shell script. I also need to do a pgps control program.

tz1 2008-06-18 19:22

Re: Using N810 as a bluetooth GPS module
 
Success!

First, create a script to launch the navicore gps control program (make sure it is set to the internal and not a BT gps via the control panel). and make it executable (I call it gpson):

Code:

#!/bin/sh
exec /usr/libexec/navicore-gpsd-helper >$1

Then, make sure you've paired with the other device (in the BT devices list).

(UPDATE!) Advertise a serial port service

Code:

sdptool add SP
Then run:

Code:

rfcomm -i hci0 listen 2 1 ./gpson {}
and then connect from a remote device. You might want to put it into an infinite loop, and or background. Also you might want to try "rfcomm -r -i hci0..." to put it in raw mode.

The navicore-gpsd-helper turns the internal GPS on (if it is selected) and emits NMEA to stdout.

Note: my linux laptop works with rfcomm connect... & cat /dev/rfcommX. I had to tweak my Mac (control panel, bluetooth, edit serial port). I will try Windows later, but adding the service above should make things work.

tz1 2008-06-18 23:49

Re: Using N810 as a bluetooth GPS module
 
This works. It can be launched from one of the statusbar launchers.

Save to /usr/local/bin/nokasgps or whatever, as perm 755 (probably owned by root). Then just run it (without parameters) to sit and listen for a connection. Pair your Nokia with your device and set up the serial port. It will take a second or two for the NMEA stream to appear. You can kill it when you don't need it, but it will just sit there and wait (maybe with BT on draining the battery a bit faster?).

Code:

#!/bin/sh
if [ $# == 0 ]; then
        sdptool add SP
        while true; do
                rfcomm -r -i hci0 listen 2 1 $0 {}
        done
fi
exec /usr/libexec/navicore-gpsd-helper >$1

Note you will want to use the control panel to insure the location is set to the "Internal GPS" - though it probably would echo a BT GPS unit.

tz1 2008-06-19 14:12

Re: Using N810 as a bluetooth GPS module
 
It works with Windows XP too. I did have to delete and repair my tablet for it to see the serial port service, but it came up with the serial ports when it was paired. I also did the same thing with my MacBook.

Now to try my n810...

ledimies 2008-06-19 15:38

Re: Using N810 as a bluetooth GPS module
 
Thanks tz1!

Your script works just fine. It would seem that the rfcomm program is not installed to OS2008 automatically. All I had to do to fix that issue was to install bluez-utils-test (apt-get install bluez-utils-test).

Now I need to figure out how can I run the script from somewhere else except from the console...

tz1 2008-06-19 16:52

Re: Using N810 as a bluetooth GPS module
 
I use:

http://maemo-hackers.org/wiki/OssoStatusbarCpu

I'd create one command for (path)nokasgps, and maybe another for "killall nokasgps" if you need it.

There is probably a way to start it backgrounded from /etc/init.d/ somewhere.

So far, it doesn't seem to use much power. The tablet looks like it would run about as long as my stand-alone devices.

Alexl 2008-09-30 05:14

Re: Using N810 as a bluetooth GPS module
 
The script works when I connect using a serial program.
However, it doesn't work when I connect using a GPS program. on my phone.
Any suggestions?:confused:

tz1 2008-10-08 19:38

Re: Using N810 as a bluetooth GPS module
 
Make sure the phone expects "NMEA" streams and isn't looking for a BT garmin or other device. The Nokia also takes time to enable GPS and lock, and your phone's software might not wait long enough or display that the GPS is still searching.

Or your phone isn't properly paired with the n810. You may need to redo the pairing after this is running so it sees the SDP service used by the GPS and not just obex and audio stuff.

interceptor3 2008-10-20 01:54

Re: Using N810 as a bluetooth GPS module
 
Tz1, I really would like to implement your code to enable the N810 to be used as a GPS module (by my Treo 680 running TomTom nav software).

However, I am a newbie and don't know much about Linux or developing for the 810. Can you please point me to a good intro to get me started? I don't even know where to place the code, if it needs to be compiled or linked or if any additional package is necessary.

I don't want to get into anything fancy, just to be able to set up nice solutions like the one you posted.

Thanks for any help you can provide.
-Mark

tz1 2008-10-20 18:17

Re: Using N810 as a bluetooth GPS module
 
PM me if this doesn't answer.

Any introduction to Linux that includes information on how to use the "command line interface" or "shell" or "shell scripting" would explain what that bit of code I posted does in general terms and how to get it on your system.

Also I was thinking of including this functionality as part of minigpsd (which is smaller, faster, but has lots more features than the stock gpsd). This could be made an installable debian file and run at bootup time, but I want to be a little more careful in not stepping on anything else.

interceptor3 2008-10-23 00:16

Re: Using N810 as a bluetooth GPS module
 
Thanks for the answer! I'll give it a try. I, for one, would vote for including this functionality in minigpsd, especially if it is an installable debian file.
Regards,
-Mark

tz1 2008-10-23 17:57

Re: Using N810 as a bluetooth GPS module
 
Annotated:

#!/bin/sh The pound sign is treated as a comment. The pair #! tells the system that it is a runnable shell script, and should be passed to the program which follows, in this case "/bin/sh". You can find similar things for python, e.g. /usr/bin/python or /usr/bin/gawk.

if [ $# == 0 ]; then The if/then are basic programming constructs in the shell. The "[" is actually the "test" command (see manpage for test) which processes everything to the closing bracket and returns a value. $# is the number of parameters on the command line. So the statement says do the following section (up to an else or "fi" - fi ends if, esac ends case, they like spelling backwards...


sdptool add SP This is a bluetooth command (from the package bluez-utils-test - search the fora for links) which turns on the SerialProfile, so it can look like it has a serial port.

while true; do
rfcomm -r -i hci0 listen 2 1 $0 {}
done


The while-true just creates an infinite loop. The rfcomm command is another bluetooth utility which listens for a connection then executes a program. In this case $0 which ends up being this same script (with a parameter this time, and the parameter will be the port the bluetooth wants to talk over). It will repeatedly run after disconnecting each session, and a disconnect will kill the script it runs.

fi
exec /usr/libexec/navicore-gpsd-helper >$1


fi ends the if section, and we only come here if there is a parameter, in this case it will be in "$1" which will expand to something like "/dev/rfcomm2". So this will run the navicore-gpsd-helper and the output will go out over the bluetooth serial port.

The "exec" says to overlay the shell process with the command, so instead of having a shell calling an executable with parameters, the shell process becomes the executable with parameters saving resources.

interceptor3 2008-11-07 03:40

Re: Using N810 as a bluetooth GPS module
 
I'm almost there. I'm getting this error:
sh: missing ]
./nokasgps: line 9: cannot create : nonexistent directory

There are no typos in my script - I've checked...
What am I missing?
Thanks for all your help.
-Mark

tz1 2008-11-07 20:19

Re: Using N810 as a bluetooth GPS module
 
Make sure the second line is
i f open-bracket dollar hatch-pound equals equals zero close-bracket semicolon space t h e n

if [ $# == 0 ]; then

It sounds like something ate the closing bracket. Double-check your typing.

Also try "sh -x ./nokasgps" to see what it is actually executing

nowave7 2009-01-13 21:34

Re: Using N810 as a bluetooth GPS module
 
Hello everybody. I've wanted to try to pair my N810 with my Nokia N80 running tomtom sw using N810 as a bluetooth GPS module. I've used the script that tz1 presented. It starts to pair with the phone, but then it shows that it has disconnected and on the phone it says that there is no GPS device found. Have I missed something?

nowave7 2009-01-13 23:08

Re: Using N810 as a bluetooth GPS module
 
It is working after all! All it needed was for the N810 to lock on to GPS signal, and the tomtom on N80 found the device and displayed the correct location! Thank you tz1 very much for the script!

tz1 2009-01-15 22:48

Re: Using N810 as a bluetooth GPS module
 
When the GPS starts up on the n810, it only sends a message every 5 seconds, and many phones or other apps will time-out after a fraction of a second and disconnect instead of retrying or waiting after the bluetooth connects. When it starts to see a signal, it will usually send messages every second which is enough for the remote device to pick up.

Jackeye 2009-04-21 20:25

Re: Using N810 as a bluetooth GPS module
 
I read this 3 pages about "how to use n810 as BT GPS", but I'm not successful on my n810. Please, can you help me and write me in one post what I have to do? I want to use n810 as BT GPS for Nokia E65..Thank you very much!

adem3311 2009-06-08 22:31

Re: Using N810 as a bluetooth GPS module
 
Quote:

Originally Posted by Jackeye (Post 281216)
I read this 3 pages about "how to use n810 as BT GPS", but I'm not successful on my n810. Please, can you help me and write me in one post what I have to do? I want to use n810 as BT GPS for Nokia E65..Thank you very much!

Go to X Terminal in the n810. This is in Utilities from the menu on the left. Then paste this code in X Terminal.

Code:

#!/bin/sh
if [ $# == 0 ]; then
        sdptool add SP
        while true; do
                rfcomm -r -i hci0 listen 2 1 $0 {}
        done
fi
exec /usr/libexec/navicore-gpsd-helper >$1

  • Tz1 wrote that code

You can now use the Nokia n810's GPA on your computer or cellphone via bluetooth.


Yea it took me about an hour to figure out what to do with that script. I tried saving it a a .install and all sorts of crazy stuff. nex time, just tell us to paste it in the terminal :)

wisesummer 2009-06-19 14:35

Re: Using N810 as a bluetooth GPS module
 
Quote:

Originally Posted by adem3311 (Post 294768)
Go to X Terminal in the n810. This is in Utilities from the menu on the left. Then paste this code in X Terminal.

Code:

#!/bin/sh
if [ $# == 0 ]; then
        sdptool add SP
        while true; do
                rfcomm -r -i hci0 listen 2 1 $0 {}
        done
fi
exec /usr/libexec/navicore-gpsd-helper >$1

  • Tz1 wrote that code

You can now use the Nokia n810's GPA on your computer or cellphone via bluetooth.


Yea it took me about an hour to figure out what to do with that script. I tried saving it a a .install and all sorts of crazy stuff. nex time, just tell us to paste it in the terminal :)

I tried to paste the codes in the X-Terminal, but it ended up showing '-sh: rfcomm: not found' endlessly. I had to close the X-Terminal forcedly. And of course my E63 still can't use the GPS module on N810.

Any solutions to my problem? Thanks a lot in advance!

qwerty12 2009-06-19 14:39

Re: Using N810 as a bluetooth GPS module
 
After enabling Extras, get root access and then run the following, as root:
apt-get install bluez-utils-test

wisesummer 2009-06-19 18:16

Re: Using N810 as a bluetooth GPS module
 
Quote:

Originally Posted by qwerty12 (Post 297925)
After enabling Extras, get root access and then run the following, as root:
apt-get install bluez-utils-test

Thanks a lot for the hint.

Enable Extra -> root access -> run 'apt-get install bluez-utils-test' -> then run

#!/bin/sh
if [ $# == 0 ]; then
sdptool add SP
while true; do
rfcomm -r -i hci0 listen 2 1 $0 {}
done
fi
exec /usr/libexec/navicore-gpsd-helper >$1

then it reads: 'Serial Port service registered
Waiting for connection on Channel 1',

then I connect my E63 to N810, it shows:'Connection from **:**:**:**:**:**(E63' mac) to /dev/rfcomm2
Press CTRL-C for hangup',

couple seconds later,

': not found2: line 1: *1A
: not found2: line 2: *1A
Disconnected'

And my E63 keeps asking me to connect to N810, each time same result as above.

Would someone tell me what's wrong with my tablet? Many thanks!

Jesper Cheetah 2009-07-22 23:24

Re: Using N810 as a bluetooth GPS module
 
I've stumbled on this thread many times in my searches for a simple way to let my N810 act as a GPS module. Specifically I want my Nokia E51 phone to use the GPS over bluetooh. I find that most of the solutions available seem overly convoluted, but at last I've found a method that is pretty easy and seems to work well.

First you have to shut down obexsrv:

/etc/init.d/obexsrv stop

I believe obexsrv is a program for sharing files over bluetooth, but I never do that anyway. The problem is that obexsrv insists on listening on channel 1, and my E51 insists on connecting to channel 1 to obtain GPS data. There seems to be no way to configure either of them to use a different channel.

With that taken care of, we can start announing that we have a serial port profile on channel one:

sdptool add --channel=1 SP

And now the magic moment, connect gpspipe to the bluetooth channel:

rfcomm watch 0 1 sh -c "gpspipe -r > /dev/rfcomm0"

Some of the convoluted examples given elsewhere are probably because the rfcomm watch command is fairly new and people had to find other ways of achieving this behaviour.

Now you should see something like "Waiting for connection on channel 1". If you get "Can't bind RFCOMM socket: Address already in use", that means something else is already listening on channel 1. Did you remember to shut down obexsrv?

You need to make sure the GPS keeps running. I tend to use GPSJinni for this if I don't have any other need for the GPS, but MaemoMapper, GPXView or practically any other GPS program would work as well. Does anyone know a way to keep the GPS running without having a foreground application open?

With that done, you should now be able to connect to the channel. You can test this from another Linux system like this:

rfcomm bind /dev/rfcomm0 <bluetooth-address-of-your-n810> 1
cat /dev/rfcomm0

You should now see the line "GPSD,R=1" appear, followed by loads of GPS data. On the n810 side, you should see "Connection from xx:xx:xx:xx:xx:xx to /dev/rfcomm0".

You can find the bluetooth MAC address by typing hciconfig.

The commands sdptool, hciconfig and rfcomm are available in the package bluez-utils-test. Don't ask me where I got the package from, but I think it was in one of the official Maemo repositories.

iankellogg 2009-08-15 04:51

Re: Using N810 as a bluetooth GPS module
 
I felt the need to update this. There is an application that has been around for at least a few months called minigpsd. You have to start it manually every time you want to use it but I know that it can stream gps info over http and tcpip not sure about bluetooth but it does seem that you can. I ve had great success using it as a gps receiver for my laptop using ubuntu, blueman, and minigpsd over a created adhoc network.

rohin_adalja 2010-05-14 00:16

Re: Using N810 as a bluetooth GPS module
 
^^ please explain now that wayfinder doesnt work how can i use the n810 gps data on an ipod touch where many gps programs are available but no gps chip

maemofied 2010-05-14 08:23

Re: Using N810 as a bluetooth GPS module
 
Quote:

Originally Posted by iankellogg (Post 311896)
I felt the need to update this. There is an application that has been around for at least a few months called minigpsd. You have to start it manually every time you want to use it but I know that it can stream gps info over http and tcpip not sure about bluetooth but it does seem that you can. I ve had great success using it as a gps receiver for my laptop using ubuntu, blueman, and minigpsd over a created adhoc network.

Could you please elaborate your setup?
I would like to try using my N810 GPS on my PC for Google Earth.

rohin_adalja 2010-05-15 22:01

Re: Using N810 as a bluetooth GPS module
 
please x2 !!!

rohin_adalja 2010-05-20 20:37

Re: Using N810 as a bluetooth GPS module
 
wow.. nobody?

raedbenz 2010-07-17 20:33

Re: Using N810 as a bluetooth GPS module
 
Quote:

Originally Posted by tz1 (Post 193170)
Code:

static void sendnokgps(char *cmd)
{
    int n, len;
    struct sockaddr_un igps;
    n = socket(AF_UNIX, SOCK_STREAM, 0);
    if (n >= 0) {
        igps.sun_family = AF_UNIX;
        strcpy(igps.sun_path, "/var/lib/gps/gps_driver_ctrl");
        len = strlen(igps.sun_path) + sizeof(igps.sun_family);
        if (connect(n, (struct sockaddr *) &igps, len) != -1) {
            char buf[4];
            if (!fork()) {      // this can take a while
                write(n, cmd, strlen(cmd));
                read(n, buf, 4);
                close(n);
                exit(0);
            }
            close(n);
        }
    }
}


if the other end supports RFCOMM and for a certain reason doesnt reply, will the read(n, buf, 4); make the system freeze?
or u recommend me to use just BLUEZ rfcomm API to communicate (on RS232) to a bluetooth module from maemo ?

Thanks

rohin_adalja 2010-10-22 23:20

Re: Using N810 as a bluetooth GPS module
 
Anyone want to help me?? please since wayfinder stopped working on m810 i just want to use its gps as a bluetooth module and connect it to my jailbroken ipod touch (there is an app by which you can use an external bluetooth gps module and the ipod will recognise the data).. Please instruct.. this is the only hope

rohin_adalja 2010-10-23 22:02

Re: Using N810 as a bluetooth GPS module
 
wow.. no body has any idea how to do that?

rohin_adalja 2010-10-30 16:57

Re: Using N810 as a bluetooth GPS module
 
anybody yet?


All times are GMT. The time now is 23:05.

vBulletin® Version 3.8.8