Help with serial interface.

After many troublesome hours I have managed to get my Arduino Uno to communicate with Siemens TC35i (GSM Modem)

I am able to send a text message, and also retrieve any messages that have been send to the modem. Which was an achievment in it self. :smiley:

However........

When I send the following

gsmSerial.print("AT+CMGR=1\r"); // This reads the message at location 1

It automatically sends out the message over the serial, which I can see in the arduino monitor.
Which is something on the lines of "+44xxxxxxxxxx", "19/01/2013",, "12:14:36" Test sms message (mobile number, date, time, message content)

Is there a means of capturing this data? I.e. store it as a string?

Regards
Daniel

When I send the following

gsmSerial.print("AT+CMGR=1\r"); // This reads the message at location 1

It automatically sends out the message over the serial

It? What is "it"?

Is there a means of capturing this data? I.e. store it as a string?

Of course.

When I send the following

gsmSerial.print("AT+CMGR=1\r"); // This reads the message at location 1

It automatically sends out the message over the serial
It? What is "it"?

It is a GSM modem (TC35i) which responds to AT commands over serial, i.e. ("AT+CMGR=1\r"); // command for reading a message

Is there a means of capturing this data? I.e. store it as a string?

Of course.

I have tried declaring a string called incomString, then using this as follows;

gsmSerial.print("AT+CMGR=1\r");
incomString = gsmSerial.read();

It is a GSM modem (TC35i) which responds to AT commands over serial

To the Arduino, not to the Serial Monitor. The Arduino is doing that, apparently. Though it's hard to tell from your code, since you forgot to post it.

I have tried declaring a string called incomString

Where?

then using this as follows;

If gsmSerial is an instance of SoftwareSerial, the read() method returns one character.

PaulS:

It is a GSM modem (TC35i) which responds to AT commands over serial

To the Arduino, not to the Serial Monitor. The Arduino is doing that, apparently. Though it's hard to tell from your code, since you forgot to post it.

I have tried declaring a string called incomString

Where?

then using this as follows;

If gsmSerial is an instance of SoftwareSerial, the read() method returns one character.

I am using the SoftwareSerial, the incomString is declared at the start of program. I am currently at work atm, hence no post of the current code sorry. So i've tried my best to explain the scenario and problem.

In brief my ultimate aim is home automation using sms,

  1. To send a text message i.e. heating.
  2. The arduino reads this text message from the TC35i GSM modem.
  3. Recognises the heating command.
  4. Subsequently turns on an LED to simulate heating on.

I shall post the code tonight I have for this part tonight.

P.s this is the second part by the way, the first was to simulate a burglar sensor as follows.

  1. Pushbutton simulates proxy switch.
  2. {Predefinded text + switch sensor was activated} was then sent as sms using the TC35i.
    This all works fine

Regards
Dan

the incomString is declared at the start of program.

Oh, well, that ought to work, then.

Assuming, of course, that you declared it correctly, along with an index variable, and that you increment the index value at the appropriate time, and that you store data in the string at the correct time/place, and that you NULL terminate the string at the appropriate place and time. That's a lot of assumptions I'm not willing to make.

Paul,

I think i'm missing a few vital things when trying to receive the serial stream, going off your last post.

My understanding of serial use is limited, since my only previous use to output strings on an LCD display using "serial.print", hence why I found communicating to the TC35i ok in the end.

However this is the first time I have tried to deal with incomming serial data, after sending serial data.

Regards
Dan

Hi Paul, here is my current Arudino code for sending the message and receiving message. (Gone back to basics) of what works.

#include <SoftwareSerial.h>  
char gsm_char=0;      //Stores character from the gsmSerial
char inchar=0;
String incomString;

SoftwareSerial gsmSerial(2,3);  //Creates a software serial port. (rx,tx)
 
void setup()
{
  //Initialize serial ports for communication.
  Serial.begin(9600);
  gsmSerial.begin(9600);
  Serial.println("Starting TC35 and debug Communication...");
}
 
