#include #include #include #include #include #include #include // Seconds to wait before a new sensor reading is logged. #define LOGGING_FREQ_SECONDS 60 // Number of times to sleep (for 8 seconds) before // a sensor reading is taken and sent to the server. // Don't change this unless you also change the // watchdog timer configuration. #define MAX_SLEEP_ITERATIONS LOGGING_FREQ_SECONDS / 8 #define DHTPIN 2 #define DHTTYPE DHT22 const int chipSelect = 4; //real time clock ds3231 DS3231 rtc(SDA, SCL); DHT dht(DHTPIN, DHTTYPE); int sleepIterations = 0; volatile bool watchdogActivated = false; // Define watchdog timer interrupt. ISR(WDT_vect) { // Set the watchdog activated flag. // Note that you shouldn't do much work inside an interrupt handler. watchdogActivated = true; } // Put the Arduino to sleep. void sleep() { // Set sleep to full power down. Only external interrupts or // the watchdog timer can wake the CPU! set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Turn off the ADC while asleep. power_adc_disable(); // Enable sleep and enter sleep mode. sleep_mode(); // CPU is now asleep and program execution completely halts! // Once awake, execution will resume at this point. // When awake, disable sleep mode and turn on all devices. sleep_disable(); power_all_enable(); } // Take a sensor reading and send it to the server. void logSensorReading() { // Take a sensor reading int reading = 99999; // Connect to the server and send the reading. Serial.print(F("Sending measurement: ")); Serial.println(reading, DEC); } void setup_interrupts(void) { // Setup the watchdog timer to run an interrupt which // wakes the Arduino from sleep every 8 seconds. // Note that the default behavior of resetting the Arduino // with the watchdog will be disabled. // This next section of code is timing critical, so interrupts are disabled. // See more details of how to change the watchdog in the ATmega328P datasheet // around page 50, Watchdog Timer. noInterrupts(); // Set the watchdog reset bit in the MCU status register to 0. MCUSR &= ~(1<= MAX_SLEEP_ITERATIONS) { // Reset the number of sleep iterations. sleepIterations = 0; // Log the sensor data (waking the CC3000, etc. as needed) /*logSensorReading();*/ getAndWrite(); delay(1000); } } // Go to sleep! sleep(); }