Reply
Thread Tools
Posts: 804 | Thanked: 1,598 times | Joined on Feb 2010 @ Gdynia, Poland
#1
Hello!

I'm writing an app to remotely control N900 with any different Bluetooth and Java ME phone. So far I got almost everything working (even system-wide simulation of keypresses and mouse-touch events), by the way: you can now download xdotools package from extras-devel for fremantle if you need it. I need help with bluetooth communication. I found enormous amounts of sources, but unfortunately none really worked for me. I'm now just requesting help in getting BT communication between my N900 Python script and N95 Java ME app. What I have now to demonstrate just my problem is:

Nokia N900 side:
Code:
import bluetooth

server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )

port = 5
server_sock.bind(("",port))
server_sock.listen(1)
print "listening on port %d" % port

uuid = "1e0ca4ea-299d-4335-93eb-27fcfe7fa848"
bluetooth.advertise_service( server_sock, "FooBar", uuid )

print "Waiting for connections"

client_sock,address = server_sock.accept()
print "Accepted connection from ",address

data = client_sock.recv(1024)
print "received [%s]" % data

client_sock.close()
server_sock.close()
Code is taken from http://people.csail.mit.edu/albert/b...omm-server-sdp and edited. It is quite obsolete anyway...

I tried also http://git.kernel.org/?p=bluetooth/b...ervice;hb=HEAD and am aware of http://git.kernel.org/?p=bluetooth/b...f=test;hb=HEAD examples. But when I used this, the service was not discovered by N95 Java MIDlet.

My connection string in MIDlet is:
Code:
UUID uuid = new UUID("1e0ca4ea299d433593eb27fcfe7fa848",false);
connectionURL = "btspp://" + myRemoteDevice.getBluetoothAddress() + ":" + uuid + ";authenticate=false;name=FooBar";
And I get IllegalArgumentException while calling Connector.open() with this url. If I change uuid to just hardcoded "5" (server-side code is listening on port 5), N95 tries to send the data (bluetooth icon is blinking), but N900 script never gets it, and soon N900 gets IOException with information "SymbianOS error = -6004 : General: System failure" (it's in Polish, but that's what it says).

According to http://symbian.newlc.com/Symbian-OS-Error-Codes.html it means EPageTimedOut error from "Bluetooth Errors" category.

I've read already http://developers.sun.com/mobility/m...es/bluetooth2/ and many other documents, but I still have no idea how to set things up...

I've also googled all those errors and found no solution, just flocks of programmers unable to find solution (like me). I think I just should get some newer python code and try to build something on it, but I am totally lost at the moment.

Could anyone help me and just explain or point to source, which could explain me how to exchange data between Java ME applet on Nokia N95 phone and python script on Nokia N900 phone? I need to register bt service on N900 and connect N95 client app to it. It's a total blocker for now for my app (mmmRemotePhoneKeyboard, when I will solve this issue with bluetooth, I will upload it to extras-devel). Thank you very much in advance.

Edit: soved, see further posts

Last edited by misiak; 2012-05-14 at 14:24.
 

The Following User Says Thank You to misiak For This Useful Post:
Posts: 804 | Thanked: 1,598 times | Joined on Feb 2010 @ Gdynia, Poland
#2
Bump. What I really need is code in Python, similar to http://git.kernel.org/?p=bluetooth/b...ervice;hb=HEAD which will:

1. Open bluetooth adapter
2. Register service with custom uuid
3. Listen on bluetooth adapter for incoming connections with this uuid
4. Read incoming data within these connections (and maybe reply)

I know how to do this in Java ME, I have problems getting it work in Python. (Python on N900 should act as server, midlet on other phone as client)
 

The Following User Says Thank You to misiak For This Useful Post:
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#3
Are you running the N900 script as root?

If not, how are you able to bind to a socket < 1024 which should be reserved for root processes?

My general hunch is that you need to make sure that something is actually listening on that port before trying to debug the client code. Using telnet is one way.
 

The Following 2 Users Say Thank You to Joorin For This Useful Post:
Posts: 804 | Thanked: 1,598 times | Joined on Feb 2010 @ Gdynia, Poland
#4
Originally Posted by Joorin View Post
Are you running the N900 script as root?

If not, how are you able to bind to a socket < 1024 which should be reserved for root processes?
Well, that's quite simple and it works. I have no idea why I didn't think of running script as root, I just thought that bluetooth port numeration has nothing to do with unix/linux overall port numeration... stupid me :P

Thank you very much.

Now, I have a working setup:
Nokia N900
Code:
import bluetooth

server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )

port = 3
server_sock.bind(("",port))
server_sock.listen(1)
print "listening on port %d" % port

uuid = "A55665EE-9F91-4610-9085-C2055C888B39"
bluetooth.advertise_service( server_sock, "btsppEcho", uuid )

print "Waiting for connections"

client_sock,address = server_sock.accept()
print "Accepted connection from ",address

while True:
    data = client_sock.recv(1024)
    print "received [%s]" % data

client_sock.close()
server_sock.close()
And final connection string in MIDlet is:
Code:
"btspp://" + myRemoteDevice.getBluetoothAddress() + ":3;authenticate=true;encrypt=true;master=false";
Thank you once again, you saved existance of my app

Last edited by misiak; 2011-04-27 at 02:17.
 

The Following User Says Thank You to misiak For This Useful Post:
Posts: 726 | Thanked: 345 times | Joined on Apr 2010 @ Sweden
#5
Happy hacking.

But, using ports < 1024 is not needed. You can pick some other port, 1024 <= p < 65535, and then your process won't have to run as root.

This is recommended unless you give up your root permissions after doing the bind.
 

The Following 2 Users Say Thank You to Joorin For This Useful Post:
Posts: 804 | Thanked: 1,598 times | Joined on Feb 2010 @ Gdynia, Poland
#6
Originally Posted by Joorin View Post
Happy hacking.

But, using ports < 1024 is not needed. You can pick some other port, 1024 <= p < 65535, and then your process won't have to run as root.

This is recommended unless you give up your root permissions after doing the bind.
I know that I should use higher ports, but my Java ME code cannot discover any service running on ports above 39... I may be doing something wrong, but any port higher, than 39 in connection string causes wrong url exception. I'm not a good "Bluetooth coder" (well, maybe not even good coder at all), so it may be my mistake somewhere in code. But, on the other hand, when I register a service from Java ME (midlet acts as a server), it always gets low port number (3-5 usually) assigned by phone, tested on Nokia N95 and Nokia N97.

Previously, I programmed any bt related code only with Java ME on both sides and never had any permission problem, but I need to keep in mind that N900 programming is more like PC than phone programming :P

Once again, thank you very much for your help.
 

The Following User Says Thank You to misiak For This Useful Post:
nokiabot's Avatar
Posts: 1,974 | Thanked: 1,834 times | Joined on Mar 2013 @ india
#7
good job buddy .this is awsome always wanted it and can it type seamlesly also ?
 
Posts: 804 | Thanked: 1,598 times | Joined on Feb 2010 @ Gdynia, Poland
#8
Originally Posted by nokiabot View Post
good job buddy .this is awsome always wanted it and can it type seamlesly also ?
Not seamlessly, I had some problems with keyboard. It doesn't work pretty well either way, I had some major problems which blocked me and I suspended the projects 2 years ago, which means it will probably never be finished.
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 16:00.