Simply send SMS using Java with GSM Modem or HSDPA Dongle!

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.


Simple way to pack All Jar Dependencies into One Jar using maven-dependency-plugin



<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.harshadura.gsm</groupId>
    <artifactId>smsdura</artifactId>
    <packaging>jar</packaging>
    <version>1.0</version>
    <name>smsdura</name>
    <url>http://maven.apache.org</url>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>javax.comm</groupId>
            <artifactId>comm</artifactId>
            <version>2.0.3</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/comm.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>commons-net</groupId>
            <artifactId>commons-net</artifactId>
            <version>3.0.1</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/commons-net-3.0.1.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/log4j-1.2.16.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>jsmpp</groupId>
            <artifactId>jsmpp</artifactId>
            <version>2.1.0</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/jsmpp-2.1.0.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>smslib</groupId>
            <artifactId>smslib</artifactId>
            <version>3.5.1</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/smslib-3.5.1.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>RXTXcomm</groupId>
            <artifactId>RXTXcomm</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/RXTXcomm.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>pduutils</groupId>
            <artifactId>pduutils</artifactId>
            <version>1.0.0</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/pduutils.jar</systemPath>
        </dependency>
    </dependencies>
</project>





After then just type
mvn clean install

OpenMRM – Medical Record Management System


This is a Project which I have done with few of my colleagues specifically for SLIIT ITP Subject.
I have open sourced the Full source Code at github and rest of the project gonna Open sourced at Sourceforge FOSS home.

I am really thankful to Roshan Ayya, Dr. Dikaz Sheriff at Western Hospital, Colombo for giving lots of helps to make this Product a Success.

The ripen is a lil intro on whats it? and how it works.
visit the official project web portal to see more.thx



How it Works!

 


OpenMRM is a Cross Platform Supported Desktop Application Product,  which is purely coded using Java. Its a  Electronic Medical record Management system Specially developed for Clinic or same kind of Small or Medium Scaled Hospital.
 
We started developing this Application from building a simple data model, wrapped that into an API, and then built a web-based application that uses the API. But it was a Vain, So then we Started to build this Desktop Application and now all Seems Working great. 

OpenMRM still in developing process, and its a Fully open sourced project. Community can get involved and support us to develop the next generation of high end OpenMRM. and in the Meantime You can download the source from GitHub and feel free to submit your comments and found any bugs regarding OpenMRM.

Related Links


Project Home

Fork the Git Source
Download Source