Bluetooth Problems - InquiryError if GPS on, Service Discovery Problems..

Hey Guys!

I've tried to write a simple bluetooth programm, that can send strings between two phones, but nothing really wants to work on my benq/siemens C81(=S75) or E71!!!

first Problem is, as soon as my GPS Device Holux GPSlim236 is turned on, I can't perform a Device Search! It always returns InquiryError! if the gps is turned off, I can correctly detect a lot of other devices and search their services...but only if the gps is off o.o

these are parts of my code:

/***Eigene Bluetooth-Informationen anzeigen***/

// retrieve the local Bluetooth device object

LocalDevice local = LocalDevice.getLocalDevice();

// retrieve the Bluetooth address of the local device

String address = local.getBluetoothAddress();

// retrieve the name of the local Bluetooth device

Client.append("\n"+address+"\n"+ownname+"\n");

/***Bluetooth-Ger鋞esuche starten***/

//den DiscoveryAgent deklarieren

Client.append("\nStarting BT\n");

DiscoveryAgent agent = local.getLocalDevice().getDiscoveryAgent();

//letztes gefundenes Ger鋞

btDev =null;

//Damit das Array, das die gefundenen Ger鋞e enth鋖t, beschreibselt werden kann

FoundDevicesNum = 0;

//suche starten

agent.startInquiry(DiscoveryAgent.GIAC,this);

Client.append("\nSearching...\n");

.............

publicvoid deviceDiscovered(RemoteDevice remoteDevice, DeviceClass deviceClass){

btDev = remoteDevice;

//((Form)Display.getDisplay(this).getCurrent()).append(btDev.getBluetoothAddress()+"\n");

FoundDevices[FoundDevicesNum] = btDev;

FoundDevicesNum++;

}

publicvoid inquiryCompleted(int discType){

if (discType == DiscoveryListener.INQUIRY_COMPLETED)

{

if(btDev ==null){

((Form)Display.getDisplay(this).getCurrent()).append("No device has been discovered!");

}

else

{

//((Form)Display.getDisplay(this).getCurrent()).append("Inquiry completed.");

List FoundDevicesSelection =new List("Select Device",Choice.IMPLICIT);

for (int o=0;o<FoundDevicesNum;o++)

try{FoundDevicesSelection.append( FoundDevices[o].getFriendlyName(false),null);}

catch (IOException ex){Display.getDisplay(this).setCurrent(new Alert("!",ex.toString(),null,AlertType.INFO));}

FoundDevicesSelection.addCommand(new Command("Back", Command.BACK, 1));

FoundDevicesSelection.setSelectCommand(new Command("OK",Command.OK,0));

FoundDevicesSelection.setCommandListener(this);

Display.getDisplay(this).setCurrent(FoundDevicesSelection);

}

}else

if (discType == DiscoveryListener.INQUIRY_TERMINATED)

{((Form)Display.getDisplay(this).getCurrent()).append("\nInquiry Terminated");}

elseif (discType == DiscoveryListener.INQUIRY_ERROR)

{((Form)Display.getDisplay(this).getCurrent()).append("\nInquiry Error");}

}

Could anybody explain that to me? seems really strange...

And my next problem is, that on my phone everything seems to be a bit strange! I've only got 2 of my C81's and only one S/E W810i to test, but I cant find a server created on a C81 with a C81!

What works and what doesnt:

W810 creates Server - C81 uses normal Device Search, then Service Search - it detects normal SerialPort and my Server and runs PERFECTLY

W810 creates Server - C81 uses simple Service Search - it DOESNT find the server on the w810i

C81 creates Server - W810i uses normal Device Search, then Service Search - it only detects the devices default serialport, and NOT my own server....

C81 creates Server - W810i uses simple Service Search - it finds my own service and runs PERFECTLY

so, as you see, the other phone can only connect to the C81 server via simple service search, the device and then service search can't find the C81 server!

but also, on the C81 the simple service search doesn't work!

so right now I can't connect to C81's with each other, cause it simply doesnt work! I dont know if its of any help if I post my whole code...maybe I'll just post how the server is launched:

publicvoid run()

