Sieć nRF24 i przesyłanie struktur

/*
Nadajnik
*/

/*
Nadajnik
*/
#include <RF24.h>
#include <RF24Network.h>


RF24 radio(7, 8);               // nRF24L01 (CE,CSN)
RF24Network network(radio);      // Include the radio in the network
const uint16_t this_node = 00;   // Address of this node in Octal format ( 04,031, etc)
const uint16_t node01 = 01; // (Address where the data is going)

struct package
  {
    float temp = 11.11;
    float hum = 22.22;
    uint16_t light = 33;
    uint16_t batt = 44; 
  };
typedef struct package Package;
Package data;

void setup() {

  Serial.begin(9600);

//  SPI.begin();
  radio.begin();
  radio.setPALevel(RF24_PA_HIGH);
  network.begin(32, this_node);  //(channel, node address)
}

void loop() {

  network.update();

  RF24NetworkHeader header(node01);     // (Address where the data is going)
  bool ok = network.write(header, &amp;data, sizeof(data)); // Send the data
  Serial.println("sending array...");
  delay(1000);
}
/*
 * Odbiornik
 * 
 */

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

RF24 radio(7, 8); 
RF24Network network(radio);      // Include the radio in the network
const uint16_t this_node = 01;   // Address of this node in Octal format ( 04,031, etc)
//const uint16_t node00 = 00;      // (Address where the data is going)

struct package
  {
    float temp = 11.11;
    float hum = 22.22;
    uint16_t light = 33;
    uint16_t batt = 44; 
  };
typedef struct package Package;
Package incomingData;

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.setPALevel(RF24_PA_HIGH);
  network.begin(32, this_node); //(channel, node address)
}

void loop() {
  
  network.update();
  while ( network.available() ) {     // Is there any incoming data?
    RF24NetworkHeader header;

    network.read(header, &amp;incomingData, sizeof(incomingData)); // Read the incoming data
    
      Serial.println("Struktura, 4 elementy:");
      Serial.println(incomingData.temp);
      Serial.println(incomingData.hum);
      Serial.println(incomingData.light);
      Serial.println(incomingData.batt);
      Serial.println("Koniec");

  }

}
LINKI

Dodaj komentarz