hey guys, let me briefly explain what i am trying to do:
i have a raspberry pi (rpi from now on) and an arduino uno (uno from now on).
i have connected a pair of nrf24l01 to both my rpi and uno. the idea is, uno will read temp and send it to rpi. but i dont want uno to constantly read and send the data; i want uno to read the temp whenever i want it to read. for this purpose i switch uno to listener and rpi to writer.
what i am trying to do is: i am sending an "onn" message from rpi, and arduino will receive the message. if it confirms that it is an "onn" message, then uno will switch back to writer and read the temp and send it to rpi.
so guys, if i was clear with my explanation, this is the part of my code in uno that listens from rpi:
void fromPi() {
const uint64_t listen_addr = 0xF0F0F0F0E0LL;
radio.openReadingPipe(1,listen_addr);
radio.enableDynamicPayloads();
radio.powerUp();
radio.startListening();
char msg[] = {0};
if(radio.available()) {
radio.read(msg,radio.getDynamicPayloadSize());
//Serial.println(msg);
String decoded(msg);
if (decoded == "onn") {
Serial.println("inside on");
decoded == "something else";
}
else if (decoded != "onn") {
Serial.println("inside else");
}
}
}
this piece of code works, when i send "onn" from rpi, it will print "inside on". then if i stop sending "onn" from rpi, arduino wont print out anything.
upon seeing this result, i changed the code to look like this:
bool fromPi() {
const uint64_t listen_addr = 0xF0F0F0F0E0LL;
radio.openReadingPipe(1,listen_addr);
radio.enableDynamicPayloads();
radio.powerUp();
radio.startListening();
char msg[] = {0};
if(radio.available()) {
radio.read(msg,radio.getDynamicPayloadSize());
//Serial.println(msg);
String decoded(msg);
return decoded == "onn";
}
}
since this is a bool function, i wanted it to return either 0 or 1, just like how serial.available returns 0 or 1. but for some reason it returns 55. also, if i start my rpi code, meaning if i send "onn" message, then it returns 1. but if i stop my rpi code, meaning i wont send "onn" message, it still returns 1.
i want my code to work just like serial.available. what to and what not to do?
thanks in advance