[SOLVED] nrf24l01 storing each packet in different array

hi guys

i am trying to store each sent packet from a transmitter to a receiver in a separate array
for example
arr1 for packet 1
arr2 for packet 2

how can this be made?

thanks in advance for ur help

Do a memcpy() from your dataReceived to the individual array where you want to store it.

gfvalvo:
Do a memcpy() from your dataReceived to the individual array where you want to store it.

thank u for ur reply

but i did not mean this

in the transmitter side i send a packet fully loaded which the receiver receives it successfully ,then i try to send another packet but the receiver can not receive it and receive the first element of the fully loaded packet once again

is there an example or guide line for what should be made?

these are the sketches if u r interested to know the case exactly

Tx

#include "sha256.h"
#include <Arduino.h>
#include "./printf.h"

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define CE_PIN   9
#define CSN_PIN 10

#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

// NOTE: the "LL" at the end of the constant is "LongLong" type
// These are the IDs of each of the slaves
const uint64_t slaveID = 0xE8E8F0F0E1L  ;

RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000;
int txVal = 0;
byte ackMessg[6];
byte ackMessgLen = 4; 

uint8_t* hash;
uint8_t copy[32];
void printHash(uint8_t* hash) {
  int i;
  for (i=0; i<32; i++) {
    Serial.print("0123456789abcdef"[hash[i]>>4]);
    Serial.print("0123456789abcdef"[hash[i]&0xf]);
      copy[i]=hash[i];
  }
  Serial.println();
}

void setup() {
  printf_begin();
  
  uint32_t a;
  unsigned long ms;
  
  sensors.begin();

  Serial.begin(9600);

  radio.begin();
    radio.setDataRate( RF24_2MBPS );
    radio.enableAckPayload();
    radio.setRetries(3,5); // delay, count

  // SHA tests
 /// Serial.println("Test: FIPS 180-2 B.1");
 /// Serial.println("Expect:ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
 /// Serial.print("Result:");
  ms = micros();
  Sha256.init();
  Sha256.print("abc");
  printHash(Sha256.result());
  Serial.println();
  for(int x=0;x<32;x++)
        {   //Serial.print(copy[x]);
           // Serial.print(" ");  
                                  }
         //   Serial.println();
            
  //Serial.print(" Hash took : ");
 // Serial.print((micros() - ms));
 // Serial.println(" micros");
 // Serial.println();
  
  }


void loop() {

  currentMillis = millis();
    if (currentMillis - prevMillis >= txIntervalMillis) {

    radio.openWritingPipe(slaveID); 
    bool rslt,rsltt;
    rslt = radio.write( copy, 32 );
  
    if ( radio.isAckPayloadAvailable() ) {
        radio.read(ackMessg,ackMessgLen);
        Serial.print("Acknowledge received: ");
        Serial.print(ackMessg[0]);
        Serial.print("  ");
        Serial.println(ackMessg[1]);
        
        if(ackMessg[1]==23)

       {sensors.requestTemperatures();
  Serial.print("Temperature is: ");
  byte x=sensors.getTempCByIndex(0);
  radio.openWritingPipe(slaveID);
  radio.write( x, sizeof(x) );
  radio.read(ackMessg,ackMessgLen);
  Serial.print(x);
  Serial.println();
    
    }
    prevMillis = millis();
 }
 
}}

Rx

int temperature ;
  unsigned long startTimer = millis();
    if ( radio.available() ) {
      byte temperature[1] ;
        radio.read( (char*)dataReceived, sizeof(dataReceived) );
        
       Serial.println(startTimer);
       Serial.println();
       for (int x = 0; x <32; x++) {
      //if (dataReceived[x] < 16) {
      //  Serial.write('0'); }
      Serial.print(dataReceived[x]);
      Serial.print(" ");
      }
       Serial.println();
        
    Serial.println();
       Serial.println();

       i = 0;
    do
    {
        bMatch = true;
        for( j=0; j<NUM_ELEMENTS; j++ )
            if( dataReceived[j] != buffers[i][j] )
                bMatch = false;           
        if( !bMatch )
            i++;
    }
    
    while( i < NUM_COMPARES && !bMatch );

    if( bMatch )
    { radio.writeAckPayload(1, ackData, sizeof(ackData));
        radio.read(temperature, sizeof(temperature));
        Serial.println("temperature is ");
         Serial.print(temperature[0]);
         Serial.println( );
        ackData[0] += valChange; // this just increments so you can see that new data is being sent
        Serial.print( "Match found at buffer[" );
        Serial.print(i);
        Serial.println( "]" );
    }
    else
        Serial.println( "No match found." );
    }

}

output at receiver

186 120 22 191 143 1 207 234 65 65 64 222 93 174 34 35 176 3 97 163 150 23 122 156 180 16 255 97 242 0 21 173
temperature is
173
Match found at buffer[0]

which shows that temperature value has not been received

i discovered the error

i did not put the rado.write line in the write place

these are my working codes

Rx

#include <SPI.h>
//~ #include <TMRh20nRF24L01.h>
//~ #include <TMRh20RF24.h>
#include <nRF24L01.h>
#include <RF24.h>

#define CE_PIN   9
#define CSN_PIN 10

#define NUM_COMPARES    2
#define NUM_ELEMENTS    32

