A Technology Blog About Code Development, Architecture, Operating System, Hardware, Tips and Tutorials for Developers.

Wednesday, June 23, 2010

GSM MODEM WITH MY GSM PHONE

10:02:00 PM Posted by Satish , , , , 6 comments

INTRODUCTION TO GSM MODEM:

A GSM modem is a wireless modem that works with a GSM wireless network. A wireless modem behaves like a dial-up modem. The main difference between them is that a dial-up modem sends and receives data through a fixed telephone line while a wireless modem sends and receives data through radio waves. Computers use AT commands to control modems. Both GSM modems and dial-up modems support a common set of standard AT commands.

MOBILE PHONE OR GSM MODEM:


In general, a GSM/GPRS modem is recommended for use with a computer to send and receive messages. This is because some mobile phones have certain limitations comparing to GSM/GPRS modems. Using my Nokia 3110C, I am not able to receive any messages to my computer. And also I noticed the phone always run out battery in no time. But there are some phones in the market which support all the AT commands. Here is the list of AT Commands supported by the Nokia phones.

SETUP THE MOBILE PHONE AS GSM MODEM:

1. Connect your mobile phone to a computer and set up the corresponding wireless modem driver.
2. Run MS HyperTerminal by selecting Start -> Programs -> Accessories -> Communications -> HyperTerminal.
3. In the Connection Description dialog box, enter a name and choose an icon you like for the connection. Then click the OK button.
-->

4. In the Connect To dialog box, choose the COM port that your mobile phone is connecting to in the Connect using combo box. For example, choose COM1 if your mobile phone is connecting to the COM1 port. Then click the OK button.
Note:
Sometimes there will have more than one COM port in the "Connect Using" combo box. To know which COM port is used by your mobile phone, follow the procedure below:
a. Go to Control Panel -> Phone and Modem Options".
b. Then click the Modems tab. In the list box, you can see which COM port the mobile phone or GSM/GPRS modem is connected to.
5. The "Properties" dialog box comes out. Enter the correct port settings for your mobile phone. Then click the OK button.
Note:
To find the correct port settings that should be used with your mobile phone, one way is to consult the manual of your mobile phone. Another way is to check the port settings used by the wireless modem driver that you installed earlier.
To check the port settings used by the wireless modem driver, follow these steps:
a. Go to Control Panel -> Phone and Modem Options -> Modems tab.
b. Select your mobile phone in the list box.
c. Click the "Properties" button.
d. The Properties dialog box appears. Click the Advanced tab and then click the Change Default Preferences button.
e. The Change Default Preferences dialog box appears. The Port speed field on the General tab corresponds to HyperTerminal's "Bits per second" field. You can also find the setting for flow control on the General tab. On the Advanced tab, you can find the settings for data bits, parity and stop bits.
6. Type AT in the main window. A response OK should be returned from the mobile phone or GSM/GPRS modem. Type AT+CPIN? in the main window. The AT command AT+CPIN? is used to query whether the mobile phone is waiting for a PIN (personal identification number, i.e. password). If the response is +CPIN: READY, it means the SIM card does not require a PIN and it is ready for use. If your SIM card requires a PIN, you need to set the PIN with the AT command AT+CPIN=[PIN].

Now the mobile phone is configured to work as a GSM modem.
JAVA CONFIGURATION FOR COM PORT:

As the modem is connected to the COM port of the computer, you have to use Java Communications API.
Sun provides an API extension for communicating with parallel and serial ports, specifically for Solaris and Windows environments. The API can be found here. There are also third party APIs and an open source implementation, which works on several platforms including Linux. You can download the Java Communications API from here.

INSTALLING THE JAVA COMMUNICATIONS API IN WINDOWS ENVIRONMENT:

Among the items that you download from Sun are three very important files:
1. comm.jar
2. win32com.dll
3. javax.comm.properties

For the JVM to recognize the serial ports, proper placement of these files is important. And have found the following installation methods to be effective:

1. comm.jar should be placed in:

    %JAVA_HOME%/lib
    %JAVA_HOME%/jre/lib/ext

2. win32com.dll should be placed in:

    %JAVA_HOME%/bin
    %JAVA_HOME%/jre/bin
    %windir%System32

3. javax.comm.properties should be placed in:

    %JAVA_HOME%/lib
    %JAVA_HOME%/jre/lib

Now Java is correctly configured to interact with the COM ports. Now it is the time to write a program to send and receive message.

SENDING AND RECEIVEING SMS:

For sending and receiving SMS I am using the following procedure.

1. Connecting to the COM port where the modem is connected.
2. Registering the listener for serial port event.
3. Using the following set of AT commands to send the SMS.

            AT (To check the modem)
            OK (Response - modem connected)

            AT+CMGF=1 (To set the text messaging mode)
            OK (Response - text messaging mode set successfully)

            AT+CSCA="+979797979796464" (To set the message center)
            OK (Response - message center is set properly)

            AT+CMGS="+91021482048023" (To set the recipient no and open the message writing prompt)
            >my test message + [Ctrl+z] ("Ctrl+z" is to come out of the message writing prompt)
            OK             
            CMGS: +919886599334 (Message sent)
    
4. As we have registered to the serial port events, when ever any data will come to the serial port the implemented method will print the data to the console. It is applicable for receive message also.

If you are using the GSM/GPRS modem, then lot of other features of phone like call receiving, making a call, call forwarding, answering machine etc can be developed for any enterprise application. 

SHARED ITEMS:

1. Source Code or you can fork at GitHub.

6 comments:

  1. Hi
    I have used your source code and follow the SETUP THE MOBILE PHONE AS GSM MODEM instructions.
    We check our mobile pin.
    AT
    OK
    AT+CPIN?
    +CPIN: READY

    OK
    but i got the following error in hyper terminal

    AT+CMGF=1
    OK
    AT+CSCA="9842201155"
    ERROR
    AT+CSCA="+919842201155"
    OK
    AT+CSCA="+919842201155">HI
    ERROR

    But i can run this program in netbeans it can build successfuly.
    But i can't send the message.

    I Don't know what is the problem.
    Please Help me to give some ideas.
    regards
    viji

    ReplyDelete
  2. Hi sathiesh..
    Very thank you for this post. i got some error,that is , where we put "SMSConnector, 30000" setting during hyperterminal settings.


    sPort = (SerialPort) portId.open("SMSConnector", 30000);


    Thank you so much friend.

    ReplyDelete
  3. @Vijayalakshmi : If you are not able to send message from hyper terminal, then there is no point running your java application.

    I want to know some of the things from you..

    1. Which GSM modem/ phone you are using?
    2. Please check your message center number by inserting the SIM to any mobile number and use the same at AT+CSCA="+979797979796464".(use this +91 format)

    Lets go step by step and first send a message from Hyper Terminal.

    One thing is sure your device is configured properly as you are getting OK status.

    @Beril: Can you please try sending a SMS from hyper terminal.

    ReplyDelete
  4. I have one doubt in SMS Sending.
    I have used ur blog code to send sms.
    But this code is only supported nokia mobile.
    If i use Sony Ericson or Samsung i want to send sms.
    But i don't have any idea. So please update me what can i do.
    Please give me any ideas.
    viji

    ReplyDelete
  5. @Vijaylakshmi:

    There are different type of AT command sets for different modem h/ws.

    So what ever i used in this post are for Nokia phones. You may have to google the command sets for other h/ws(phones).

    generally for dedicated GSM modems, the manufactures use to provide the instructions sets to work with, and sometime they use to provide the Java API hiding their native implementations..

    ReplyDelete
  6. thanks for the information hopefully can provide value to the many benefits

    ReplyDelete