whith this code the output is clear, but when y put de serial.print (// Serial.println("valida"+valida)
the output is not clear, a lot of numbers.
Paste my cod under de text,
Thanks,
My setup is:
void setup()
{
//digitalWrite(9,HIGH);
//delay(1000);
Serial.println("Esperando Mensajes");
Serial.begin(19200); // for serial monitor
mySerial.begin(19200); // for GSM shield
mySerial.print("AT+CMGF=1\r"); // set SMS mode to text
delay(100);
mySerial.print("AT+CNMI=2,2,0,0,0\r");
// blurt out contents of new SMS upon receipt to the GSM shield's serial out
delay(100);
}
void loop()
{
char SerialInByte;
// Now we simply display any text that the GSM shield sends out on the serial monitor
if(mySerial.available() >0)
{
incoming_char=mySerial.read(); //Get the character from the cellular serial port.
Serial.print(incoming_char); //Print the incoming character to the terminal.
delay(5);
//-------------------------------------------
smsRecibo = String(smsRecibo + incoming_char);
largo = smsRecibo.length();
//valida si prende o apaga, largo 13
if (largo=13)
{
mensaje = smsRecibo; //Serial.print(mensaje);
int elemento = mensaje.indexOf('O'); //palabra ON o OF
String valida = mensaje.substring(elemento,1);
//prende automatico control por humedad
//T000
if (valida == "ON")
{
//se llama a subrutina para seguir parseando
// Serial.println("valida"+valida);
validar();
}
//apaga
Most people use == in if statements, for good reason.
tell me what is the best solution for this problem,
First, strings and Strings are completely different things. Do NOT use string when you mean String.
Strings really have no place on the Arduino.
But, since you have them, it pays to read the documentation. The indexOf() method takes a character OR a String, and determines if the object it is called on contains the character or String.
So, if you want to know if a String contains "ON", just ask.
int onPos = mensaje.IndexOf("ON");
if(onPos >= 0)
{
// mensaje contains "ON"
}
else
{
// Well, it doesn't
}
my idea is print in the serial monitor: "Largo 10" for example.
but the problem is: the monitor when i used 9600 for other programs print well, but in this program where i used sim900 set monitor to 19200.
in this escenario the messages for sim900 print well, but the others serial print not.
The baud rate you use to talk to the serial port that the PC is listening to has no relationship with the baud rate you use to talk to the modem. If using 9600 to talk to the PC, keep using that. It doesn't matter that you talk to the modem at a different speed.