{

StringItem received_msg =null;

//SERVER krams

if (type.equals("server"))

{

String name ="JavaStars06";//the name of the service

String url ="btspp://localhost:" + uuid//the service url

+";name=" + name

+";master=false;authenticate=false;authorize=false;encrypt=false";

LocalDevice local =null;//?

StreamConnectionNotifier server =null;

byte buffer[] =newbyte[100];

try{

//((Form)Display.getDisplay(this).getCurrent()).append("\nSetting device discoverable...");

local = LocalDevice.getLocalDevice();

local.setDiscoverable(DiscoveryAgent.GIAC);

ownname = local.getFriendlyName();

//((Form)Display.getDisplay(this).getCurrent()).append("\nStart advertising service...");

server = (StreamConnectionNotifier)Connector.open(url);

// Retrieve the service record template

local.getRecord( server ).setAttributeValue( 0x0008,new DataElement( DataElement.U_INT_1, 0xFF ) );

// set ServiceAvailability (0x0008) attribute to indicate our service is available

// 0xFF indicate fully available status

// This operation is optional

((Form)Display.getDisplay(this).getCurrent()).append("\nWaiting for incoming connection...");

connection = server.acceptAndOpen();

((Form)Display.getDisplay(this).getCurrent()).deleteAll();

String othername = RemoteDevice.getRemoteDevice(connection).getFriendlyName(false);

//othername = "othername";

//ownname = "ownname";

((Form)Display.getDisplay(this).getCurrent()).append("\n"+othername+" connected!");

InputStream is = connection.openInputStream();

os = connection.openOutputStream();

while(true)

{

String cmd ="";

int m = is.read(buffer);

for (int i=0;i<m;i++ )

cmd = cmd + (char)buffer[i];

if (Chat.size()>1)

{

received_msg = (StringItem) Chat.get(Chat.size()-1);

if (received_msg.getLabel().equals(othername)==true)

{

received_msg.setText(received_msg.getText()+"\n"+cmd);

}

else

{

received_msg =new StringItem(othername, cmd);

received_msg.setLayout(Item.LAYOUT_NEWLINE_BEFORE);

received_msg.setFont(font);

Chat.append(received_msg);

}

}

else

{

received_msg =new StringItem(othername, cmd);

received_msg.setLayout(Item.LAYOUT_NEWLINE_BEFORE);

received_msg.setFont(font);

Chat.append(received_msg);

}

if (Display.getDisplay(this).getCurrent().getTitle().equals("BT-Test")==true)

{ Chat.append("\nshutdown thread");break;}

}

connection.close();

}catch (Exception e){Chat.append("Exception Occured: " + e.toString());}

}

[11424 byte] By [MTiNa] at [2007-11-26 12:42:34]
# 1
What do you mean by "simple Service Search"?
hnipaka at 2007-7-7 16:17:20 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2

oh sorry, must have forgotten to post that :)

private String BluetoothSimpleServerSearch()

{

String result = null;

try

{result = LocalDevice.getLocalDevice().getDiscoveryAgent().selectService(uuid,ServiceRecord.NOAUTHENTICATE_NOENCRYPT,false);}

catch (BluetoothStateException ex) {MainMenu.append(ex.toString(),null);}

return result;

}

thats how the simple service search looks like - insted of looking for all nearby devices and then searching through their services I just use that single line of code to select the first service of that kind the device finds! then it returns the connection url...

thats the only way the w810i can find my server created on a siemens s75!

but un my s75, it doesn't seem to work (at least I can't find the server on the 810i), insted, the more complex device and service search works...

I really need some help =((

Message was edited by:

MTiN

MTiNa at 2007-7-7 16:17:20 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3

I think I've read somewhere that "simple service search" should be avoided as it is unreliable (or whatever - http://developers.sun.com/learning/javaoneonline/2005/mobility/TS-3234.pdf).

How do you do "normal" service search after device discovery - what values do you use in agent.searchServices()?

hnipaka at 2007-7-7 16:17:20 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4

private void BluetoothServiceSearch() throws BluetoothStateException

{

//DiscoveryAgent agent = LocalDevice.getLocalDevice().getDiscoveryAgent();

List FoundServicesSelection = new List("Select Service URL",Choice.IMPLICIT);

FoundServicesSelection.addCommand(new Command("Back", Command.BACK, 1));

FoundServicesSelection.setSelectCommand( new Command("OK",Command.OK,0));

FoundServicesSelection.setCommandListener(this);

Display.getDisplay(this).setCurrent(FoundServicesSelection);

try {FoundServicesSelection.append("Searching "+btDev.getFriendlyName(false),null);} catch (IOException ex) {FoundServicesSelection.append(ex.toString(),null);}

int attrSet[] = {0x0100};//this attribute will return the service name

UUID uuidSet[] = {new UUID(0x1101)};

LocalDevice.getLocalDevice().getDiscoveryAgent().searchServices(attrSet,uuidSet,btDev,this);

}

as you see, I search for all Serial Port Services...but it doesn't work either if I search for the exact service uuid....

and that also wouldn't explain why already the Device search crashes if my gps mouse is on! The Device Search works in several GPS Midlets that I've got, e.g. trekbuddy but I've already emailed the author and he didn't answer me...

MTiNa at 2007-7-7 16:17:20 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5
That's true, that's no explanation for crash during discovery.I can send you code I use in the program you've have mentioned if you like, just send me an e-mail (kruhc@... ) directly, not via forum, I did not know whom to reply to :-)
hnipaka at 2007-7-7 16:17:20 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6

thank you very much!

just sent the email, I hope you got it, cause currently I'm having some serious problems with gmail, some people simply won't get my mails...

but nevertheless...why is this **** bluetooth implementation so bad on siemens mobile phones...everything works so nice in the emulator and on the sony ericcson cells :(

MTiNa at 2007-7-7 16:17:20 > top of Java-index,Java Mobility Forums,Java ME Technologies...