You Are Here:

Community: Developer Discussion Boards

#1 Old Why not work on Nokia but does on LG? - 2009-01-21, 05:15

Join Date: Dec 2008
Posts: 3
the_ether
Offline
Registered User
I'm trying to create a BT server application. For some reason this app. won't connect to my second device if I run my server app. on my Nokia 5310 but it does when I run it on my LG Viewty.

The relevant code snippet is:

UUID uuid = new UUID( 0x1101 ); // serial server
local = LocalDevice.getLocalDevice();
local.setDiscoverable( DiscoveryAgent.GIAC );

String str = "btspp://localhost:"
+ uuid.toString() + ";name=Nokia5310;authorize=true";

scn = (StreamConnectionNotifier)Connector.open( str );
append("Started as server...");
sc = scn.acceptAndOpen();
append( "Connected!" );

I never get the "Connected" message on my Nokia.

What is strange is that when my server app. is running on my Nokia, as soon as I turn on the BT search function on my second device, I see the border of the BT logo on my Nokia phone flash once, implying that it has detected a signal, however I get no message and no connection is made.

My second device can pair with Nokia phone normally, without my application.

I have no problems with running the exact same server app. on my LG phone. Any ideas what is wrong with my app.?
Reply With Quote

#2 Old Re: Why not work on Nokia but does on LG? - 2009-01-21, 09:32

Join Date: Mar 2003
Posts: 16,947
Location: Bangkok
symbianyucca's Avatar
symbianyucca
Offline
Forum Nokia Expert
Maybe you should debug it and see which lines do get executed, and if there is any error returned by any code lines, or leaves..
Reply With Quote

#3 Old Re: Why not work on Nokia but does on LG? - 2009-01-21, 18:09

Join Date: Dec 2008
Posts: 3
the_ether
Offline
Registered User
Quote:
Originally Posted by symbianyucca View Post
Maybe you should debug it and see which lines do get executed, and if there is any error returned by any code lines, or leaves..
There are no errors. I see the message, "Started as server..." but then the system hangs in the following line,

sc = scn.acceptAndOpen()

If there was an error then an exception would have been raised by that line.
Reply With Quote

#4 Old Re: Why not work on Nokia but does on LG? - 2009-01-21, 18:45

Join Date: Mar 2003
Posts: 16,947
Location: Bangkok
symbianyucca's Avatar
symbianyucca
Offline
Forum Nokia Expert
ok, maybe you could then check the Nokia examples that are working in Nokia devices, and see what you are doing differently.
Reply With Quote

#5 Old Re: Why not work on Nokia but does on LG? - 2009-02-04, 22:06

Join Date: Jul 2007
Posts: 6
hassonrobert
Offline
Registered User
I am having exactly the same problem.

I have a 3rd party device that sends data over Serial Port.
I created a BTSPP server to receive the strings from the device.
I only changed the name of the server string from the original Nokia Sample Server code (as you can see from the code below)

The btspp server works on a S60 (E73) and receives the string from the device while it still hangs on the "wait connection" on S40 (6131).

I see the border on the BT logo turn on when the client connects to the phone but the Server does not "catch" it. When I launch the BT client (also from the sample projects) on another S40 it does find the BTSPP server and connects to it. It also finds 2 other services (3:COM1 and 15:Nokia PC suite)

Similarly my XP SP2 pc when exploring services does not discover a Serial Port service exposed by the 6131. It only sees the "COM1" and the "PC Suite port".


Is there a difference in the way the s40 BT stack behaves from the s60? What is puzzling is that it does work between a client that runs on s40...

Thanks in advance for your support



Code:


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.bluetooth.DiscoveryAgent;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.UUID;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.microedition.io.StreamConnectionNotifier;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

/**
 * A class that demonstrates Bluetooth communication between server mode PC and
 * client mode device through serial port profile.
 * 
 * @see <a href="http://sourceforge.net/projects/bluecove/">BlueCove - JSR-82
 *      implementation</a>
 */
public class DeviceServerCOMM extends MIDlet {

	/*-
	 * ================
	 * Bluetooth Server
	 * ================
	 * 
	 * This example application is a straighforward implementation of 
	 * a bluetooth server.
	 * 
	 * 
	 * Usage
	 * =====
	 * 
	 * Start the program. Events are logged by printing them out with standard 
	 * output stream. Once the server is up and ready to accept connections, 
	 * connect to server with client.
	 * 
	 * 
	 * How it Works
	 * ============
	 * 
	 * The application starts a loop to wait for a new connection. After a new 
	 * connection is reseived the connection is handled. In the handling 
	 * operation few tokens and end token is written to connection stream. 
	 * Each read token is logged to standard output. After handling session 
	 * the loop continues by waiting for a new connection.
	 * 
	 */

