Hi fellows,
I am new in Arduino world, and Im trying to make my final project in the plataform Arduino UNO. But I am having a kind of problem that I am not being able to solve. That´s why I am here to ask the community help.
So, what I am trying to do is make two hops with three Arduinos. In a nutshell, I´m trying to send by Xbee Shield a packet in this format
(2#1#0#) -> (destinationHost, sourceHost, hop). To you understand, my 3 arduinos, have an identification such as 1, 2 and 3.
If I tell you that I am sending a packet from (1) to (2), I wold use this (2#1#0#).
But as I told, I am having problem in a method of my code that is displayed bellow:
Beacon Service::recebeBeacon(short id) {
Beacon beacon;
String msg;
while(Serial.available() > 0) {
byte temp = Serial.read();
msg = msg + (char) temp;
}
Serial.flush();
if (msg.length() > 0) {
beacon = converteStringParaBeacon(msg);
delay(1000);
Serial.flush();
if (verificaMensagemBeacon(beacon,id)) {
return beacon;
}
}
return beacon;
}
My arduino (1) just sends the packet like this (2#1#0#), and it is ok!
void loop() {
//Send beacon com Dest(2), Source(1), Hop(0)
beacon = Beacon(2,1,0);
service.enviaBeacon(beacon);
delay(2000);
}
But, when I get the message with Arduino (2), I get a lot of garbage, however the message comes two. Look at the picture attached and
you´ll understand. Please, does anyone knows what is happening???
void loop() {
recebe = service.recebeBeacon(ard_8);
delay(2000);
//recebe.getDhost(), recebe.getShost(), recebe.getSALTO() are short types
beacon = Beacon(recebe.getDhost(), recebe.getShost(), recebe.getSALTO());
Serial.println(service.converteBeaconParaString(beacon));
delay(2000);
}
Am I being clear, guys?
Thank you so muck for your attention.