×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    13

    Using RFCOMM - help!

    Hi,

    I have been in here looking for some answers on OBEX for a couple of weeks now, but I only just came across an article that stated that if I wish to send commands (AT COmmands in my case) that I should be using RFCOMM and not OBEX... (thats 2 weeks I'll never get back!)

    So I'm changing my tactics to RFCOMM, but I'm a little stuck...

    I do the device discovery / service discovery, but I'm getting caught in this part of the code:

    Code:
    private static void deploy(String address) throws IOException {	 
    	        
    		UUID uuid = new UUID("1101",true);
    		if (!address.startsWith("btgoep://0060579E9ACC:9" + uuid + ";authenticate=false;master=false;encrypt=false"))
    			//if (!address.startsWith("btgeop:////0060579E9ACC:9;authenticate=false;master=false;encrypt=false"))
    			throw new IllegalArgumentException("address " + address
    					+ " this does not look like an OBEX address");
    
    		ClientSession cs = (ClientSession) Connector.open(address);
    		HeaderSet hs = cs.createHeaderSet();
    		hs.setHeader(HeaderSet.COUNT, new Long(2));
    		HeaderSet response = cs.connect(hs);
    		try{
    	//		if (response.getResponseCode() != ResponseCodes.OBEX_HTTP_OK) {
    	//			System.err.println("Failed to connect "
    	//				+ response.getHeader(HeaderSet.DESCRIPTION));
    	//		} else {
    				System.out.println("Sending AT Command to " + address);
    			 
    			 String lfcr = "\r\n";
    			 byte[] data =("ATEO" + lfcr).getBytes();
    			 //byte[] data =("AT+CPIN").getBytes();
    			 //byte[] data =("AT+CMGF=0").getBytes();
    			 // byte[] data = ("AT+CPIN=\"" + pinNumber + "\"", 0, 1000).getBytes();
    			 
    			 
    		
    			 HeaderSet header = cs.createHeaderSet();
    			 header.setHeader(HeaderSet.NAME, "micktest");
    			 header.setHeader(HeaderSet.TYPE, "text");
    			 header.setHeader(HeaderSet.LENGTH, new Long(data.length));
    			
    			 Operation putOperation = cs.put(header);
    			 OutputStream outputStream = putOperation.openOutputStream();
    			 outputStream.write(data);
    			// outputStream.close();
    			 
    			 System.out.println("Response code is : "+putOperation.getResponseCode());
    			 putOperation.close();			 
    //			}
    		} finally {
    			if (null != cs) {
    				cs.disconnect(null);
    				cs.close();
    			}
    		}
    	}
    I'm not sure, because I simply changed the code to 1101 that its using RFCOMM or not. I know its supposed to be 0x1101 but it would not accept the 0x ?

    I then set this line above the code :

    Code:
    static final UUID RFCOMM_UUID = new UUID(0x1101);
    Still no joy!

    I'm getting errors pointing to this line
    Code:
    throw new IllegalArgumentException("address " + address
    Should I be doing more to use RFCOMM or is it a case of simply changing the UUID code? And is it ever being used or called...

    Thanks for any help!

    DG.

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    13

    Re: Using RFCOMM - help!

    OMG your the man...

    Its nearly there! (I hope!)

    That thread was perfect. I changed the codes in RFCOMM, I tried both 1103 and 111F (I put 111F as 0x111F, is that right?)

    Unfortunately I'm not all the way there... I think a little more tweaking and I might have it...

    Here is me code so far (if anybody has a Nokia 6310i can you please test )

    Code:
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;
    import javax.microedition.io.Connector;
    import javax.microedition.io.StreamConnection;
    
    
    
    public class AtSend {
    
        public static void main(String[] args) throws IOException, InterruptedException {
    
            String serverURL = "btspp://0060579E9ACC:3;authenticate=false;encrypt=false;master=false";
            if ((args != null) && (args.length > 0)) {
                serverURL = args[0];
            }
            if (serverURL == null) {
                String[] searchArgs = null;
                // Connect to OBEXPutServer from examples
                // searchArgs = new String[] { "11111111111111111111111111111123" };
                ServicesSearch.main(searchArgs);
                if (ServicesSearch.serviceFound.size() == 0) {
                    System.out.println("Service not found");
                    return;
                }
                // Select the first service found
                serverURL = (String)ServicesSearch.serviceFound.elementAt(0);
            }
    
    
            System.out.println("Connecting to " + serverURL);
    
           // ClientSession clientSession = (ClientSession) Connector.open(serverURL);
           // HeaderSet hsConnectReply = clientSession.connect(null);
        //    if (hsConnectReply.getResponseCode() != ResponseCodes.OBEX_HTTP_OK) {
          //      System.out.println("Failed to connect");
         //       return;
         //   }
      
          StreamConnection connection = (StreamConnection) Connector.open(serverURL);
        
          OutputStream out = connection.openOutputStream();
          InputStream in = connection.openInputStream();
         
          String message = "AT\r";
          
          byte buffer[] = new byte[10000];  
          
          out.write(message.getBytes());
          
          out.flush();
          out.close();
    
          // read the response from mobile phone
          in.read(buffer);
      	 //System.out.println(buffer.toString());
      	  System.out.println("AT Command Response : " + in.read());
      	  connection.close();
     //  } 
      // catch (Exception e)
     //  {
     //     e.printStackTrace();
     //  }
    
            
            
            
         //   HeaderSet hsOperation = clientSession.createHeaderSet();
        //    hsOperation.setHeader(HeaderSet.NAME, "Hello.txt");
         //   hsOperation.setHeader(HeaderSet.TYPE, "text");
    
            //Create PUT Operation
          // Operation putOperation = clientSession.
    
            // Send some text to server
            //byte data[] = "Hello world!".getBytes("iso-8859-1");
          // String lfcr = "\r\n";
           // byte[] data =("ATEO" + lfcr).getBytes();
            
            
    
        	//connection.close();
        }
    }
    This code established a connection (still requiring pairing, but I can figure that bit out later...)

    Problem is now, when running "AT\r" I'm not getting back AT OK... I'm getting :

    Code:
    Connecting to btspp://0060579E9ACC:3;authenticate=false;encrypt=false;master=false
    BlueCove version 2.0.3 on widcomm
    AT Command Response : 13
    BlueCove stack shutdown completed
    What is 13?

    Thanks.

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    13

    Re: Using RFCOMM - help!

    OK, this is weird!

    No I'm getting a different response code of 75?

    Code:
    Connecting to btspp://0060579E9ACC:3;authenticate=false;encrypt=false;master=false
    BlueCove version 2.0.3 on winsock
    Output Stream : com.intel.bluetooth.BluetoothRFCommOutputStream@ef22f8
    Input Stream  : com.intel.bluetooth.BluetoothRFCommInputStream@1e0cf70
    AT Command Response : 75
    BlueCove stack shutdown completed
    Anybody any clues as to what these are, why I'm getting them and why I'm just not getting back the simple "AT OK" response?

    I'm running this as a college proj and I'm using a Nokia 6310i with old (unfixed firmare) of V5.51, so this makes it the most vulnerable phone out there!

    I'm cracking up!

    DG.

  5. #5
    Registered User
    Join Date
    Jul 2008
    Posts
    13

    Re: Using RFCOMM - help!

    Hi,

    Sorry for all the replies to my own thread... I'm hoping somebody can pick it up at the right time to offer the help I need...

    After the trouble with the random numbers... which actually turned out to be AT OK, but in binary and split across several lines, I finally managed to figure out the buffer output and convert it to gods great English

    So only problem I have now is finding good old AT Commands that will send back some useful information!

    Does anybody know any for the Nokia that will send back Phonebook and maybe SMS messages!

    I read something about the phone contacts needing to be on the SIM and not the phone to read them...

    Any help at this final hurdle would be very much appreciated!

    Project is nearly done and I'm a happy out!

    DG.

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105

  7. #7
    Registered User
    Join Date
    Jan 2006
    Posts
    11

    Re: Using RFCOMM - help!

    I am having the same problem. I could get proper response-message in response to "AT\r" command.
    I am getting strange characters but "OK".

  8. #8
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    mmc18, could you please explain your situation in more detail. I do not understand you last sentence.

Similar Threads

  1. Connection problem with RFCOMM : error -6305
    By tsrasanen in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2007-05-11, 16:29
  2. Bluetooth: confirmation message on incoming RFCOMM connections
    By pracucci in forum Mobile Java Networking & Messaging & Security
    Replies: 10
    Last Post: 2007-05-07, 20:09
  3. Is L2CAP worth the extra effort?
    By ed_welch in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2007-02-23, 10:02
  4. Is it possible to listen multiple RFComm socket as a Bluetooth Slave?
    By makmake in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2007-01-24, 10:07
  5. RFCOMM Channel Request
    By dphj in forum Bluetooth Technology
    Replies: 1
    Last Post: 2004-03-17, 10:33

Posting Permissions

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