	/*-
	 * 
	 * ---- Bluetooth attributes ----
	 */

	// serial port profile
	protected String UUID = new UUID("1101", true).toString();
        
	protected int discoveryMode = DiscoveryAgent.GIAC; // no paring needed

	/*-
	 * 
	 * ---- Connection handling attributes ----
	 */
	protected int endToken = 255;

	/*-
	 * 
	 * ---- User interface attributes ----
	 */
	protected Form infoArea = new Form("Bluetooth Server");
	
	
	protected void startApp() throws MIDletStateChangeException {
		infoArea.deleteAll();
		Display.getDisplay(this).setCurrent(infoArea);
		
		try {
			LocalDevice device = LocalDevice.getLocalDevice();
			device.setDiscoverable(DiscoveryAgent.GIAC);

			String url = "btspp://localhost:" + UUID + ";name=OCR";

			log("Create server by uri: " + url);
			StreamConnectionNotifier notifier = (StreamConnectionNotifier) Connector
					.open(url);

			serverLoop(notifier);

		} catch (Throwable e) {
			log(e);
		}
	}

	protected void pauseApp() {
	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
	}

	private void serverLoop(StreamConnectionNotifier notifier) {
		try {
			while (true) { // infinite loop to accept connections.
				log("Waiting for connection...");
				handleConnection(notifier.acceptAndOpen());
			}
		} catch (Exception e) {
			log(e);
		}
	}

	private void handleConnection(StreamConnection conn) throws IOException {
		OutputStream out = conn.openOutputStream();
		InputStream in = conn.openInputStream();
		startReadThread(in);

		try { // to write some tokens through the bluetooth link
			int[] tokens = new int[] { 1, 3, 5, 7, endToken };
			for (int i = 0; i < tokens.length; i++) {
				out.write(tokens[i]);
				out.flush();
				log("write:" + tokens[i]);
				// wait a sec before next write.
				Thread.sleep(1 * 1000);
			}
		} catch (Exception e) {
			log(e);
		} finally {
			log("Close connection.");
			if (conn != null) {
				try {
					conn.close();
				} catch (IOException e) {
				}
			}
		}
	}

	private void startReadThread(final InputStream in) {
		Thread reader = new Thread() {
			public void run() {
				try {
					while (true) {
						int r = in.read();
						log("read:" + r);
						if (r == endToken)
							break;
					}
				} catch (Throwable e) {
					log(e);
				} finally {
					if (in != null) {
						try {
							in.close();
						} catch (IOException e) {
						}
					}
				}
			}
		};
		reader.start();
	}

	/*-
	 *   -------  Utility section -------
	 */

	synchronized private void log(String msg) {
		infoArea.append(msg);
		infoArea.append("\n\n");
	}

	private void log(Throwable e) {
		log(e.getMessage());
	}

}
Reply With Quote

#6 Old 2009-02-05, 12:21

Join Date: Mar 2003
Posts: 2,617
traud
Offline
Super Contributor
Quote:
Originally Posted by hassonrobert View Post
I created a BTSPP server to receive the strings from the device.
If there are several services with UUID 0x1101 like in Series 40 (and in the latest S60 editions), how should the remote device know which one to choose?
Last edited by traud : 2009-10-06 at 16:01.
Reply With Quote

#7 Old Re: Why not work on Nokia but does on LG? - 2009-02-09, 13:05

Join Date: Jul 2007
Posts: 6
hassonrobert
Offline
Registered User
Traud,
thanks for your interest. The remote Service looks for a service with "OCR" in the name. Again this seems to do the trick with the S60 but not the S40...

Is there a way to kill the "com1" and "pc suite" competing services on the s40?
Reply With Quote

#8 Old 2009-02-09, 21:57

Join Date: Mar 2003
Posts: 2,617
traud
Offline
Super Contributor
Do you mean a Nokia N73? Does that have a SPP profile at all?
Last edited by traud : 2009-10-06 at 16:00.
Reply With Quote

#9 Old Re: Why not work on Nokia but does on LG? - 2009-02-10, 11:23

Join Date: Jul 2007
Posts: 6
hassonrobert
Offline
Registered User
Sorry I meant E71. Is SPP not supported by all JSR82?
In any case on the E71 the communication between the device and the phone worked proving that it does have a BTSPP and that it works on that device. Again still puzzled as to why it is not working on 6131 (S40).

