//CODE SOURCE - PROJET DOMOTIQUE - SIMON GARNIER pour DFS Q2 2019
//Partie capteur météo à utiliser sur Arduino UNO
//_______________________________________________________________

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#include <DHT.h>

#define DHTPIN 2                
#define DHTTYPE DHT11           
DHT dht(DHTPIN, DHTTYPE);       

int ledvert = 10;
int ledbleu = 9;
RF24 transmit (7,8);                            
byte address [5] = "00001";                     

struct package
  {
    float temperature = 0;
    float humidite = 0; 
  };

typedef struct package Package;
Package data;

//SETUP________________________________________________________________________
void setup() {
  pinMode(ledvert, OUTPUT);
  pinMode(ledbleu, OUTPUT);
  digitalWrite(ledvert, HIGH);
  dht.begin();
  transmit.begin();
  transmit.openWritingPipe(address);            
  transmit.setPALevel(RF24_PA_MAX);            
  transmit.setDataRate(RF24_250KBPS);           
  transmit.setChannel(100);                     
  transmit.stopListening();
  }
//LOOP_________________________________________________________________________
void loop() {
  data.temperature = dht.readTemperature();
  data.humidite = dht.readHumidity();
  transmit.write(&data,sizeof(data));
  digitalWrite(ledbleu, HIGH);
  delay(1000);
  digitalWrite(ledbleu, LOW);
  delay(5000);                                
}