const uint64_t   deviceID = 0xE8E8F0F0E1LL; // Define the ID for this slave

uint8_t  buffers[NUM_COMPARES][NUM_ELEMENTS] ={ {186, 120, 22 ,191, 143 ,1 ,207 ,234 ,65 ,65 ,64, 222, 93 ,174 ,34, 35, 176, 3 ,97 ,163 ,150, 23, 122 ,156, 180 ,16 ,255 ,97, 242, 0, 21 ,173},
  {86, 120, 22 ,191, 143 ,1 ,207 ,234 ,65 ,65 ,64, 222, 93 ,174 ,34, 35, 176, 3 ,97 ,163 ,150, 23, 122 ,156, 180 ,16 ,255 ,97, 242, 0, 21 ,173}}; 

int valChange = 1;

bool bMatch;
int i, j;

RF24 radio(CE_PIN, CSN_PIN);

uint8_t  dataReceived[32];
byte ackData[2] = {12,23};
byte tempReceived[4];

void setup() {

    Serial.begin(9600);
    Serial.println("Starting");
    radio.begin();
    radio.setDataRate( RF24_2MBPS );
    radio.openReadingPipe(1,deviceID);
    radio.enableAckPayload();
    radio.writeAckPayload(1, ackData, sizeof(ackData));
    radio.startListening();
}

void loop() {
  
int temperature ;
  unsigned long startTimer = millis();
    if ( radio.available() ) {
      byte temperature[1] ;
        radio.read( (char*)dataReceived, sizeof(dataReceived) );
        
       Serial.println(startTimer);
       Serial.println();
       for (int x = 0; x <32; x++) {
      //if (dataReceived[x] < 16) {
      //  Serial.write('0'); }
      Serial.print(dataReceived[x]);
      Serial.print(" ");
      }
       Serial.println();
        
    Serial.println();
       Serial.println();

       i = 0;
    do
    {
        bMatch = true;
        for( j=0; j<NUM_ELEMENTS; j++ )
            if( dataReceived[j] != buffers[i][j] )
                bMatch = false;           
        if( !bMatch )
            i++;
    }
    
    while( i < NUM_COMPARES && !bMatch );

    if( bMatch )
    { radio.writeAckPayload(1, ackData, sizeof(ackData));
        radio.read(temperature, sizeof(temperature));
        Serial.println("temperature is ");
         Serial.print(temperature[0]);
         Serial.println( );
        ackData[0] += valChange; // this just increments so you can see that new data is being sent
        Serial.print( "Match found at buffer[" );
        Serial.print(i);
        Serial.println( "]" );
    }
    else
        Serial.println( "No match found." );
    }

}

Tx

#include "sha256.h"
#include <Arduino.h>
#include "./printf.h"

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define CE_PIN   9
#define CSN_PIN 10

#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

// NOTE: the "LL" at the end of the constant is "LongLong" type
// These are the IDs of each of the slaves
const uint64_t slaveID = 0xE8E8F0F0E1L  ;

RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000;
int txVal = 0;
byte ackMessg[6];
byte ackMessgLen = 4;

uint8_t* hash;
uint8_t copy[32];
void printHash(uint8_t* hash) {
  int i;
  for (i=0; i<32; i++) {
    Serial.print("0123456789abcdef"[hash[i]>>4]);
    Serial.print("0123456789abcdef"[hash[i]&0xf]);
      copy[i]=hash[i];
  }
  Serial.println();
}

void setup() {
  printf_begin();
 
  uint32_t a;
  unsigned long ms;
 
  sensors.begin();

  Serial.begin(9600);

  radio.begin();
    radio.setDataRate( RF24_2MBPS );
    radio.enableAckPayload();
    radio.setRetries(3,5); // delay, count

  // SHA tests
 /// Serial.println("Test: FIPS 180-2 B.1");
 /// Serial.println("Expect:ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
 /// Serial.print("Result:");
  ms = micros();
  Sha256.init();
  Sha256.print("abc");
  printHash(Sha256.result());
  Serial.println();
  for(int x=0;x<32;x++)
        {   //Serial.print(copy[x]);
           // Serial.print(" "); 
                                  }
         //   Serial.println();
           
  //Serial.print(" Hash took : ");
 // Serial.print((micros() - ms));
 // Serial.println(" micros");
 // Serial.println();
 
  }


void loop() {

  currentMillis = millis();
    if (currentMillis - prevMillis >= txIntervalMillis) {

    radio.openWritingPipe(slaveID);
    bool rslt,rsltt;
    rslt = radio.write( copy, 32 );
    
 
    if ( radio.isAckPayloadAvailable() ) {
        radio.read(ackMessg,ackMessgLen);
        Serial.print("Acknowledge received: ");
        Serial.print(ackMessg[0]);
        Serial.print("  ");
        Serial.println(ackMessg[1]);
       
        if(ackMessg[1]==23)

       {//sensors.requestTemperatures();

       Serial.print("Temperature is: ");
  byte x=sensors.getTempCByIndex(0);
  radio.openWritingPipe(slaveID);
  radio.write( &x, sizeof(x) );
  
  radio.read(ackMessg,ackMessgLen);
  Serial.print(x);
  Serial.println();
   
    }
    prevMillis = millis();
 }
 
}}