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. what is the data type of the variable direction di
View Tutorial          By: [email protected] at 2009-12-25 03:07:46

2. hi gud mrng........
i wanna connectivity of

View Tutorial          By: sac at 2011-09-02 04:56:43

3. php-cgi.exe return popup "is not a valid Win3
View Tutorial          By: noob at 2013-06-30 09:47:38

4. Yes, as @ Mansi said it's really helpful.
I

View Tutorial          By: Eko SW at 2011-06-22 23:38:22

5. the example program that given above for recursion
View Tutorial          By: bharathi at 2012-07-17 09:31:14

6. Hi Ramlak,
I am using jdk1.4.2 to run the a

View Tutorial          By: mounika at 2008-04-27 03:05:36

7. today Iam getting time ,date of sending and "
View Tutorial          By: raghu at 2012-01-07 14:43:32

8. Very Nice Example...!!thanks
View Tutorial          By: Shafique khan at 2013-01-22 18:58:22

9. help me pls example ng c++ program code using do
View Tutorial          By: diana bernardo at 2010-10-15 23:34:19

10. Hi Steven. It looks like your example program does
View Tutorial          By: Ben Hallinan at 2008-04-25 08:36:42