Saving RF24 signals to memory

I've been looking everywhere for an example of this and cannot find anything. If I am sending single binary numbers over RF24 using the nrf24lo1, is there a way to collect up to the last 10 numbers received and check to see if each new number is greater than the last?

Sure, they're just messages coming in, save them as a couple variables, compare latest received to prior received, save the higher on into a new variable.

For the life of me I cant figure this out. heres my code:

void loop(void)
{
  // Pump the network regularly
  network.update();

  // Is there anything ready for us?
  while ( network.available() )
  {
    // If so, grab it and print it out
    RF24NetworkHeader header;
    payload_t payload;
    network.read(header,&payload,sizeof(payload));
    Serial.print("Received scene #");
    Serial.println(payload.ms);
      if(newValue > payload.ms) {
        payload.ms = newValue;
        Serial.print(newValue);
        radio.stopListening();
      }
      else {
          Serial.println("no newValue");
      }
    }
    }

I'm using the RF24 library and im trying to get radio communication to stop listening if the new value is greater than the payload being received. Right now my serial is showing:

Received scene #2
no newValue
Received scene #3
no newValue

Any help would be awesome.

I wonder if you are confusing yourself with your choice of variable names. As far as I can see the thing you call newValue is really the previousValue.

With the values (2,3) that you have shown the previousValue is not greater than the incoming value so your test fails. Actually the test works perfectly - it's just that it's the wrong test.

...R

That worked! However I realized I neglected to say that I was planning on having the new values not only be larger than the previous but also only accept a new value if it is one (1) greater than the previous value. My new code is this and its not proving any positive results. My issue is in the loop I believe. It collects the new value however when it goes to loop the function that data is seemingly lost and the function starts looking for a new number…

/*
 Wireless show control communications between hayride wagon 
 and individual scenes.  Wagon receives scene numbers sent
 from scene nodes and cues playback of scenes in 
 chronological order
 
 RECEIVE NODE - use for wagons
*/

#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <nRF24L01.h>

// led pin
int ledPos = 1;
int ledNeg = 2;

// nRF24L01(+) radio attached using Getting Started board 
RF24 radio(9,10);

// Network uses that radio
RF24Network network(radio);

// Address of our node
const uint16_t this_node = 0;

// Address of the other node
const uint16_t other_node = 1;

// Structure of our payload
struct payload_t
{
  unsigned long ms;
  unsigned long counter;
};

long oldValue = 0;
long newValue = 0;

void setup(void)
{
  Serial.begin(57600);
  Serial.println();
  Serial.println("Onboard Receiver Activated & Ready");
  delay(2000);
 
  SPI.begin();
  radio.begin();
  network.begin(/*channel*/ 90, /*node address*/ this_node);
  
  digitalWrite(ledPos, LOW);
  digitalWrite(ledNeg, LOW);
}

void loop(void)
{
  // Pump the network regularly
  network.update();

  // Is there anything ready for us?
  while ( network.available() )
  {
    // If so, grab it and print it out
    RF24NetworkHeader header;
    payload_t payload;
    network.read(header,&payload,sizeof(payload));
    Serial.print("Received scene #");
    Serial.println(payload.ms);
    payload.ms = newValue;
      if(newValue = (oldValue + 1)) {
        oldValue = newValue;
        Serial.print("New Scene Detected");
        radio.stopListening();
        delay(5000);
        Serial.println("Ready to receive new scene");
        radio.startListening();
      }
      else {
          Serial.println("No New Scene Detected");
      }
    }
    }

Your scheme doesn't seem to be very reliable. If you miss a message, your system won't do anything.

if(newValue = (oldValue + 1))

You're missing an =

michinyon I’m still working on it and honestly do not have much programming experience. Ultimately I would like to have the code default to a “backup” command if the receiver does not receive the next number after 45 seconds, then start looking for the following number so it doesn’t lose track.

I still am having trouble having the new values saved to memory for the next iteration of the loop. my serial port looks like this:

Received scene #2
New Scene DetectedReady to receive new scene
Received scene #2
New Scene Detectedady to receive new scene
Received scene #2
New Scene DetectedReady to receive new scene
Received scene #2
New Scene Detected

DanBrookwell:
That worked! However I realized I neglected to say

Did you delete an earlier short reply and replace it with this?

Please don't do that as it is very confusing.

(And apologies if my memory is letting me down)

...R

I'm sorry i realized I had left out a great deal of info and I didnt want to double post... wont happen again.

Just wondering if anyone knew a solution to being able to loop and look for a new signal that is one more than the last?

Thanks

This is no longer an RF24 issue. You know how to send and receive a message containing a number. All you need to do now is handle the received number. To achieve what you want you will need to remember the 'current number' and I suggest you store that in a global variable. When you receive a number which equals current number plus one, update the current number to the new one. That requires two lines of code which you should find trivial to write compared to the work to get the RF24 interface working.