void loop() {
  
    if(Serial.available() > 0)
    {
      gsm_char = Serial.read();       
        //Evaluate input.
      if(gsm_char=='t')
        { //Checks input char = s
          gsmSerial.print("AT\r");  //Send test command
        }
      else if(gsm_char=='s')
        { //Checks input char = s
          gsmSerial.print("AT+CMGF=1\r"); //Set text mode.
          delay(100);      
          gsmSerial.print("AT+CMGS=+447726262626\r"); //AT command to send SMS
          delay(100);
          gsmSerial.print("Temperature"); //Print the message
          delay(10);
          gsmSerial.print("\x1A"); //Send it ascii SUB
        } 
      else if(gsm_char=='r')
        {  //Checks input char = r
          gsmSerial.print("AT+CMGR=1\r"); //Reads text message location 2
        // Here is where I am to then store the text message that is then sent from the TC35i GSM modem
        //
       }              
    }
}
        // Here is where I am to then store the text message that is then sent from the TC35i GSM modem

No, it isn't. You need to read and store all the response data, until the end of the response arrives, and then figure out what command it the response is in response to.

Either that or you create a blocking waitForCompleteResponse() function and call it after sending each command.

Here is a link to a way to collect serial data:

Nick Gammon also posts links to his serial site, periodically.

Hi Paul,

I now understand this snipet of code;

    if(gsmSerial.available() > 0)
    { //If a character comes in from the cellular module...
      gsm_char=gsmSerial.read();    //Stores the char in gsm_char.
      Serial.print(gsm_char);  //Print its to debug serial (so can be seen in monitor)
    }

This code is actioned upon each char received

Using this automatically prints any char that has been sent from the TC35i GSM modem, correct me if I am wrong, but this can now be engineered to store each char in a new location within an array?

Then I can use the array to also get the parts of information I require? By pointing to the location of the data and reading the required No of chars?

Regards
Dan

correct me if I am wrong, but this can now be engineered to store each char in a new location within an array?

Yes, it can.

Then I can use the array to also get the parts of information I require? By pointing to the location of the data and reading the required No of chars?

Yes. The strtok() function is a good place to start.

That shall be my task come tomorrow, or the weekend.

Definitely the hardest part was getting the TC35i working as many a person has trouble with this device. But in no way form would it be worth while without the hurdles :slight_smile:

Slowly but surely I'll design and make my own home automation project for my final year degree project.

Cheers Paul......for now lol.

Slowly but surely I'll design and make my own home automation project for my final year degree project.

Id guess that you are about 90% of the way there. Collecting, parsing, and using the SMS data is going to seem trivial compared to the problems you've overcome so far, when you look back on the whole project.

The real key is determining when the message ends. There must be some sort of marker that says "Hey, I'm the last character in the response from the modem. You can use the data now." Figure out what that character is, and collect data in an array until that marker arrives. Then, parse and use the data.

As a start, print each character received from the modem twice - once as a character and once as a HEX value - using one line per character.

One or more non-printing characters will (hopefully) reveal themselves as the end of the message - probably a carriage return or line feed (or both).

Yes, slowly but surely it's coming together now on the arduino, like you say I need to get the information loaded into an array, but also find out its end of transmission command so to speak. As with this know you can use so you know when transmission has ended.

Then data can be parsed out, date, time, message content etc.

From here I'll need to make a set of commands the arduino will recognise and then make an action upon i.e. heating on, heating off, lights on etc. These would then act on an output as required.

Summarily with inputs, I'll have some proxy sensors and upon trigger the arduino will send a text message to a pre programmed number.

Fingers crossed that's how it should come together lol. Then I can control things from anywhere providing I have cell signal, which is more reliable the using it over the net, which is the whole reasoning behind my project :slight_smile:

Back at work at the moment, and since the message board is back up, and before I jet off to the pub I thought i'd update you.

Storing into array has/hasn't been working, I think I have some minor floors in my code.

Going to have a good go at on Sunday (hopefully) failure to get it work on then, I shall post an update my code. It is probably soemthing very trivial, but I can't seem to figure it for the life of me.

Dan