if i reset de arduino i get difereng data ex:
Read: 41
Read: 54
Read: D
Read: D
Read: A
inData: [AT]
Read: 4F
Read: 4B
Read: D
Read: A
inData: [OK]
Read: 41
Read: 54
Read: D
Read: D
Read: A
inData: [AT]
Read: 4F
Read: 4B
Read: D
Read: A
inData: [OK]
Read: 41
Read: 54
Read: 2B
Read: 43
Read: 41
Read: 54
Read: D
Read: D
Read: A
inData: [AT]
Read: 4F
Read: 4B
Read: D
Read: A
inData: [OK]
Read: 41
Read: 54
Read: D
Read: D
Read: A
inData: [AT]
Read: 4F
Read: 4B
Read: D
Read: A
inData: [OK]
Read: 41
Read: 54
Read: 2B
Read: 43
Read: 4D
Read: 47
Read: 46
Read: 3D
Read: 31
Read: D
Read: D
Read: A
inData: [AT+CMGF=1]
Read: 4F
Read: 4B
Read: D
Read: A
inData: [OK]
Read: 41
Read: 54
Read: 2B
Read: 43
Read: 50
Read: 4D
Read: 53
Read: 3D
Read: 22
Read: 53
Read: 4D
Read: 22
Read: 2C
Read: 22
Read: 53
Read: 4D
Read: 22
Read: 2C
Read: 22
Read: 53
Read: 4D
Read: 22
Read: D
Read: D
Read: A
inData: [AT+CPMS="SM","SM","SM]
Read: 2B
Read: 43
Read: 50
Read: 4D
Read: 2B
Read: 43
Read: 4D
Read: 47
Read: 4C
Read: 3A
Read: 20
Read: 32
Read: 2C
Read: 22
Read: 52
Read: 45
Read: 43
Read: 20
Read: 52
Read: 45
Read: 41
Read: 44
Read: 22
Read: 2C
Read: 22
Read: 37
Read: 22
Read: 32
Read: 22
Read: A
inData: [+CPM+CMGL: 2,"REC READ","7"2"]
Read: A
inData: []
any problem?
PaulS:
OK. So, you are seeing an end of packet marker, as evidenced by the inData stuff being printed after the if(ended) statement.
Comment out the first set of Serial.print() statements.
After the if(ended) statement, you now need to parse the replies from the device. Since the reply is a string (a NULL terminated array of chars), all the normal string functions (strstr(), for instance) can be used.
Can you please Dear Sr. explain me beter what i have to put in the function (strstr(), for instance) ?
Thanks
system
July 30, 2012, 7:19pm
24
explain me beter what i have to put in the function (strstr(), for instance) ?
strstr() takes two arguments - the string to search and the string to search for. So:
if(strstr(inData, "REC READ"))
{
// Hey, this is the REC READ response...
}
I don't know what else you want from that record, so you'll have to do the rest.
Read: 41 in decimal is 65 and Leter A
Read: 54 84 Leter T
Read: D 13 Carriage Return
Read: D 13 Carriage Return
Read: A 10 Line Feed
#include <SoftwareSerial.h>
SoftwareSerial phone(2, 3);
#define EOP '\n'
bool started = false;
bool ended = false;
char inData[280];
byte index;
void setup()
{
phone.begin(9600);
delay(500);
Serial.begin(9600);
phone.println("AT");//text mode
delay(500);
phone.println("AT");//text mode
delay(500);
phone.println("AT+CMGF=1");//text mode
delay(500);
phone.println("AT+CPMS=\"SM\",\"SM\",\"SM\"\r\n");
delay(500);
phone.println("AT+CMGL=\"ALL\"\r");
//Serial.println("AT+CMGD=1");//delete sms
delay(500);
}
void loop()
{
while(phone.available() > 0)
{
char inChar = phone.read();
Serial.print("Read: ");
Serial.println(inChar, HEX);
if(inChar == EOP)
{
ended = true;
break;
}
else
{
if(index < 279)
{
inData[index] = inChar;
index++;
inData[index] = '\0';
}
}
}
if(ended)
{
Serial.print("inData: [");
Serial.print(inData);
Serial.println("]");
ended = false;
index = 0;
inData[index] = '\0';
}
if(strstr(inData, "REC READ"))
{
Serial.println("REC READ FOUND");
}
}
I get "REC READ FOUND" afther severel loops now i want to read the sms "body" that is in this case "Stop" but the string dont get there ( dont stor, i try to chang the if(strstr(inData, "REC READ")) to if(strstr(inData, "Stop") but no sucess) any ideas? Thanks
+CPM+CMGL: 2,"REC READ","351910172170","Meu91","12/07/24,22:38:14+04",145,4
Stop
system
July 31, 2012, 10:08am
27
now i want to read the sms "body" that is in this case "Stop" but the string dont get there
OK.
Where did this:
+CPM+CMGL: 2,"REC READ","351910172170","Meu91","12/07/24,22:38:14+04",145,4
Stop
come from?
What does ALL of your serial output look like? At least the part after "REC READ FOUND" is printed?
Hi,
Terminal
...................
...................
...................
Read: 45
Read: 41
Read: 44
Read: 22
Read: 2C
Read: 22
Read: 33
Read: 37
Read: 22
Read: 32
Read: 22
Read: 2C
Read: 6F
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
REC READ FOUND
...................
...................
...................
"REC READ FOUND" is printed.
+CPM+CMGL: 2,"REC READ","351910172170","Meu91","12/07/24,22:38:14+04",145,4
Stop
This dont print by your code only with the
#include <SoftwareSerial.h>
SoftwareSerial phone(2, 3);
char incomingByte = 0;
void setup(){
phone.begin(9600);
delay(500);
Serial.begin(9600);
phone.println("AT");//text mode
delay(500);
phone.println("AT");//text mode
delay(500);
phone.println("AT+CMGF=1");//text mode
delay(500);
phone.println("AT+CPMS=\"SM\",\"SM\",\"SM\"\r\n");
delay(500);
phone.println("AT+CMGL=\"ALL\"\r");
//Serial.println("AT+CMGD=1");//delete sms
delay(500);
}
void loop() {
while(1){
if (phone.available() > 0) {
incomingByte = phone.read();
Serial.print(incomingByte);
}
}
}
system
July 31, 2012, 1:00pm
29
This:
if(strstr(inData, "REC READ"))
{
Serial.println("REC READ FOUND");
}
belongs INSIDE this block,
if(ended)
{
Serial.print("inData: [");
Serial.print(inData);
Serial.println("]");
ended = false;
index = 0;
inData[index] = '\0';
}
as I've told you before.
If your message (Stop) doesn't end with a CR/LF, the Arduino will keep reading, and tacking data onto the array, until the CR/LF does arrive.
if i use:
void loop()
{
while(phone.available() > 0)
{
char inChar = phone.read();
Serial.print("Read: ");
Serial.println(inChar, HEX);
if(inChar == EOP)
{
ended = true;
break;
}
else
{
if(index < 279)
{
inData[index] = inChar;
index++;
inData[index] = '\0';
}
}
}
if(ended)
{
Serial.print("inData: [");
Serial.print(inData);
Serial.println("]");
ended = false;
index = 0;
inData[index] = '\0';
if(strstr(inData, "REC READ"))
{
Serial.println("REC READ FOUND");
}
}
}
i dont get "REC READ FOUND"
system
July 31, 2012, 1:35pm
31
if i use:...i dont get "REC READ FOUND"
Of course you don't.
Add some comments to the code, to explain what you think each line is doing. I'll correct any misconceptions.
With this :
#include <SoftwareSerial.h>
SoftwareSerial phone(2, 3);
#define EOP '\n'
bool started = false;
bool ended = false;
char inData[280];
byte index;
void setup()
{
phone.begin(9600);
delay(500);
Serial.begin(9600);
phone.println("AT");//text mode
delay(500);
phone.println("AT");//text mode
delay(500);
phone.println("AT+CMGF=1");//text mode
delay(500);
phone.println("AT+CPMS=\"SM\",\"SM\",\"SM\"\r\n");
delay(500);
phone.println("AT+CMGL=\"ALL\"\r");
//Serial.println("AT+CMGD=1");//delete sms
delay(500);
}
void loop()
{
while(phone.available() > 0)
{
char inChar = phone.read();
Serial.print("Read: ");
Serial.println(inChar, HEX);
if(inChar == EOP)
{
ended = true;
break;
}
else
{
if(index < 279)
{
inData[index] = inChar;
index++;
inData[index] = '\0';
}
}
}
if(ended)
{
Serial.print("inData: [");
Serial.print(inData);
Serial.println("]");
ended = false;
index = 0;
inData[index] = '\0';
}
if(strstr(inData, "REC READ"))
{
Serial.println("REC READ FOUND");
}
}
i get REC READ FOUND
but if i use if(strstr(inData, "Stop")) dont, the storing stops before all data came in
if(ended)
{
Serial.print("inData: [");
Serial.print(inData);
Serial.println("]");
ended = false;
index = 0;
inData[index] = '\0';
}
if(strstr(inData, "Stop"))
{
Serial.println("Stop FOUND");
}
}
system
July 31, 2012, 1:55pm
35
So, when the carriage return arrives, you set the index position back to 0, and stuff a NULL in the first element of the array. The strstr() function then starts at the first element of the array, matching characters in the 2nd array, until it encounters a NULL in the first array (or the second one).
Since it hits the NULL right off the bat, inData will never match "Stop", after the carriage return arrives.
But, I can't see your serial output, so I can't see what is really happening for you.
this is what a get
Terminal:
Read: 41
Read: 54
Read: D
Read: D
Read: A
inData: [AT]
Read: 4F
Read: 4B
Read: D
Read: A
inData: [OK]
Read: 41
Read: 54
Read: D
Read: D
Read: A
inData: [AT]
Read: 4F
Read: 4B
Read: D
Read: A
inData: [OK]
Read: 41
Read: 54
Read: 2B
Read: 43
Read: 4D
Read: 47
Read: 46
Read: 3D
Read: 31
Read: D
Read: D
Read: A
inData: [AT+CMGF=1]
Read: 4F
Read: 4B
Read: D
Read: A
inData: [OK]
Read: 41
Read: 54
Read: 2B
Read: 43
Read: 50
Read: 4D
Read: 53
Read: 3D
Read: 22
Read: 53
Read: 4D
Read: 22
Read: 2C
Read: 22
Read: 53
Read: 4D
Read: 22
Read: 2C
Read: 22
Read: 53
Read: 4D
Read: 22
Read: D
Read: D
Read: A
inData: [AT+CPMS="SM","SM","SM"]
Read: 2B
Read: 43
Read: 50
Read: 4D
Read: 2B
Read: 43
Read: 4D
Read: 47
Read: 4C
Read: 3A
Read: 20
Read: 32
Read: 2C
Read: 22
Read: 52
Read: 45
Read: 43
Read: 20
Read: 52
Read: 45
Read: 41
Read: 44
Read: 22
Read: 2C
Read: 22
Read: 31
Read: 4D
Read: 37
Read: 2B
Read: 22
Read: 2C
Read: D
system
July 31, 2012, 2:22pm
37
this is what a get
Which is not as much as you were getting. Why? What are you doing different?
Im lost... i need to:
1 st if is present get "REC READ"
2 read sms body
3 dependig in what is on it (sms body) do stuff
i cant tell, sory
Which is not as much as you were getting. Why? What are you doing different?
system
July 31, 2012, 2:40pm
39
Every time you run the code, you seem to get different output. I think you need to work first on getting consistent output. Then, you can figure out how to parse the data.
Modify the code that seems to print all the data, to print it one character at a time, printing that character as a character and in HEX format, so we can see what the whole message looks like.
Can you please explain how can i get "consistent output"?
Thanks