Advertisement
Guest User

Untitled

a guest
Aug 5th, 2013
449
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void setup()
  2. {
  3.   //Start communications radio
  4.   //Serial.begin(9600);
  5.   SPI.begin();
  6.   radio.begin();
  7.   network.begin(/*channel*/ 90, /*node address*/ this_node);
  8.  
  9.   analogReference(DEFAULT);
  10.   //delay(1000);
  11.   pinMode(2, INPUT);
  12.   //attachInterrupt(0, messageReceived, FALLING);
  13.  
  14.   //Sleep the NRF24L01
  15.   //radio.powerDown();
  16.  
  17.   //Sleep the MCU
  18.   //LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
  19. }
  20.  
  21. void(* resetFunc) (void) = 0; //declare reset function @ address 0
  22.  
  23. void loop()
  24. {  
  25.   attachInterrupt(0, messageReceived, FALLING);
  26.   //radio.powerDown();
  27.   LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
  28.   //radio.powerUp();
  29.   detachInterrupt(0);
  30.  
  31.   network.update();
  32.  
  33.   if(network.available())
  34.   {
  35.     // If so, grab it and print it out
  36.     RF24NetworkHeader header;
  37.     payload_t payload;
  38.     network.read(header, &payload, sizeof(payload));
  39.  
  40.     //Interrogation de toutes les données
  41.     if((payload.value == 0) && (header.from_node == edams_server))
  42.     {
  43.       int chk = dht22.read22(DHT22_PIN);
  44.       if(chk == DHTLIB_OK)
  45.       {
  46.         dht22_temperature_data_send();
  47.         dht22_humidity_data_send();
  48.       }
  49.       battery_level_send();
  50.     }
  51.     //Interrogation d'une donnée précise
  52.     else if ((payload.value == 1) && (header.from_node == edams_server))
  53.     {
  54.       if(payload.id == 301 || payload.id == 302)
  55.       {
  56.         int chk = dht22.read22(DHT22_PIN);
  57.         if(chk == DHTLIB_OK)
  58.         {
  59.           if(payload.id == 301)
  60.             dht22_temperature_data_send();
  61.           else if(payload.id == 302)
  62.             dht22_humidity_data_send();
  63.         }
  64.       }
  65.       else if(payload.id == 303)
  66.       {
  67.         battery_level_send();
  68.       }
  69.     }
  70.     //Interrogation du firmware du noeud
  71.     else if ((payload.value == 9) && (header.from_node == edams_server))
  72.     {
  73.     }
  74.   //resetFunc();  //call reset
  75.   }
  76. }
Advertisement
RAW Paste Data Copied
Advertisement