/*------------------------------------------------------------------------------ * AUTO-GENERATED CODE FROM CTA-EMM-WEB * EDIT ONLY IF YOU KNOW WHAT YOU ARE DOING *----------------------------------------------------------------------------*/ #include "mysensors.h" #include "utils.h" // === LDR SETUP ======================================= #define LDR_PIN 1 // analog String read_LDR() { return FloatToString(100/1023.0 * analogRead(LDR_PIN)); } // === DHT22 SETUP ======================================= // https://github.com/adafruit/DHT-sensor-library #define DHT22_PIN 4 // digital #define DHTTYPE DHT22 DHT dht(DHT22_PIN, DHTTYPE); String read_DHT22_TEMP() { return FloatToString(dht.readTemperature()); } String read_DHT22_AH() { return FloatToString(dht.readHumidity()); } // === BMP085 SETUP =============================================== // https://github.com/adafruit/Adafruit-BMP085-Library Adafruit_BMP085 bmp; bool is_bmp085_connected=false; String read_BMP085_PRESSURE() { if (is_bmp085_connected) return String(bmp.readPressure()); else return String(""); } // ---------------------------------------------------------------- // === RTC_DS1307 SETUP =========================================== // https://github.com/adafruit/RTClib RTC_DS1307 rtc; String read_RTC_DS1307() { if (rtc.isrunning()) return get_datetime_str(rtc.now()); else return String(""); } String get_datetime_str(DateTime dt) { String result=""; result += String(dt.year(), DEC); result += String("-"); result += String(dt.month(), DEC); result += String("-"); result += String(dt.day(), DEC); result += String(" "); result += String(dt.hour(), DEC); result += String(":"); result += String(dt.minute(), DEC); result += String(":"); result += String(dt.second(), DEC); return result; } // Expects something like "2015,6,28,13,13,10" String set_time_from_csv(String s) { DateTime dt; int i_month = s.indexOf(CSV_SEP); int i_day = s.indexOf(CSV_SEP, i_month + 1); int i_hour = s.indexOf(CSV_SEP, i_day + 1); int i_minute = s.indexOf(CSV_SEP, i_hour + 1); int i_second = s.indexOf(CSV_SEP, i_minute + 1); String year = s.substring(0, i_month); String month = s.substring(i_month + 1, i_day); String day = s.substring(i_day + 1, i_hour); String hour = s.substring(i_hour + 1, i_minute); String minute = s.substring(i_minute + 1, i_second); String second = s.substring(i_second + 1); dt = DateTime(year.toInt(), month.toInt(), day.toInt(), \ hour.toInt(), minute.toInt(), second.toInt()); rtc.adjust(dt); return String("done: ") + get_datetime_str(dt); } // ---------------------------------------------------------------- void mysensors_setup() { dht.begin(); is_bmp085_connected = bmp.begin(); #ifdef AVR Wire.begin(); #else Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due #endif rtc.begin(); // adjust rtc from compile date time // rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); }