| Reply | « Previous Thread | Next Thread » |
|
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! |
|
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. |
|
Quote:
thank you for the answer. I thought that every GSM device implements the AT-Commands, response to AT-Commands automatically. Is it not right? |
|
Quote:
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? |
|
Quote:
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? |
|
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.
|
|
Thank you again traud.
Can you tell me how can i build a DUN connection with Java Blutooth API? |
|
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?
|
|
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.
|
|
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. |
|
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"; Forget about 0x13, was my fault. ;)
Last edited by traud : 2007-09-18 at 21:37.
|
|
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? ;-) |
|
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. |
|
Use Inputstream.read() without any parameter (or buffer) like
Code:
System.out.write(in.read()); 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). |
|
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());
}
}
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 | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| 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 |