/* written/aggregated by: henry pai last edit: June 2016 ================================ what this code does right now: Overall- Logs sensor data (for now just weather station) at a certain minute interval with "push" model (node collects and then "pushes" data to home node) and turns off arduino board in between interval measurements. Detailed- - Sends composite measurement command (OC!) via SDI12 protocol at address 0 - Averages wind data and precip data over a minute; temp, P, and RH are instantaneous - Collects data (command 0D0!) - Pushes data to PC with XBee modules (tested with Series 1 radios) via transparent (AT) - Sleeps board every 8 seconds and checks minute timestamp for on the minute inteval measurements ================================================================================================= resources and some reused code from: Setting time: (separate code) https://github.com/SodaqMoja/Sodaq_DS3231/blob/master/examples/adjust/adjust.pde SD card = http://envirodiy.org/mayfly/software/simple-file/ SDI12 = https://github.com/EnviroDIY/Arduino-SDI-12/blob/master/examples/d_simple_logger/d_simple_logger.ino Sleep board = https://learn.adafruit.com/low-power-wifi-datalogging?view=all Time string formatting = from Dr. Diego Dierick XBee Pro 900hp physical setup & config = http://learn.parallax.com/tutorials/robot/elev-8/elev-8-v3-wireless-telemetry-xbee/configuring-xbee-900mhz-modules XBee API Arduino (same site has an RPI/python example as well) = http://www.desert-home.com/2013/10/floats-and-strings-over-serial-link.html XBee sleep configuration = https://www.guiduc.org/wp/2012/01/trouble-with-xbee-serie-2-sleep-mode/ Mayfly Board Schematic = http://363hx939kn9r1sp3hxo0om0z.wpengine.netdna-cdn.com/wp-content/uploads/2016/05/v0p3p_schematic2.jpg ================================================================================================================================ TODO: - Once antennas come in, test range of radios - Write test messaging in transparent (no weather station is in yet) - Go to Castle to test - Prep enclosure and antennas for test - Prep XBee boards for base station and install hyperterminal - Charge LiPo and bring LiPo charger - ASSUME range test is successful, complete XBee API transmission mode; OTHERWISE go to CR300 + cell modem + WRCC route - Write Arduino XBee API communication (checksum) - Write Python/RPi base station code (logs data to file) - What is the base station? Windows laptop? Mini-PC? How does this integrate with Axis P1214-e Camera? - How does XBee handle checksum? - "Push" data back to UNR - Test on rsync/ftp'ing to henry's CTEMPS repository - Also look to plot data real time to Plotly */ #include #include #include #include #include #include #include #include "Sodaq_DS3231.h" #define INTERVAL_MINUTE 2 // Likely will change this between tests and actual deployments #define MET_PIN 7 // Depends where we plug in #define SD_SS_PIN 12 #define FILE_NAME "Log3.txt" #define HEADER "DateTime,SampleNum,sdiAddr,dirAvg_deg,wSpeedMin_ms,wSpeedAvg_ms,wSpeedMax_ms,aTemp_C,RH_percent,absPress_hPa,rainAccum_hitscm2,rainIntensity_mhr,Vs" int samplenum = 1; volatile bool watchdogActivated = false; SDI12 metSDI0(MET_PIN); void setup() { Serial1.begin(9600); // Serial1 line is the xbee port, it is currently in transparent (AT) mode setupLogFile(); // 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< 5); delay(100); tempBuffer = getBuffer(metSDI0); //Serial.println(tempBuffer); delay(60100); // met station averages over 60 secs for wind & precip metSDI0.flush(); metCommand = "0D0!"; // requests data, should be 11 including SDI address metSDI0.sendCommand(metCommand); while(!metSDI0.available()>1); // wait for acknowlegement delay(300); // let the data transfer metBuffer = getBuffer(metSDI0); // replaces "+" with "," metSDI0.flush(); String dataRec = createDataRecord(timestamp, metBuffer); // creates single line for txt file logData(dataRec); //Save the data record to the log file Serial1.print(dataRec); //Echo the data to the serial connection; modified, THIS LINE WILL CHANGE IN API MODE delay(100); } } sleep(); } // 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); // Disable the ADC while asleep. power_adc_disable(); // Enable sleep. sleep_enable(); // Disable brown-out detection during sleep. This is timing critical and // must be done right before entering sleep mode. MCUCR |= (1<