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. when i copy paste your program or source code

View Tutorial          By: hello at 2010-07-09 18:56:23

2. Thanks for posting this :)
Being a noobie @

View Tutorial          By: C at 2008-06-23 18:17:26

3. Hello all,

I need the codes for sen

View Tutorial          By: Fionna at 2009-07-13 00:34:45

4. Hai,
dis is anu, dng final year. i need to

View Tutorial          By: anu at 2012-07-12 15:41:19

5. what about strings in J2ME ?
View Tutorial          By: Swapnil at 2012-07-20 09:19:15

6. I have already establish connection with mysql in
View Tutorial          By: shaishav at 2013-06-20 04:27:44

7. Wow, damn nice. It does everything, and the script
View Tutorial          By: Ethan Windsor at 2012-06-14 13:47:39

8. To the,
sir/mam, i want to do java certific

View Tutorial          By: CERTIFICATION OF JAVA at 2011-03-03 02:27:05

9. Thanks a lot for valuable program.


View Tutorial          By: Kailash at 2012-07-30 10:09:12

10. @ Qui:

You can set the CSS Style:
View Tutorial          By: hache at 2010-06-22 02:02:56