sms in arduino

does anyone know a way of coding in arduino to send the AT+COPS? command as a sms body? i need to print the result of AT+COPS? in my sms...i have try many time but no luck...plz help....

What hardware do you have?

What is your current code?

How are you trying to do it?

What is AT+COPS? :-?

AT+COPS? is the AT command using Hilo SAGEM tha will show the network of mobile phone…
I’m trying to put it in the sms body…
this in my current code…

int led = 13;
int onModulePin = 2; // the pin to switch on the module (without press on button)

int timesToSend = 1; // Numbers of SMS to send
int count = 0;

//int a;

char msg = “MY MAXIS”;
char msg2 = “MY CELCOM”;

//char incomingByte;
//Serial b;
//int ch;

//int ch = getchar();

void switchModule()
{
digitalWrite(onModulePin,HIGH);
delay(2000);
digitalWrite(onModulePin,LOW);
}

void setup()
{

pinMode(led, OUTPUT);
pinMode(onModulePin, OUTPUT);

Serial.begin(115200); // the GPRS baud rate

switchModule(); // swith the module ON

for (int i=0;i<5;i++)
{
delay(5000);
}

Serial.println(“AT+CMGF=1”); // set the SMS mode to text

/*if (Serial.available())
{
msg = Serial.read();
Serial.print(msg);
}
*/

}
void send()
{
Serial.println(“AT+COPS?”);
if ( Serial.available())
{
Serial.println(msg);
}
else if (Serial.available())
{
Serial.println(msg2);
}
}

void loop()
{
/*Serial.write(“AT+COPS?”);
if (Serial.available())
{
msg = Serial.read();
Serial.print(msg);
}
*/
while (count < timesToSend)
{
delay(1500);
Serial.print(“AT+CMGS=”); // send the SMS the number
Serial.print(34,BYTE); // send the " char
Serial.print(“0148281947”); // send the number change ********* by the actual number
Serial.println(34,BYTE); // send the " char
delay(1500);

//erial.print(msg,BYTE); // the SMS body
delay(500);
Serial.println(0x1A,BYTE); // end of message command 1A (hex)

delay(5000);

count++;
}

if (count == timesToSend)
{
Serial.println(“AT*PSCPOF”); // switch the module off
count++;
}

}

my main problem, nothing can be put in front of the Serial.println
so, i cant declare it
n if you have any idea about this, please help…my project will not work if i cant solve this…

 for (int i=0;i<5;i++)
 {
   delay(5000);                        
 }

Is there some reason not to just use delay(25000);?

void send()
{
   Serial.println("AT+COPS?");
   if ( Serial.available())
   {
       Serial.println(msg);
   }
   else if (Serial.available())
   {
       Serial.println(msg2);
   }
}

If there is serial data available, the 2nd block of code will never be sent. If there isn’t, the second block of code will not be sent.

Might want to re-think what this function is doing.

/*Serial.write("AT+COPS?");
  if (Serial.available())
    {
        msg = Serial.read();
        Serial.print(msg);
    }
   */

I know this is commented out, but, just to be clear, if this code were executed, it would only read one character from the serial port.

The loop function is called in an infinite loop. Are you sure that you want to sending data millions (potentially) of times per second? Hope you have an unlimited text messaging plan.

my main problem, nothing can be put in front of the Serial.println

Can you explain this statement? Which Serial.println? What do you (think you) want to put in front of it?

i'm thinking to assign some value but i'm not so sure that this will work.. here is the simple code...

if (Serial.available() == Serial.println("AT+COPS?"))
{
     Serial.println("AT+COPS?") 
}

can u please give me some example of code to get the value of the AT+COPS? and print it as sms body.

if (Serial.available() == Serial.println("AT+COPS?"))

The Serial.println function does not return a value, so it can not be used that way. All it does is send the argument out over the serial port.

What are you expecting to happen after the other device receives "AT+COPS?"? Does it return some data?

..... You turn off first the ECHO at your GSM module? If not all the cmds writed will be repeated by the modulo.

Test this : ATE 0 :o

And only then start to write your code. Both Tx and Rx data at serial will be available at any time because this nice CPU have USART.

Best regards Frank

Serial.println function does not return a value,…

so, what is the function than i can use to return a value…
because AT+COPS? will return a value that i cant assigned, which mean it will return a value that it get from mobile network company.

thanks frank for the information.. but i dont understand what cmds could do..

so, what is the function than i can use to return a value…

Serial communication is asynchronous. That means that sending and receiving data do not need to happen in any specific order. Therefore, there is no function that you can use that returns a value.

Instead, you need to understand that communication is asynchronous, and write your code accordingly.

Use Serial.print to send a command.

Then, use Serial.available() to see if there is any data to receive. Use Serial.read() to read that data.

If you are certain that there will be a response, then use while to wait for some data, or to wait for the end-of-data marker, if you know what that marker is.

Use Serial.print to send a command.

Then, use Serial.available() to see if there is any data to receive. Use Serial.read() to read that data.

okay, so that mean i can use Serial.read() to read the data that i’ve receive from Serial.available() and that data come from Serial.print right?

did i need to make another function to get the data from Serial.print before i called it back using Serial.available() to receive the data?

okay, so that mean i can use Serial.read() to read the data that i've receive from Serial.available() and that data come from Serial.print right?

did i need to make another function to get the data from Serial.print before i called it back using Serial.available() to receive the data?

Serial.print is used to send data to the serial port. If there is another device attached to the other end of the serial port, and that device reads the serial data, and that devices sends a reply, the Serial.available() function will tell you how many bytes of data are in the reply (that have been received so far).

Serial.read() is how you get the data, one byte (or character) at a time.

The data does not come from Serial.print. It comes from the device that was Serial.printed to. You don't receive data from Serial.available(). What you receive from Serial.available() is the number of bytes that are available to read.

okay...thanks...i got them...

another things that i want to ask you... what it is mean by macrofat.cpp, macrofat.h, mmc.cpp, mmc.h ? i got the cod from this link: http://blushingboy.net/p/SDuFAT/

I've try to compile it but it give error which is initialize() was not a member of mmc. what does it mean?

and how can i open the submenu in the arduino..

for your knowledge, i used windows 7 and did it have any effect to the code?