You Are Here:

Community: Developer Discussion Boards

Reply « Previous Thread | Next Thread »

#1 Old Question send AT-commands via Bluetooth with Java programm - 2007-07-05, 00:34

Join Date: Mar 2006
Posts: 11
zhchinde
Offline
Registered User
Hello all,

I'm trying to write a program which should send AT-commands to a mobile phone via bluetooth. I use JSR-82 as API. The program establishes a SPP connection to the mobile phone and sends the AT-commands as a string. But the mobile phone does'nt response to the AT-commands. Is it possible to send AT-commands through a SPP connection? How can I receive a response from the mobile phone, if it gives me one?

here is the sending code:

try{
// connectionURL is got from service discovery, //servRecord.getConnectionURL(1,false)

connection = (StreamConnection) Connector.open(connectionURL);

OutputStream out = connection.openOutputStream();
InputStream in = connection.openInputStream();

String message = "ATD123445678";// AT-command to dial 12345678

// send AT-command
out.write(message.getBytes());

out.flush();
out.close();

byte buffer[] = new byte[10000];
// read the response from mobile phone
in.read(buffer);
System.out.println(buffer.toString());

connection.close();
} catch (Exception e){
e.printStackTrace();
}


Is there some thing wrong in the code? Why did the mobile phone not response to the AT-command?

thanks for any tips!
Reply With Quote

#2 Old Re: send AT-commands via Bluetooth with Java programm - 2007-07-05, 18:32

Join Date: Dec 2004
Posts: 228
matrix241
Offline
Regular Contributor
what's active on the receiving phone? is there a midlet that gets data?
In case there isn't a midlet that elaborates the bytes that are coming, you will not have an answer. No automatical elaboration.
Reply With Quote

#3 Old Re: send AT-commands via Bluetooth with Java programm - 2007-07-06, 01:20

Join Date: Mar 2006
Posts: 11
zhchinde
Offline
Registered User
Quote:
Originally Posted by matrix241
what's active on the receiving phone? is there a midlet that gets data?
In case there isn't a midlet that elaborates the bytes that are coming, you will not have an answer. No automatical elaboration.

thank you for the answer.

I thought that every GSM device implements the AT-Commands, response to AT-Commands automatically. Is it not right?
Reply With Quote

#4 Old 2007-07-07, 09:48

Join Date: Mar 2003
Posts: 2,766
traud
Offline
Super Contributor
Quote:
Originally Posted by zhchinde
The program establishes a SPP connection to the mobile phone
DUN!
Furthermore, some mobile phones need a moment to have the AT parser started and some need a wake-up AT command. So just wait half a second, send an AT and then send the rest. However, then you have a lot of fun to code: PPP, IP, TCP, HTTP, … what do you want to achive, actually?
Reply With Quote

#5 Old Re: send AT-commands via Bluetooth with Java programm - 2007-07-07, 19:34

Join Date: Mar 2006
Posts: 11
zhchinde
Offline
Registered User
Quote:
Originally Posted by traud
then you have a lot of fun to code: PPP, IP, TCP, HTTP, … what do you want to achive, actually?
why that? I don't have fun to code tcp, http I am just trying to finish my homework :-)

I have tried to send AT and wait, no reponse either...
I'm doubting that the mobile phones would not reply a string which was sent via Bluetooth spp. The AT-commands must be sent in a certain format or so...

How to send AT-commands, so that the phone replies?
Reply With Quote

#6 Old 2007-07-09, 11:27

Join Date: Mar 2003
Posts: 2,766
traud
Offline
Super Contributor
If you do not believe me, than I am no help for you, anyway, I try:
Where is the carrige return ('\r') after sending the AT command?

SPP does not mean there is an AT command layer, however, in mobile phones it is normally. SPP does not mean there is ATD support, however, in mobile phones there is normally. Nevertheless, a good programmed mobile phone does not need/have a SPP, just DUN not to confuse user. DUN does everything SPP would do on a mobile phone. There is no need to have SPP and many phones out there do not have SPP. Furthermore, SPP is a quite generic profile. Many devices have several SPP based services and it is rather luck which you get in JSR-82.

At the conclude: After dialling this number, the phone will start PPP and talk PPP to you. Then you talk IP, then TCP and then (most of the time) HTTP. This way it is rather useless. I guess you want to start a voice rather than a data call: Append a semicolon at the end of the number.
Last edited by traud : 2007-09-18 at 21:26. Reason: Removed a misunderstanding and bug of the carriage return.
Reply With Quote

#7 Old Re: send AT-commands via Bluetooth with Java programm - 2007-09-17, 14:33

Join Date: Mar 2006
Posts: 11
zhchinde
Offline
Registered User
Thank you again traud.

Can you tell me how can i build a DUN connection with Java Blutooth API?
Reply With Quote

#8 Old 2007-09-17, 19:54

Join Date: Mar 2003
Posts: 2,766
traud
Offline
Super Contributor
In the service search you change your UUID to 1103 for DUN or 111F for Hands-Free. Anyway, what do you want to achive actually?
Reply With Quote

#9 Old Re: send AT-commands via Bluetooth with Java programm - 2007-09-18, 00:47

Join Date: Mar 2006
Posts: 11
zhchinde
Offline
Registered User
traud,

I want to achieve a small program for a PC with bluetooth dongle, which can send AT commands to a Bluetooth mobile phone and receive, show the response from the mobile phone. Just like a very basic HyperTerminal.

Now I can send String "AT" via Bluetooth with SPP profile to the mobile phone. I can see a symble on the mobile phone, that it has a BT connection, but I could not receive any response.

