Advertisement
Guest User

Untitled

a guest
Nov 15th, 2012
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. /*
  2. Copyright (C) 2012 James Coliz, Jr. <maniacbug@ymail.com>
  3. RF24 libraries and code
  4. Copyright 2009 Jonathan Oxer <jon@oxer.com.au>
  5. SHT1x library and code
  6. Copyright ???? ???? ???? ???????
  7. DallasTemperature library and code
  8. Copyright 2012 C. LeBlanc <ominously.chaotic@gmail.com>
  9. Mashing it all together
  10.  
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. version 2 as published by the Free Software Foundation.
  14. */
  15.  
  16. #include <RF24Network.h>
  17. #include <RF24.h>
  18. #include <SPI.h>
  19. #include <SHT1x.h>
  20. #include <OneWire.h>
  21. #include <DallasTemperature.h>
  22.  
  23. #define dataPin 8
  24. #define clockPin 7
  25. #define ONE_WIRE_BUS 6
  26.  
  27. RF24 radio(9,10);
  28. RF24Network network(radio);
  29.  
  30. SHT1x sht1x(dataPin, clockPin);
  31. OneWire oneWire(ONE_WIRE_BUS);
  32. DallasTemperature sensors(&oneWire);
  33.  
  34. DeviceAddress outsideTemp = {0x28, 0x9B, 0xFB, 0xDE, 0x03, 0x00, 0x00, 0x71};
  35.  
  36. const uint16_t outside = 1;
  37. const uint16_t base = 0;
  38. const unsigned long interval = 2000; //ms
  39. unsigned long last_sent;
  40.  
  41. struct payload_t
  42. {
  43. float temp;
  44. float humid;
  45. };
  46.  
  47. void setup(void)
  48. {
  49. pinMode(2, OUTPUT); //Green LED
  50. pinMode(3, OUTPUT); //Red LED
  51. digitalWrite(2, HIGH); //Keeps the LEDs off
  52. digitalWrite(3, HIGH); //until needed in the loop
  53. sensors.begin();
  54. sensors.setResolution(outsideTemp, 10);
  55. SPI.begin();
  56. radio.begin();
  57. network.begin(/*channel*/ 90, /*node address*/ outside);
  58. }
  59.  
  60. void loop(void)
  61. {
  62. float tempC = sensors.getTempC(outsideTemp);
  63. float tempF = DallasTemperature::toFahrenheit(tempC);
  64. float humidity = sht1x.readHumidity();
  65. sensors.requestTemperatures();
  66. network.update();
  67. // If it's time to send a message, send it!
  68. unsigned long now = millis();
  69. if ( now - last_sent >= interval )
  70. {
  71. last_sent = now;
  72.  
  73. payload_t payload = { tempF, humidity };
  74. RF24NetworkHeader header(/*to node*/ base);
  75. bool ok = network.write(header,&payload,sizeof(payload));
  76. if (ok) {
  77. digitalWrite(3, HIGH);
  78. digitalWrite(2, LOW);
  79. }
  80. else {
  81. digitalWrite(2, HIGH);
  82. digitalWrite(3, LOW);
  83. }
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement