Pages: 1 [2]   Go Down
Author Topic: String issue  (Read 1222 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45985
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
But it's with the same result of the old code:
Changing the way that the collected data is made known to the caller will not change the data.

The problem is here:
Code:
  while (Uart.available() > 0)
  {
    incomingByte = (Uart.read());
    reply = reply + char(incomingByte);
  } 
This expects all the data to have arrived by the time that the function is called. There is no guarantee that this will happen.

There is some end-of-message marker that signifies that the complete message has been received. You need to wait, in the send_command function, until that end character is received.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is not working yet.
I still have this from the phone:
Code:
+CPMS="ME"

+CPMS: 1,70,0,30,1,70

OK

+CMGR=1

+CMGR: 1,,24
0791551118312800240B811079186914F500001

instead of:

Code:
+CPMS="ME"

+CPMS: 1,70,0,30,1,70

OK

+CMGR=1

+CMGR: 1,,24
0791551118312800240B811079186914F500001101313204812905CCF4392C07
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24308
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, we can see the output, but what does the code look like?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code now is:

Code:
#include <NewSoftSerial.h>

NewSoftSerial Uart(10, 11);

void send_command(String at_cmd, int dly, String &reply){

 // String msg;
  char incomingByte;
 
  Uart.println(at_cmd);
  delay(dly);
  while (Uart.available() > 0)
  {

    incomingByte = (Uart.read());
   // reply = reply + char(incomingByte);
reply += incomingByte; 

}



void setup() {

  Uart.begin(4800);
  Serial.begin(9600);
 
//Coloca o pino 13 em Output onde será ligado o relé
  pinMode(rele, OUTPUT);
  pinMode(botao, INPUT);

  String at_response;
  String at_response2;

 

  send_command("AT+CPMS=\"ME\"",1000, at_response);
Serial.print(at_response);

 
  send_command("AT+CMGR=1", 1000, at_response2);
Serial.println(at_response2);
 
 
 
}
void loop() {}


The output is:
+CPMS="ME"

+CPMS: 1,70,0,30,1,70

OK
+CMGR=1

+CMGR: 1,,24
0791551118312800240B811079186914F500001


The last line is the SMS message I need to read and compare. So this is incomplete.
It had to be:
0791551118312800240B811079186914F500001101313204812905CCF4392C07


thanks!

Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45985
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
+CPMS: 1,70,0,30,1,70
What do these numbers mean?

Code:
+CMGR: 1,,24
And these?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
+CPMS: 1,70,0,30,1,70
What do these numbers mean?

Code:
+CMGR: 1,,24
And these?


they are some answer from the phone (AT COMMAND), i don't know exactly what they mean, but they are useless for me.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 45985
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i don't know exactly what they mean, but they are useless for me.
If you don't know what they mean, how do you know that they are useless? What if one of the numbers indicated the message length? Wouldn't that be useful information?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i don't know exactly what they mean, but they are useless for me.
If you don't know what they mean, how do you know that they are useless? What if one of the numbers indicated the message length? Wouldn't that be useful information?

No because, the project is:
Some codes to see the serial connection with the phone, another command to change the memory to read (AT+CPMS="ME"), after I read the first message. If the message have the word "Ligar" but in PDU format (in PDU format the message content is the end of the line), the code turn a port HIGH. Else, do nothing.
If the message have the word "Desligar" but in PDU format, the code turn this same port, LOW.

because, I said this answer were useless for me. The line of the message is always with the same end for the messages I want to parse.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12425
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
+CMGR: 1,,24
07 91 55 11 18 31 28 00 24 0B 81 10 79 18 69 14 F5 00 00 1
07 91 55 11 18 31 28 00 24 0B 81 10 79 18 69 14 F5 00 00 11 01 31 32 04 81 29 05 CC F4 39 2C 07

looks definitely like some hexdump

lets google...
 
AT +CMGR - http://www.developershome.com/sms/cmgrCommand.asp -
The AT command +CMGR (command name in text: Read Message) is used to read a message from a message storage area. The location of the message to be read from the message storage area is specified by an index number. The message to be retrieved by the AT command +CMGR does not necessarily have to be an SMS message. It can be of other message types such as status reports and cell broadcast messages



AT +CPMS - http://www.developershome.com/sms/cpmsCommand.asp -
The AT command +CPMS (command name in text: Preferred Message Storage) serves several purposes. It can be used to:

1. Select the message storage area that will be used when sending, receiving, reading, writing or deleting SMS messages.

2. Find the number of messages that are currently stored in the message storage area.

3. Find the maximum number of messages that can be stored in the message storage area.

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
+CMGR: 1,,24
07 91 55 11 18 31 28 00 24 0B 81 10 79 18 69 14 F5 00 00 1
07 91 55 11 18 31 28 00 24 0B 81 10 79 18 69 14 F5 00 00 11 01 31 32 04 81 29 05 CC F4 39 2C 07

looks definitely like some hexdump

lets google...
 
AT +CMGR - http://www.developershome.com/sms/cmgrCommand.asp -
The AT command +CMGR (command name in text: Read Message) is used to read a message from a message storage area. The location of the message to be read from the message storage area is specified by an index number. The message to be retrieved by the AT command +CMGR does not necessarily have to be an SMS message. It can be of other message types such as status reports and cell broadcast messages



AT +CPMS - http://www.developershome.com/sms/cpmsCommand.asp -
The AT command +CPMS (command name in text: Preferred Message Storage) serves several purposes. It can be used to:

1. Select the message storage area that will be used when sending, receiving, reading, writing or deleting SMS messages.

2. Find the number of messages that are currently stored in the message storage area.

3. Find the maximum number of messages that can be stored in the message storage area.




yes, about the commands, they are what i said before.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm nearst now with this code:
Code:
char incomingByte;
#include <NewSoftSerial.h>

NewSoftSerial cell(10,11);
int rele = 12;

String response;


void setup() {
   cell.begin(9600);
   Serial.begin(9600);
   delay(500);
   
pinMode(rele, OUTPUT);   
digitalWrite(rele, LOW); 

   //Set memory to read sms from, ME = phone memory
 cell.println("AT+CPMS=\"ME\""); 
     delay(1000);
 
    cell.flush();
   Serial.flush();

     //Read received message
cell.println("AT+CMGR=1");
}
void loop(){
 


 
 if(cell.available() >0 && (!response.startsWith("079") && !response.endsWith("C07")))  {

   incomingByte = cell.read(), BYTE;
       // say what you got:       
       Serial.print(incomingByte);
       
       response = response + incomingByte;
 }
 

//se a mensagem tiver a palavra Ligar, ligar o rele.
if (response.substring(response.length()-12) == ("05CCF4392C07")) {

digitalWrite(rele, HIGH);

}



But the problem is with the loop.

After read the message, I have to delete it and continue verifying new messages to compare the content.

How can I do it?

thank all!
Logged

Pages: 1 [2]   Go Up
Jump to: