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

// تعريف الـ NRF24L01
RF24 radio(4, 5); // CE→14, CSN→12 على ESP32
const byte address[6] = "00001";

// هيكل البيانات (يجب أن يطابق المرسل تمامًا)
struct SensorData {
  float temperature;
  float humidity;
  float pressure;
  float accelX, accelY, accelZ;
  float gyroX, gyroY, gyroZ;
};

SensorData receivedData;

void setup() {
  Serial.begin(115200);
  
  // تهيئة الـ NRF24L01
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
}

void loop() {
  if (radio.available()) {
    radio.read(&receivedData, sizeof(receivedData));
    
    // طباعة البيانات في الـ Serial Monitor
    Serial.println("====== البيانات المستلمة =======");
    Serial.print("الحرارة: "); Serial.print(receivedData.temperature, 2); Serial.println(" °C");
    Serial.print("الرطوبة: "); Serial.print(receivedData.humidity, 2); Serial.println(" %");
    Serial.print("الضغط: "); Serial.print(receivedData.pressure, 2); Serial.println(" hPa");
    
    Serial.println("-- التسارع (g) --");
    Serial.print("X: "); Serial.print(receivedData.accelX, 2);
    Serial.print(" | Y: "); Serial.print(receivedData.accelY, 2);
    Serial.print(" | Z: "); Serial.println(receivedData.accelZ, 2);
    
    Serial.println("-- الجيروسكوب (°/ث) --");
    Serial.print("X: "); Serial.print(receivedData.gyroX, 2);
    Serial.print(" | Y: "); Serial.print(receivedData.gyroY, 2);
    Serial.print(" | Z: "); Serial.println(receivedData.gyroZ, 2);
    Serial.println("=============================");
  }
}