school project help!!

i need help with my school project i have a sm5100b gsm module and a Mega2560
i want to send a sms to control led's
when i send sms to my Mega2560 i get this

+CMT: "+14105551234","+13065550024","10/12/10,12:21:37+00",30
Turn on light

when i get this string on Serial1 how can i send "lights are on" string to Serial2

thank you

when i send sms to my Mega2560 i get this

+CMT: "+14105551234","+13065550024","10/12/10,12:21:37+00",30
Turn on light

First, show us the code that gets this data on Serial1. If you are really getting this data, it should be trivial to parse the input to determine the command. Then, taking appropriate action is even more trivial.

How to parse the input depends on how you have collected it, if you have collected it at all.

i can see this string on the serial monitor only
but i have no idea where to go from here :slight_smile:

i can see this string on the serial monitor
but i have no idea where to go from here

That's great that you can see it, but we don't. And seeing the output doesn't help a lot if you don't know what program created the output.

Here's an idea where to go from here: Post the code that work at the moment and how you wired up your stuff. If you don't, you won't get any useful help.

Korman

SM5100B cellular module created the output and is hooked to tx 1 and rx 1
on my mega 2560. when i send a text to the cellular module i see this on serial monitor

+CMT: "+14105551234","+13065550024","10/12/10,12:21:37+00",30
Turn on light <--this is the text i sent.

i don't know how to write a program that can read serial input and then do some thing with it
like >turn on light from serial1 and send a different string to serial2.
i'm new to all of this and self taught

Ah, that makes it a lot clearer. Start here:
http://arduino.cc/en/Serial for an introduction about Serial ports.
http://arduino.cc/en/Serial/Read for an example as starting point. You might want to receive from Serial2 and write out to Serial1 for your first tests.

Once you have this example working so that you see the data from your modem sent via the ArduinoMega to the serial monitor, you can take the next step: Read the whole string from the modem and write it out in one batch to the serial monitor. Take special care to understand when the message you received is complete.

Only if you have that under control, you can start to worry about disassembling the string and finding the part you care about.

Now that you have extracted the part you care about, you can act on it - eg turn on the light.

Taken in this order, you should progress smoothly adding on new thing after the other and thus reducing the confusion.

Korman

i use this to read the data

char incoming_char=0; //Will hold the incoming character from the Serial Port.

void setup()
{

//Initialize serial ports for communication.
Serial.begin(9600);
Serial1.begin(9600);

//Let's get started!
Serial.println("Starting SM5100B Communication...");
}

void loop() {
//If a character comes in from the cellular module...
if(Serial1.available() >0)
{
incoming_char=Serial1.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
}
//If a character is coming from the terminal to the Arduino...
if(Serial.available() >0)
{
incoming_char=Serial.read(); //Get the character coming from the terminal
Serial1.print(incoming_char); //Send the character to the cellular module.
}
}

This part:

incoming_char=Serial1.read();    //Get the character from the cellular serial port.
  Serial.print(incoming_char);  //Print the incoming character to the terminal.

reads a character from one serial port, and writes it to another, without ever adding it to a collection. You need to add it to a collection in order to see if the collection contains data of interest.

The collection objects that you might me interested in are arrays or the String object.

Once you have the data in a collection (a NULL terminated array of characters or a String), you can think about parsing.

When you have the collection, come on back, and we'll help you parse it.

why is my if substring in black and not red http://arduino.cc/en/Tutorial/StringSubstring

(stringOne.substring(14,18) its red in the tutorial
i have Arduino 0021

Does it compile? If so, then does it really matter what color the text is?

it compiles but when i load the tutorial

void setup() {
Serial.begin(9600);
Serial.println("\n\nString substring():");
}

void loop() {
// Set up a String:
String stringOne = "Content-Type: text/html";
Serial.println(stringOne);

// substring(index) looks for the substring from the index position to the end:
if (stringOne.substring(19) == "html") {
Serial.println("It's an html file");
}
// you can also look for a substring in the middle of a string:
if (stringOne.substring(14,18) == "text") {
Serial.println("It's a text-based file");
}

// do nothing while true:
while(true);
}

i get this back on my serial monitor

String substring():
Content-Type: text/html
It's an html file
It's a text-based file

i though if (stringOne.substring(14,18) == "text")
it would extract the word text from "Content-Type: text/html"

i though if (stringOne.substring(14,18) == "text")
it would extract the word text from "Content-Type: text/html"

It did, as a copy. The substring function does not alter the string it is called on. That is, stringOne is not changed in any way. The letters in positions 14, 15, 16, 17, and 18 are copied into a new String object, and that new String is returned. The result should be 5 characters long, so should not match "text", though.

Turns out the documentation for this function is crap, too. The 2nd argument is not the end of the substring, it is first position not copied into the substring. Dumb. Dumb. Dumb.

if (stringOne.substring(14,18) == "text") {

Serial.println("It's a text-based file");
}

If this kind of code isn't behaving as expected, break it down into steps and look what it's doing. In the example above, you could print out the result from stringOne.substring(14,18).

Korman

i though if (stringOne.substring(14,18) == "text")
it would extract the word text from "Content-Type: text/html"

All you are asking is if "text" is located at a certain place in the string, which only returns true/not true. If you want to extract what is at (14,18), then you might try something like below.

stringTwo = stringOne.substring(14,18);