Guest User

Untitled

a guest
Aug 5th, 2019
158
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //SENDER
  2.  
  3. #include <SPI.h>            
  4. #include <nRF24L01.h>
  5. #include <RF24.h>
  6. #include <DHT.h>
  7.  
  8. RF24 radio(7, 8);    // CE, CSN
  9. const byte address[6] = "00001";
  10.  
  11. struct packageOfWeatherData{            // data struct of received data from outside
  12.     float temperature;
  13.     float humidity;
  14.     float heatindex;
  15.   };
  16. typedef struct packageOfWeatherData PackageOfWeatherData;
  17. PackageOfWeatherData weatherDataPackage;
  18.  
  19. struct fullWeatherDataPackage{        //data struct of received outside and measured inside data
  20.     float outTemperature;
  21.     float outHumidity;
  22.     float inTemperature;
  23.     float inHumidity;
  24.   };
  25. typedef struct fullWeatherDataPackage FullWeatherDataPackage;
  26. FullWeatherDataPackage inOutWeatherData;                  // <--- this will be sent to the other Arduino
  27.  
  28. DHT dht(2, DHT11);
  29.  
  30. void setup() {
  31.   radio.begin();
  32.   radio.openReadingPipe(1, address);
  33.   radio.setPALevel(RF24_PA_MAX);
  34.   radio.setChannel(100);
  35.   radio.setDataRate(RF24_250KBPS);
  36.   radio.startListening();
  37.  
  38.   dht.begin();
  39.  
  40.   Serial.begin(115200);
  41.  
  42. }
  43.  
  44. void loop() {
  45.  
  46.    if (radio.available()) {
  47.         radio.read(&weatherDataPackage, sizeof(weatherDataPackage));
  48.      //   Serial.print("új adat   "); Serial.println(millis()/1000);
  49.  
  50.         inOutWeatherData.outTemperature = weatherDataPackage.temperature;
  51.         inOutWeatherData.outHumidity = weatherDataPackage.humidity;
  52.         inOutWeatherData.inTemperature = dht.readTemperature();
  53.         inOutWeatherData.inHumidity = dht.readHumidity();
  54.  
  55. //        Serial.print(F("Outside Temperature: ")); Serial.print(inOutWeatherData.outTemperature, 1); Serial.print(F("°C    "));
  56. //        Serial.print(F("Outside Humidity: ")); Serial.print(inOutWeatherData.outHumidity, 0); Serial.print(F("%    "));
  57. //        Serial.print(F("Inside Temperature: ")); Serial.print(inOutWeatherData.inTemperature, 1); Serial.print(F("°C    "));
  58. //        Serial.print(F("Inside Humidity: ")); Serial.print(inOutWeatherData.inHumidity, 0); Serial.println(F("%    "));
  59.  
  60.         Serial.write((byte*)&inOutWeatherData, sizeof(inOutWeatherData));         // sending struct package to the other Arduino
  61.     }
  62. }
  63.  
  64.  
  65.  
  66.  
  67. //-----------------------------RECEIVER-----------------------
  68.  
  69. struct fullWeatherDataPackage{        //data struct of received outside and measured inside data
  70.     float outTemperature;
  71.     int outHumidity;
  72.     float inTemperature;
  73.     int inHumidity;
  74.   };
  75. typedef struct fullWeatherDataPackage FullWeatherDataPackage;
  76. FullWeatherDataPackage inOutWeatherData;
  77.  
  78. void setup() {
  79.   Serial.begin(115200);
  80.  
  81. }
  82.  
  83. void loop() {
  84.  
  85.  
  86.   Serial.readBytes((byte*)&inOutWeatherData, sizeof(inOutWeatherData));
  87.  
  88.   Serial.print(F("Outside Temperature: ")); Serial.print(inOutWeatherData.outTemperature, 1); Serial.print(F("°C    "));
  89.   Serial.print(F("Outside Humidity: ")); Serial.print(inOutWeatherData.outHumidity, 0); Serial.print(F("%    "));
  90.   Serial.print(F("Inside Temperature: ")); Serial.print(inOutWeatherData.inTemperature, 1); Serial.print(F("°C    "));
  91.   Serial.print(F("Inside Humidity: ")); Serial.print(inOutWeatherData.inHumidity, 0); Serial.println(F("%    "));
  92.  
  93.  
  94.   delay(1000);
  95.  
  96. }
RAW Paste Data