Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7057645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:00:42+00:00 2026-05-28T04:00:42+00:00

I found free source project to send sms using java comm: http://code.google.com/p/find-ur-pal/source/browse/src/?r=21 Function sending

  • 0

I found free source project to send sms using java comm:
http://code.google.com/p/find-ur-pal/source/browse/src/?r=21

Function sending sms looks like this:

  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("atz");
                delay=LONG;
                startTime=(new Date()).getTime();
                break;

              case 1:
                delay=STANDARD;
                mySerial.send("ath0");
                startTime=(new Date()).getTime();
                break;
              case 2:
                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 3:
                expectedResult=result.indexOf("OK");

               // log ("received ok ="+expectedResult);
                if (expectedResult>-1){
                  mySerial.send("at+csca=\""+csca+"\"");
                  startTime=(new Date()).getTime();
                }else{
                  step=step-1;
                }

                break;
              case 4:
                expectedResult=result.indexOf("OK");

               // log ("received ok ="+expectedResult);
                if (expectedResult>-1){
                  mySerial.send("at+cmgs=\""+recipient+"\"");
                  startTime=(new Date()).getTime();
                }else{
                  step=step-1;
                }

                break;
              case 5:
                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 6:
                expectedResult=result.indexOf("OK");
                //read message number
                if (expectedResult>-1){
                  int n=result.indexOf("CMGS:");
                  result=result.substring(n+5);
                  n=result.indexOf("\n");
                  status=0;
                  messageNo=Long.parseLong(result.substring(0,n).trim() );

                  log ("sent message no:"+messageNo);


                }else{
                  step=step-1;
                }

              break;
            }
            step=step+1;

            aThread.sleep(100);

          }catch (Exception e){
              e.printStackTrace();
          }
        }

        mySerial.closeConnection() ;

        //if timed out set status

        if (timeOut ) {
            status=-2;
            log("*** time out at step "+step+"***");
        }
      }

AT commands are sending according to specifications. And it works perfectly, but now I have read sms from Inbox. I have write similar function like this:

public void receiveMessage() throws Exception
      {
          int expectedResult = 0;

          SerialParameters params = defaultParameters;

            mySerial =new SerialConnection (params);

            mySerial.openConnection();

            // step 1
            mySerial.send("atz");
            delay=LONG;

            Thread.sleep(100);
            //aThread.sleep(100);

            String result=  mySerial.getIncommingString() ;

            // step 2
            delay=STANDARD;
            mySerial.send("ath0");
            Thread.sleep(100);

            // step 3
            result=  mySerial.getIncommingString() ;
            expectedResult=result.indexOf("OK");

            //log ("received ok ="+expectedResult);
            if (expectedResult>-1){
              mySerial.send("at+cmgf=1");
              //startTime=(new Date()).getTime();
            }

            // step 4
            result=  mySerial.getIncommingString() ;
            expectedResult=result.indexOf("OK");

            //log ("received ok ="+expectedResult);
            if (expectedResult>-1){
              //mySerial.send("at+cmgl=\"ALL\"");
                mySerial.send("at+cmgr=1");
              //startTime=(new Date()).getTime();
            }

            Thread.sleep(100);
            result=  mySerial.getIncommingString() ;

      }

In step 1 I send atz command and I got response OK then command ath0 and response OK and then command at+cmgl=\”ALL\” and again response OK, but where are my messages ? I was thinking then the last response (getIncommingString) should contain messages read from inbox.

I know that are SMSLib and other libraries. But to use that libraries I have to added a lot of other libraries (for logging). I want to have simple application to send and receive sms.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:00:43+00:00Added an answer on May 28, 2026 at 4:00 am

    If you are reading SMS’s from the SIM Card then you must first execute AT+CMGL to find out the indexes of any SMS’s (SMS-DELIVERs) stored. Then you need to use AT+CMGR to read a specific SMS. Are you working in PDU mode or Text mode?

    Just as a side note. Why are you sending ATZ and ATH0 commands? These are profile and call related commands.

    To see all message statuses allowed from your modem:

    AT+CGML=?
    

    A typical response would be:

    +CMGL: ("REC UNREAD","REC READ","STO UNSENT","STO SENT","ALL")
    

    So to look at all messages on your SIM card:

    AT+CGML="ALL"
    

    To see all unread (new) messages on your SIM card:

    AT+CGML="REC UNREAD"
    

    There is another option where you can prevent SMS messages being stored on your SIM card. This is controlled by using the AT+CNMI command to configure unsolicited messages to be enabled. Then whenever a SMS is received then you will receive a +CMT message asynchronously. If you want to know more about that one just let me know.

    There are a few benefits making use of the unsolicited approach. The main one being you don’t have to manage your SIM cards memory (no risk of it getting full). Also with large quantities of SMS’s your SIM card can actually become unusable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Requirements: free, preferably open-source implemented in one of the .NET managed langs Google found
Found a piece of code today, that I find a little smelly... TMyObject.LoadFromFile(const filename:
I've been looking for a free library/source code to format SQL queries, preferably in
Free as in beer. I can live without the source code. About 10 years
I'm looking for a free/open source collaborative project manager that can be deployed internally
I'm starting a software project that I'd ultimately like to release as free, open-source
I just found /n softwares free Powershell NetCmdlets, and after playing with them I
I haven't found this question, feel free to close if it's already up here.
I've looked at free javascript html editors, and I haven't found any that I
Found some old code, circa VS 2003. Now I have just VS 2008 (SP1)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.