With two RF-NANOs, the following code works well.
However, the wrong value is transmitted between RF-NANO and NodeMCU esp32 + RF24L01.
I don't know what the problem was.
send
0 15 25 3000
receive
0 15 25 11
0 15 25 11
sender
#include <RF24.h>
#include <SPI.h>
#include <nRF24L01.h>
struct Data {
public:
Data() {}
Data(uint8_t _no, uint8_t _temp, uint8_t _humi, uint16_t _co2) {
no = _no;
temp = _temp;
humi = _humi;
co2 = _co2;
}
uint8_t no; // sensor no
uint8_t temp;
uint8_t humi;
uint16_t co2;
};
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
void setup() {
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
}
void loop() {
// const char text[] = "Hello World";
const Data data(0, 15, 25, 3000);
radio.write(&data, sizeof(data));
delay(1000);
}
Receiver
#include <RF24.h>
#include <SPI.h>
#include <nRF24L01.h>
struct Data {
public:
Data() {}
Data(uint8_t _no, uint8_t _temp, uint8_t _humi, uint16_t _co2) {
no = _no;
temp = _temp;
humi = _humi;
co2 = _co2;
}
uint8_t no; // sensor no
uint8_t temp;
uint8_t humi;
uint16_t co2;
};
RF24 radio(9, 10); // CE, CSN // RF-NANO
RF24 radio(21, 22); // CE, CSN // NodeMCU esp32 + RF24L01
const byte address[6] = "00001";
void setup() {
Serial.begin(115200);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}
void loop() {
if (radio.available()) {
Data data;
radio.read(&data, sizeof(data));
Serial.print(data.no);
Serial.print(" ");
Serial.print(data.temp);
Serial.print(" ");
Serial.print(data.humi);
Serial.print(" ");
Serial.println(data.co2);
}
}