Could we turn off the COM1 and PC Suite SPP that are it seems by default active on the 6131 and maybe interfering with the 3rd party device that is trying to connect?

Thx
Reply With Quote

#10 Old 2009-02-10, 15:31

Join Date: Mar 2003
Posts: 2,617
traud
Offline
Super Contributor
Any phone supporting the Bluetooth part of JSR-82 supports the RFComm protocol. No serial-port (0x1101) based service (profile) must registered in the SDP. Mobile phones do not need a SPP at all, normally. DUN or any other profile is the trick. Do not mix protocol with profile.
Last edited by traud : 2009-10-06 at 16:00.
Reply With Quote

#11 Old Has this ever been resolved? - 2009-05-03, 18:24

Join Date: May 2009
Posts: 1
mkaz
Offline
Registered User
We too, experience the exact same problem.
We are writing a mobile phone application that accepts data from a 3rd party device. The 3rd party device uses SPP and is looking for a certain name.
With S60 this works while with S40 it does not.
In S60 using 1101 (=SPP) only 1 service is returned while S40 returns 3 (our service, the 'normal' SPP serice and the Nokia PC Center service).
We can control the service record created by us but have not been able to find out how to control the other 2.
We hoped that if we somehow would manage to disable or remove (and later restore) the additional, unwanted, services, the 3rd party device would find our service and connect.
This may be cause by the order SDP presents the services to the 3rd party devive, as stated in the last reply, but we have been unable to find ways to control this.
I would be nice to receive more detailed information and, if the first 2 posters managed to solve the issue, to find out how.

Thanks
Reply With Quote

#12 Old 2009-10-06, 15:56

Join Date: Mar 2003
Posts: 2,617
traud
Offline
Super Contributor
Quote:
Originally Posted by mkaz View Post
The 3rd party device uses SPP …
Rather than fixing the wrong part (Nokia), you should fix the one which is wrong (your 3rd party device).

Your 3rd party device should not just look for a generic UUID. If you do something special, then you create your own service with its own (long private) UUID. This service is then offered by your MIDlet and your remote device looks for and connects to that. This is not the fault of Nokia and cannot be resolved. You have to enhance your 3rd party device. Either to look for all SPP services (and their names) or better to look for one special service (your own UUID). For example since Symbian/S60 3rd Edition Feature Pack 2, there will be three SPP, too.
Quote:
Originally Posted by mkaz View Post
… and is looking for a certain name.
I see no reason why that should not work. However in Series 40, if you specify
Code:
UUID uuid = new UUID(0x1101L);
String name = "btspp://localhost:" + uuid.toString();
StreamConnectionNotifier notifier = Connector.open(name);
the 128 bit UUID variant is added to the service record (attribute 0x0001).
Code:
0000110100001000800000805f9b34fb
If your remote device does not detect this as valid SPP, then it has a bug. Furthermore, do not use the following code
Code:
String name = "btspp://localhost:1101";
as the following is added then:
Code:
00000000000000000000000000001101
By the way, if you use 0x1101L as your only UUID, you should manipulate attribute 0x0001 manually, as you would have two 0x1101L in that attribute.
Code:
ServiceRecord r = localDevice.getRecord(notifier);
DataElement d = new DataElement(DataElement.UUID, uuid);
DataElement e = new DataElement(DataElement.DATSEQ);
e.addElement(d);
boolean b = r.setAttributeValue(0x0001, e);
StreamConnection connection = notifier.acceptAndOpen();
And yes, Series 40 has a bug here as the JSR-82 specification mandates a 16 bit UUID for ‘ServiceClass1’ and Nokia appends a 128 bit one, too. Tested in Series 40 6th Edition; latest firmware of today. I guess this 128 bit versus 16 bit UUID is the problem you face. Disabling (no idea how to do that) the other SPP records would not help either. This is a bug in your remote device and Series 40 trapped it.
Last edited by traud : 2009-10-06 at 16:08.
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
which phones for laptop dvdljns PC Suite API and PC Connectivity SDK 2 2006-02-14 13:58
Nokia PC Connectivity能否链接到cdma手机上发送短信和其他操作? bborn Web Technologies and Multimedia Content- Web 技术和多媒体内容 2 2004-05-04 12:06
Nokia 7650 support Bluetooth audo? ovjo12 Bluetooth Technology 5 2003-07-17 19:50

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia