4
I’m having trouble saving a text message in a variable. The idea is to send an SMS with a command and later use a conditional operator to activate or deactivate a relay.
But I can’t save the SMS message. Whenever I try to save it, it takes on the value of:
" ÿ "
.
I’m using a GSM sim900 module with the Arduino.
Follow the code I’m trying to use:
#include <SoftwareSerial.h>
SoftwareSerial cell(2,3);
void setup()
{
cell.begin(19200);
cell.println("AT+CMGF=1");
delay(200);
cell.println("AT+CNMI=3,2,0,0");
delay(200);
}
void loop()
{
if(cell.available() >0) // se o shild resceber uma msg
{
delay(10);
msg=cell.read(); // salve ela na variavel msg
Serial.println(msg);// mostra o valor do "msg" NESSE ponto ela esta valendo ÿ
if (msg=='a') // se o primeiro caracter for "a"
{
delay(10);
msg=cell.read();
if (msg=='0') // se o segundo caracter for "0"
{
delay(10);
msg=cell.read();
if (msg=='e') // se o terceiro caracter for "e"
{
}
}
}
}
}
When printing the message in the serial, its value is ÿ
, why that?
I researched and found that before telling the Arduino to store the SMS, we have to tell him to "listen" the serial that receives the message and this is related to:
gsm.listen();
But I didn’t understand the relationship very well.
@brasofilo the language of Arduino is called Arduino ;)
– Oralista de Sistemas
Arduino’s language is C!
– Trxplz0
I’m studying some four or five programming language, it was bad not to have put... to Moh lost, thank you
– Bruno Inacio
@Trxplz0 I think the OP code is in C, but the official language of Arduino is really called Arduino.
– Oralista de Sistemas
you are printing
msg
before readingmsg
.– Lucas Virgili
áh eé... the error of vc this printing msg before reading, was from now on at the time of posting... ops
– Bruno Inacio
discovered a few more things, before entering the loop we should tell where the module should save the text with the code
AT+CPMS=?
– Bruno Inacio