Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Copyright (C) 2012 James Coliz, Jr. <maniacbug@ymail.com>
- RF24 libraries and code
- Copyright 2009 Jonathan Oxer <jon@oxer.com.au>
- SHT1x library and code
- Copyright ???? ???? ???? ???????
- DallasTemperature library and code
- Copyright 2012 C. LeBlanc <ominously.chaotic@gmail.com>
- Mashing it all together
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- version 2 as published by the Free Software Foundation.
- */
- #include <RF24Network.h>
- #include <RF24.h>
- #include <SPI.h>
- #include <SHT1x.h>
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #define dataPin 8
- #define clockPin 7
- #define ONE_WIRE_BUS 6
- RF24 radio(9,10);
- RF24Network network(radio);
- SHT1x sht1x(dataPin, clockPin);
- OneWire oneWire(ONE_WIRE_BUS);
- DallasTemperature sensors(&oneWire);
- DeviceAddress outsideTemp = {0x28, 0x9B, 0xFB, 0xDE, 0x03, 0x00, 0x00, 0x71};
- const uint16_t outside = 1;
- const uint16_t base = 0;
- const unsigned long interval = 2000; //ms
- unsigned long last_sent;
- struct payload_t
- {
- float temp;
- float humid;
- };
- void setup(void)
- {
- pinMode(2, OUTPUT); //Green LED
- pinMode(3, OUTPUT); //Red LED
- digitalWrite(2, HIGH); //Keeps the LEDs off
- digitalWrite(3, HIGH); //until needed in the loop
- sensors.begin();
- sensors.setResolution(outsideTemp, 10);
- SPI.begin();
- radio.begin();
- network.begin(/*channel*/ 90, /*node address*/ outside);
- }
- void loop(void)
- {
- float tempC = sensors.getTempC(outsideTemp);
- float tempF = DallasTemperature::toFahrenheit(tempC);
- float humidity = sht1x.readHumidity();
- sensors.requestTemperatures();
- network.update();
- // If it's time to send a message, send it!
- unsigned long now = millis();
- if ( now - last_sent >= interval )
- {
- last_sent = now;
- payload_t payload = { tempF, humidity };
- RF24NetworkHeader header(/*to node*/ base);
- bool ok = network.write(header,&payload,sizeof(payload));
- if (ok) {
- digitalWrite(3, HIGH);
- digitalWrite(2, LOW);
- }
- else {
- digitalWrite(2, HIGH);
- digitalWrite(3, LOW);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement