How to register a response from an AT-compatible mobile?

Hello all
I do hope someone can help, I've been pounding the forums and the Google for an idea of how to do this but without much luck. There were a few prospective solutions but they only seem to work on a single/hardware serial port. I won't post any of my own code here because I have pretty much nothing to go on so far.

I have an older Sony Ericsson mobile hooked up to my Uno. It's using the SoftwareSerial library and pins A4 and A5 as RX and TX pins respectively. It's currently working just fine; I can send SMS messages using the following bit of code:

 //Insert SMS coding here
                  mySerial.println("AT"); // Sends AT command to handshake with cell phone
                  delay(500);
                  mySerial.println("AT+CMGF=1"); // Switches off PDU mode
                  delay(500);
                  mySerial.println("AT+CPMS=\"ME\""); // Sets phone to use internal memory for SMS
                  delay(500);
                  mySerial.println("AT+CMGF=1"); // Puts phone into SMS mode
                  delay(1000); // Wait a second
                  mySerial.println("AT+CMGS=\"01234 567890\""); // Sends the recipient phone number to phone
                  delay(1000);
                  
                  mySerial.print("TotSml: ");
                  mySerial.print(smallSalesTotal);
                  mySerial.print("TotLrg: ");
                  mySerial.print(largeSalesTotal);
                  
                  mySerial.write(byte(26)); // Sends the "End of Message" byte to the phone
                  delay(1000);

As I said, that works just fine. However, I'd like to put a bit of error-handling in there that illuminates an LED if a problem arises with the phone. You can get a reply from the phone that'll accomplish this by way of the following code found in the examples in the SoftwareSerial library.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(A4, A5); // RX, TX

void setup()  

  Serial.begin(9600);
  mySerial.begin(9600);
}
void loop()
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

Uploading this to the Arduino allows you to use the Serial Monitor to type text straight into the serial port of the phone. If you type "AT" (no quotes) followed by Enter, the phone responds instantly with:
OK

I was hoping to add something to my code that sends the text "AT" to the phone every five minutes, and then illuminates the LED if "OK" isn't received back again. As an added bonus I'd also like to record the "conversation" between the Arduino and the phone, using the SD card module I have hooked up and working. But because of the byte-by-byte way that the Arduino receives messages back from the serial port I haven't been able to accomplish this. Any clever bods out there have any guidance?

Thanks!

What model of mobile modem thingie do you have?
You may have some luck with this: http://arduino.cc/en/Reference/GSM

I have an SM51000 based module and have been doing some work to build a sensible lightweight library to do SMS send and receive and harness its real-time clock. It's not a beginner thing to get something really robust working.

Hi there
It's just an old Sony Ericsson K600i, I chose it because most of those old Sony phones have a really straightforward way of accessing their AT command set.

I did have a look at the GSM library, but it seems hard-coded to the Telefonica GSM shield. It certainly can't find my Sony when I test the connection. I'm not smart enough with the programming to go digging through the library and see why it isn't working with my phone though, perhaps it's sending AT commands to the modem that the Sony Ericsson doesn't understand. It may even just be a case of conflicting baud rates but I really couldn't say.

As I said, that works just fine. However, I'd like to put a bit of error-handling in there that illuminates an LED if a problem arises with the phone. You can get a reply from the phone that'll accomplish this by way of the following code found in the examples in the SoftwareSerial library.

In your first code, you are sending data TO the phone, but not reading any reply FROM the phone.

In the second code, you are sending data TO the phone (that you get from the Serial Monitor) AND you are reading data FROM the phone.

Now, it doesn't seem like rocket surgery to add some code to the first code that actually reads FROM the phone.

I'm finding it a bit trickier than that; the data comes back from the phone in a way that presents quite a few obstacles. Firstly, the data comes back from the phone character by character. My program has a 10-second delay at the end of each execution of the void loop(), so if I use code snippet 2, the characters of the response come back to the Arduino with a 10 second delay between each one. Not ideal for composing strings. There are a few working code examples out there I was trying to draw from but they either have trouble taking this into account, or have trouble working with the SoftwareSerial library.

Any ideas?

Firstly, the data comes back from the phone character by character.

Yes, it does.

My program has a 10-second delay at the end of each execution of the void loop()

That's easy. Loose the delay. What, exactly is the program supposed to accomplish? Sending the same message every 10 seconds seems pointless. Sending a message when an event occurs makes sense. Having that message occur every 10 seconds does not.

In any case, you can use millis(), as illustrated in the blink without delay example, to determine if it is time to send the next message.

so if I use code snippet 2, the characters of the response come back to the Arduino with a 10 second delay between each one.

It is possible to read all the characters that have arrived, not just one.

I already use millis() for the delay feature. The program logs data from sensors and every 10 seconds using millis() and then at the end of each day it composes and sends an SMS.

I do appreciate your looking into this Paul, but sometimes it could be more helpful if people could have a good look at the specifics of the question that somebody asks and then have a go at addressing them, rather than suggesting (admittedly valid) alternatives that are still some distance away from the original terms of the question. People generally post a specific question because it turns out that the easy solution that might seem obvious to an outsider has in fact already been ruled out and they find themselves needing to do it the hard way. So if I were to ask, say, "Does anyone know the ignition advance on a 1978 Range Rover V8 engine?", answers like "Use a diesel engine instead" or "Yes, I know the ignition advance on a 1978 Range Rover V8 engine" might be not unreasonably considered a little wide of the mark. I started trying to take this advice little bit more to heart myself a couple of years back and have slowly found myself posting to forums less and less, but (hopefully) of a better quality.

Anyway, that's enough from me. Plane to catch.