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



Related Tutorials

Java program to get location meta data from an image

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

Archived Comments

1. ,Hi, (VS2008, VB.Net
I used the above code,

View Tutorial          By: Pat at 2012-06-27 17:30:37

2. ya its good example
View Tutorial          By: vijaychellappa at 2010-11-10 04:57:42

3. Hi
I tried to use this class , I don't get

View Tutorial          By: Asela at 2012-01-26 19:05:14

4. thank you so much. i've been fixing this problem o
View Tutorial          By: yo at 2011-06-05 13:25:37

5. Please help I want to map the data say username an
View Tutorial          By: akshat at 2011-07-25 12:49:06

6. The concept is clear.
View Tutorial          By: sam at 2012-08-23 03:52:15

7. Works great, thanks! However, is there any way to
View Tutorial          By: MisterCrow at 2013-04-30 11:56:49

8. Hi! Sir.I am anish from Sultanpur.I want to Know t
View Tutorial          By: Anish at 2014-12-10 08:23:49

9. Thank you for a great explanation now I'm in the l
View Tutorial          By: C++Noob at 2011-12-22 04:43:31

10. thanks...helped a lot!!!!
View Tutorial          By: Sc21ac at 2013-05-03 03:44:06