Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem regarding sending message from a GSM modem  RSS feed

 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody I am chaitanya, I have a problem regarding an application where I am supposed to send messages from a computer to a mobile. Let me discuss the requirements first, then later I will tell my problem.

A GSM modem(simcom 300) will be connected to my serial port, using comm api I am receiving the messages and sending messages. The scene is like this:

A parent will be sending a request to the server with this son's roll number and the request. For example 05N61A0564 A <date> for his son's attendance on that particular date. 05N61A0564 M MID1 for his son's first mid term exam's marks. The formats goes like this.
My program must detect the message on arrival. Then parse the message and send appropriate details to the concerned parent.

Commands to initialize the modem.
AT <enter> //general check
AT+COPS?<enter> //get network
AT+CMGF=1<enter> //enable read and write modes.
AT+CSQ<enter> //signal strength

Commands to read message contents
AT+CMGR=?<enter> //question mark indicates message number

Commands to send message
AT+CMGS="mob_num"<enter>
>mesg_content<ctrl_z><enter>

Individually I am able to send message and read the message. When a message arrival is detected the listener reads the message and displays it as

cmtl: "sm", <n> //where n is the message location number.

I am parsing the string and detecting n. When I detect n, then I will issue another command such as

AT+CMGR=<n><enter>

In return I will get the contents of the message, such as

05N61A0564 M MID1 "<sender_mob_num>" <date> <time>

I am parsing the content, detecting the request and I will issue a query to database and retreive the details and I will snd the details to appropriate mobile number. The Command goes like this:

AT+CMGS="+<country_code><destination_mobile_number>"<enter>
>message content<CTRL+Z><enter>

This is what I am supposed to do.

My problem is: <present_algorithm>

On Interupt
1) Read incoming
2) Parse message number
3) Issue CMGR command
4) Read Message content
5) Parse Message content
6) Generate output
7) Send Message using CMGS commnad

In the interupt code I am doing this:

When message is received readNumber(incoming) method is called. From there appropriate methods are called. The problem is when I issue a command such as AT+CMGR=<n> using outputStream, again an interupt is generated and inputStream is read and again readNumber(incoming) is called. In readNumber(incoming) anothe function is called and again AT+CMGR=<n> command is issued.

The program is entering into an infinite loop.

Can anybody help me proposing a simple model. I have been thinking of this over a night, but unable to solve the problem.

I found another solution, where the code above goes like this:

This time when a message arrives for the first time, the message number cmtl: "sm", <n> is detected. Then if 'a' is true readNumber(incoming) is called. Initially 'a' will be true.
Next if I issue a CMGR command, this time 'a' is false and readNumber(incoming) will not be called.
After sending the message control returns to the readNumber(incoming); line. Next 'a' is set to true. This is how I am sending a message.

But this method also has one drawback. When one message is being processed, if suddenly another message arrives this algorithm wont work.

I found another solution for this problem also. I will accumilate my SIM with default messages. At any moment there will be only one active message. Afert processing this message irt will be deleted. Then another message enters the SIM.

However this is not a good practice always. Sometimes the message is being received, sometimes the message is being ignored.

Can anyone please help me? I will be very very thankful to you people.
And one more question is, is the second approach good one, is it a good logic to send atleast one message?

Thank you all in advance and sorry my problem is very big.
 
Campbell Ritchie
Sheriff
Posts: 53759
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not a "beginning Java" question. Moving.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Not a "beginning Java" question. Moving.


Thank you sir.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!