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
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
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
Count number of vowels, consonants and digits in a String in Java
Student marks calculation program in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program
Archived Comments
1. Hey Narayanan, maybe you should check out Vesijama
View Tutorial By: Benny Bottema at 2009-05-03 14:27:07
2. how to send data one pc to another with java progr
View Tutorial By: usman at 2011-05-14 01:31:31
3. Thanks mate !!!
-- Anish Sneh
View Tutorial By: Anish Sneh at 2010-08-18 07:42:56
4. thank you..........
View Tutorial By: ravi at 2010-01-29 23:27:39
5. Thanks...it was very helpful :)
View Tutorial By: Swathi at 2012-01-25 06:49:46
6. the best site i have found so far for clearing my
View Tutorial By: darkknight at 2013-06-05 05:54:10
7. Hi VIKRAM, You cannot use your sim card number the
View Tutorial By: Ramlak at 2007-03-29 00:38:55
8. The above example for abstract class is very good.
View Tutorial By: saafia at 2013-08-19 14:33:54
9. Good ,I like here! I send gmail with j
View Tutorial By: jackhexl at 2009-04-02 03:29:44
10. thanks a looooooooooooooooot
this can give
View Tutorial By: bhagabat at 2011-07-24 02:39:59