I will try the DUN connection. Thank you.
Last edited by zhchinde : 2007-09-18 at 16:43.
Reply With Quote

#10 Old Re: send AT-commands via Bluetooth with Java programm - 2007-09-18, 00:54

Join Date: Mar 2006
Posts: 11
zhchinde
Offline
Registered User
traud,

I tried to use the DUN connection, but there was the same problem. No response was got.

Could you please tell me what did you mean by "Where is the carrige return (0x13) after sending the AT command?" Did you mean, that I should send String "AT 0x13" instead of "AT"?

I am really not good at this, sorry for the stupid questions. Thank you.
Reply With Quote

#11 Old 2007-09-18, 21:20

Join Date: Mar 2003
Posts: 2,766
traud
Offline
Super Contributor
Append a '\r' at the end of each AT command. In HyperTerminal you do the same, you hit the return key after each command. This does not actually send the command, actually each character was send already and the typed return on the keyboard adds a return at the end of the command.
Code:
String command = "AT\r";
As this is a non-printing char, in Java-world you either use the shorthand '\r' or its Unicode character position '\u000D'.

Forget about 0x13, was my fault. ;)
Last edited by traud : 2007-09-18 at 21:37.
Reply With Quote

#12 Old Red face Re: send AT-commands via Bluetooth with Java programm - 2007-09-18, 23:49

Join Date: Mar 2006
Posts: 11
zhchinde
Offline
Registered User
thank you for the quick answer, traud.

Till now I have tried to search the service with UUID 0x1103 (DUN), and send string "AT\r" by using the URL, which was got from service discovery servRecord[i].getConnectionURL. But it still dose not work. No response can be received after "AT\r". Some tips else? ;-)
Reply With Quote

#13 Old Smile Re: send AT-commands via Bluetooth with Java programm - 2007-09-21, 16:14

Join Date: Mar 2006
Posts: 11
zhchinde
Offline
Registered User
It works now.

Sorry for my mistake. I thought there was problem by sending, but not. The problem was by reading. It means, using DUN to send "AT\r\n" was right. I just could not read the response correctly. Thank you for your help traud!

Now I am using

byte buffer[] = new byte[bufferLength];
inputStream.read(buffer);

to read the response. The problem here is that I must define the bufferLength before I will read. How can I read dynamicly just so much that the phone responses? Thanks for every help.
Reply With Quote

#14 Old 2007-09-22, 17:23

Join Date: Mar 2003
Posts: 2,766
traud
Offline
Super Contributor
Use Inputstream.read() without any parameter (or buffer) like
Code:
System.out.write(in.read());
This way you can use your application as a terminal emulation over Bluetooth. Use one thread for the System.in+Bluetooth.out and one for the Bluetooth.in+System.out streams. If this is really just an homework for school, this should be sufficient. More sophisticated only on request…

By the way it is "AT\r" and not "AT\r\n" and if a phone does not have DUN, fall back to its Hands-Free Gateway (111F).
Reply With Quote

#15 Old Smile Re: send AT-commands via Bluetooth with Java programm - 2008-07-14, 16:45

Join Date: Jul 2008
Posts: 3
RayKay
Offline
Registered User
Hello all ;)

I try the code in my Java Appl. to get informations from the mobile device via Bluetooth:
Code:
public void servicesDiscovered(int transID, ServiceRecord serviceRecord[])
	{
		String url = serviceRecord[0].getConnectionURL(1, false);
try
	    {
	    	//ClientSession conn= (ClientSession)Connector.open(url);
	    	StreamConnection meineVerbindung = (StreamConnection) Connector.open(url);
	    	
	        if(conn== null)
	        	System.out.println("Kann Service URL nicht oeffnen\n");
	        else
	        {
	        	
	        	OutputStream out = conn.openOutputStream();
				InputStream in = conn.openInputStream();
		
				String message = "AT+CGMI\r\n";

				// send AT-command
				System.out.println("send AT Comand request: "+message);
				out.write(message.getBytes());
		
				out.flush();
				out.close();
		
				byte buffer[] = new byte[10000];
				// read the response from mobile phone
				in.read(buffer);
				System.out.println("AT Comand response: "+buffer.toString());}            
	
	    }
	    catch(IOException e)
	    {
	    	System.out.println("Service Error(3): "+e.getMessage());
	    }
    
	}
AT+CGMI means to get the manufacturer of the mobile. This method is called by find a service after the serviceSearch:

UUID [] uuidList = new UUID[1];
uuidList[0] = new UUID(0x1103);

agent.searchServices(null, uuidList, RemoteDevice, this);

Now my problem is, that the mobile device ask for a identifier. I don't know this identifier. After press ok I get the follow error in my Java Appl.: "Failed to connect. [111] Connection refused" so I get no AT response ;(

Has anybody an idea?

Sorry for my bad english ;)
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 Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Java samples Hp and PC via Bluetooth neko_whisker Bluetooth Technology 1 2006-06-01 09:05
APIs/Parameters/Code-Snippet Needed To Send AT Commands for Series 60 C++? periakaruppan Nokia M2M 0 2005-04-27 11:26
APIs/Parameters/Code-Snippet Needed To Send AT Commands for Series 60 C++? periakaruppan Symbian Tools & SDKs 0 2005-04-27 11:16
send file via bluetooth using java yukselg Bluetooth Technology 1 2005-01-10 14:53
how to send mutiple sms using java? stevensp General Messaging 1 2003-09-29 10:16

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 © 2010 Nokia