Comment on Tutorial - How to Send SMS using Java Program (full code sample included) By Emiley J.



Comment Added by : Razvan

Comment Added at : 2010-10-13 06:04:24

Comment on Tutorial : How to Send SMS using Java Program (full code sample included) By Emiley J.
Hi,
I run the program on windows (connecting to a phone through bluetooth) and I had the sane errors but I managed to solve the problems as follows:
1. javax.comm.* is not supported on windows anymore and I replaced it with this jar: rxtx-2.1-7-bins-r2.zip downloaded from http://rxtx.qbang.org/wiki/index.php/Download
2. edited the code to for the new jar: I added import gnu.io.*; in the SerialParameters.java file
3. I edited the Sender.java file:
- set the message center number and the port
- I modified public void run() function to change the AT commands:
public void run(){

boolean timeOut=false;
long startTime=(new Date()).getTime();



while ((step <7) && (!timeOut)){
// log(""+((new Date()).getTime() - startTime);
//check where we are in specified delay
timeOut=((new Date()).getTime() - startTime)>delay;

//if atz does not work, type to send cntrlZ and retry, in case a message was stuck
if (timeOut && (step==1)) {
step=-1;
mySerial.send( ""+cntrlZ);
}

//read incoming string
String result= mySerial.getIncommingString() ;

// log ("<- "+result+"\n--------");
int expectedResult=-1;

try{
//log ("Step:"+step);

switch (step){
case 0:

mySerial.send("AT");
delay=LONG;
startTime=(new Date()).getTime();
break;
case 1:
expectedResult=result.indexOf("OK");

//log ("received ok ="+expectedResult);
if (expectedResult>-1){
mySerial.send("AT+CMGF=1");
startTime=(new Date()).getTime();
}else{
step=step-1;
}
break;
case 2:
expectedResult=result.indexOf("OK");

// log ("received ok ="+expectedResult);
if (expectedResult>-1){
mySerial.send("AT+CMGW=\""+recipient+"\"");
startTime=(new Date()).getTime();
}else{
step=step-1;
}

break;
case 3:
expectedResult=result.indexOf(">");

// log ("received ok ="+expectedResult);
if (expectedResult>-1){
mySerial.send(message+cntrlZ);
startTime=(new Date()).getTime();
}else{
step=step-1;
}
delay=VERYLONG;//waitning for message ack

break;

case 4:
//log ("received ="+result.toString());
expectedResult=result.indexOf("+CMGW:");
//read message number
if (expectedResult>-1){
int n=result.indexOf("+CMGW:");
result=result.substring(n+7);
n=result.indexOf("\n");
status=0;
messageNo=Long.parseLong(result.substring(0,n).trim() );
mySerial.send("AT+CMSS="+messageNo);
startTime=(new Date()).getTime();
log ("sent message no:"+messageNo);
}else{
step=step-1;
}

break;
}
step=step+1;

aThread.sleep(100);

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

Try the AT commands with HyperTerminal to check if it works, this is how I discovered the problems.

Hope it will help you.


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. Very helpful and easily understandable!
View Tutorial          By: Teerna at 2014-11-12 23:55:49

2. what is differences between application scope and
View Tutorial          By: suresh at 2013-05-13 13:03:12

3. Thanks, It's exactly. A my friends has the same is
View Tutorial          By: Slim at 2012-09-29 02:52:12

4. your code error

because i try to ru

View Tutorial          By: Nasser at 2013-01-09 10:33:34

5. I am using RMS but in my case i have to show 10 re
View Tutorial          By: Hemant at 2012-08-14 05:46:40

6. I really thanks to you for providing wonderful inf
View Tutorial          By: Chandra Sekhar Puli at 2009-11-07 04:03:44

7. Hi i am sanjay ,
I got the exact difference

View Tutorial          By: Sanjay Patel at 2012-05-06 11:36:00

8. good explanation .... Thanks
View Tutorial          By: nazeer at 2012-05-24 09:18:19

9. Thanks very much, this helped alot.
View Tutorial          By: Steve at 2012-10-09 21:09:16

10. hi there, i was testing your code-samples,

View Tutorial          By: Douglas at 2011-04-07 22:35:56