| Reply | « Previous Thread | Next Thread » |
|
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.? |
|
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..
|
|
Quote:
sc = scn.acceptAndOpen() If there was an error then an exception would have been raised by that line. |
|
ok, maybe you could then check the Nokia examples that are working in Nokia devices, and see what you are doing differently.
|
|
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());
}
}
|
| hassonrobert |
| View Public Profile |
| Find all posts by hassonrobert |
|
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.
|
|
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? |
| hassonrobert |
| View Public Profile |
| Find all posts by hassonrobert |
|
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 |
| hassonrobert |
| View Public Profile |
| Find all posts by hassonrobert |
|
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.
|
|
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 |
|
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.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); Code:
0000110100001000800000805f9b34fb Code:
String name = "btspp://localhost:1101"; Code:
00000000000000000000000000001101 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();
Last edited by traud : 2009-10-06 at 16:08.
|
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| 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 |