Hello Everyone!

Today I am going to tell you about how to Simply send SMS by using your HSDPA dongle or GSM modem. Cool! Isnt It? yes Its not that Difficult too. I have tried so many ways to Accomplish this problem. After so many Attempts I got the way to do. So well I will tell you how I have done that.




Basically this was created by using SMSLib which is an open source Library for Java. After studying the API I have created a Simple API Wrapper for the convenience of all of us. I have hosted the open source coding at Github with a sample Project named SMS.Dura.Wrapper. For this sample project I have made and used a Prebuilt Jar Library named smsdura-1.0.jar which works as the wrapper. So in your Project you have to do is simply import that smsdura-1.0.jar, just configure the modem, put the Message, TP and Send. Now SMS from Java? Its very easy as Ice Cream! :D  Don't worry. I will tell you how to do that. May be it will add more value for your project as well.

I will guide you rest of the Process.
Okay lets Start!

1. First of all you have to Download this Sample Project.

2. Now we have to copy few files in the <Extras folder> to your Java Classpath.[Normally JDKDIR can be found in > C:\Program Files\Java] So go to that path and do it as said. Detailed Instructions are listed below.

---------------------------   
    External Configurations for the JVM on the targeted machine. (Strictly Recommended!)
    [These files can be found in <extras> folder of the Project path.)
---------------------------

Java Comm Installation <comm dir>
-----------------------------------
    File comm.jar should go under JDKDIR/jre/lib/ext/
    File javax.comm.properties should go under JDKDIR/jre/lib/
    Library files (i.e. win32com.dll for Win32 or the .so Linux library files) should go under JDKDIR/jre/bin/
    If you have a separate JRE directory, do the same copies for the JREDIR directory!

RxTx Installation <rxtx dir>
-----------------------------------
    File RXTXcomm.jar should go under JDKDIR/jre/lib/ext/
    The necessary library (e.g.. for Linux 32bit, the librxtxSerial.so) should go under JDKDIR/jre/bin/
    If you have a separate JRE directory, do the same copies for the JREDIR directory!

huh! All the hard work has been done. be cool now :)

3. Okay now Simply open the Project from Netbeans IDE or whatever IDE you are using.

4. Importing the Required Dependencies. I have Imported all the Jars for this Project. So by default you have to do nothing with importing. But in your project you have to import few Jar files you can found in <lib> folder. You have to import all the Jars in that folder.

5. Okay done! Now take a look at this code.
package logic;

import com.harshadura.gsm.smsdura.GsmModem;

public class TestSMS {

    private static String port = "COM3"; //Modem Port.
    private static int bitRate = 115200; //this is also optional. leave as it is.
    private static String modemName = "ZTE"; //this is optional.
    private static String modemPin = "0000"; //Pin code if any have assigned to the modem.
    private static String SMSC = "+9477000003"; //Message Center Number ex. Mobitel

    public static void main(String[] args) throws Exception {
        GsmModem gsmModem = new GsmModem();
        GsmModem.configModem(port, bitRate, modemName, modemPin, SMSC);
        gsmModem.Sender("+94712244555", "Test Message"); // (tp, msg) 
    } 
}
Okay in here. you will notice that you have to first find out the port number of your USB modem/dongle. for that you can simply right click the MyComputer Icon > goto Mange > then Search for Modems > then it will pop up a interface with several tabs.
Okay then you can simply notice theirs a Name called port. Infront of that theirs the port Number. okay cool now you know the port number. Insert that into the code.

Modem name is a optional thing.Give it some relevant name.

Bitrate? leave it as it is. Or change to a proper one. The number will change depending modem to modem. so just leave as it as.

Some modems are using PIN numbers for Security. Does your one also using such a pin? If so please insert it to the code.

well then You have to insert the SMS Message Center Number. You already know that. Suppose you own a Mobitel/Dialog Sim you can easily find out it in your Mobile phone/Dongle Message Settings. So get the Number and paste it with +94 prefix.

wow! Now all are ready. we have completed the Configuration of the modem. Cool isnt it? :D

Okay now please disconnect your Modem from the Internet Before continue. If its connected to the internet or may be the Mobile Partner or what ever the Software you are using to connect with the modem, can disturb our work. So just close them All. You better restart your computer to refresh the Modem Port. Don't Connect it to the Internet!!

Well now we are ready to send SMS thorough Java.. Be Cool..!
gsmModem.Sender("+94712244555", "Test Message"); // (tp, msg)

Just put some Telephone number and message for the Body.
Then do a Clean and Build. Now simply Run the project.

Okay all have to be working Properly..Wait, Give it some Time! Did you got the Message? :D

So thats how we can simply send SMS using Java with our USB modem.
Cool way.. huh!

Cheers!
 - Harsha

_________________________


Troubleshooting

  • Case 1 - javax.comm.NoSuchPortException

Exception in thread "main" org.smslib.GatewayException: Comm library exception: java.lang.RuntimeException: javax.comm.NoSuchPortException
at org.smslib.modem.SerialModemDriver.connectPort(SerialModemDriver.java:102)
at org.smslib.modem.AModemDriver.connect(AModemDriver.java:114)
at org.smslib.modem.ModemGateway.startGateway(ModemGateway.java:189)
at org.smslib.Service$1Starter.run(Service.java:276)
Java Result: 1

This error can be occurred caused by several reasons.

1. your dongle software might be opened. so close it, double check if its running as a background service by using Task Manager. kill if it exists.
2. Your SMSLib configurations to JVM isnt affected properly. so check again the required files are thr or not. you need to place them both JDK and JRE see ^
3. This program doesnt work well with 64Bit JVM, but it doesnt say you cant use it in a 64 bit machine. but You have install 32Bit JDK on it, remove the 64Bit JDK to prevent mix ups.
4. The port you gonna access might not really available in the system. you can simple check the Dongle port if its thr by: right clicking Computer icon then go manage > then select device manager > then expand Ports(COM LPT) column > You will see the Application interface port of your device. Thats the port you have to use thr.

  • Case 2 - SMS to multiple recipients
Unfortunately this program doesn't have the capability to send SMS for multiple recipients but the core API (SMSLib) would do it, So you may refer this to send same SMS to multiple recipients(group sms) by using the built in functions of SMSLib API.

Notes:
  • This program is licensed under: Apache License (Please see the full license document at here)
  • The program is a API Wrapper for SMSLib and  the Main API has more Functionality than this Wrapper Code.
  • Please review the below comments section for Answers towards most of the frequently asked questions.