// https://thebrickinthesky.wordpress.com/2015/09/13/arduino-rf-link-transmitterreceiver-434mhz-zumo-shield/ // Modified version of ask_receiver.pde by RadioHead // RX Data Pin = 11 #include #include //http://www.airspayce.com/mikem/arduino/RadioHead/ #include // Not actualy used but needed to compile #include //http://github.com/JChristensen/DS3232RTC #include //http://www.arduino.cc/playground/Code/Time #include //http://arduino.cc/en/Reference/Wire (included with Arduino IDE) #include //http://arduiniana.org/libraries/streaming/ #include //RH_ASK driver; // Default Speed = 2000, RX = 11, TX = 12, PTT = 10, PTTinverted = false RH_ASK driver(2000, 11, 9, 5); // RX 11, TX 9, PTT 5 float Sensor1Data; char Sensor1CharMsg[4]; int check_Sensor1Data; LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //Central European Time (Frankfurt, Paris) TimeChangeRule CEST = {"CEST", Last, Sun, Mar, 2, 120}; //Central European Summer Time TimeChangeRule CET = {"CET ", Last, Sun, Oct, 3, 60}; //Central European Standard Time Timezone CE(CEST, CET); void setup() { // set up the LCD's number of columns and rows: lcd.begin(20, 4); //LED pinMode(13, OUTPUT); Serial.begin(9600); // Debugging only. //For some reason, this is needed to initialize the driver. if (!driver.init()) { Serial.println("init failed"); } //setSyncProvider() causes the Time library to synchronize with the //external RTC by calling RTC.get() every five minutes by default. setSyncProvider(RTC.get); Serial << F("RTC Sync"); if (timeStatus() != timeSet) Serial << F(" FAIL!"); Serial << endl; } void loop() { static time_t tLast; time_t t; tmElements_t tm; // Set Time in UTC 16,5,23,10,15,0 yy,m,d,h,m,s //check for input to set the RTC, minimum length is 12, i.e. yy,m,d,h,m,s if (Serial.available() >= 12) { //note that the tmElements_t Year member is an offset from 1970, //but the RTC wants the last two digits of the calendar year. //use the convenience macros from Time.h to do the conversions. int y = Serial.parseInt(); if (y >= 100 && y < 1000) Serial << F("Error: Year must be two digits or four digits!") << endl; else { if (y >= 1000) tm.Year = CalendarYrToTm(y); else //(y < 100) tm.Year = y2kYearToTm(y); tm.Month = Serial.parseInt(); tm.Day = Serial.parseInt(); tm.Hour = Serial.parseInt(); tm.Minute = Serial.parseInt(); tm.Second = Serial.parseInt(); t = makeTime(tm); RTC.set(t); //use the time_t value to ensure correct weekday is set setTime(t); Serial << F("RTC set to: "); printDateTime(t); Serial << endl; //dump any extraneous input while (Serial.available() > 0) Serial.read(); } } t = now(); if (t != tLast) { tLast = t; printDateTime(t); if (second(t) == 0) { float c = RTC.temperature() / 4.; float f = c * 9. / 5. + 32.; Serial << F(" ") << c << F(" C ") << f << F(" F"); } Serial << endl; } uint8_t buf[RH_ASK_MAX_MESSAGE_LEN]; uint8_t buflen = sizeof(buf); if (driver.recv(buf, &buflen)) // Non-blocking { int i; // Message with a good checksum received, dump it. for (i = 0; i < buflen; i++) { // Fill Sensor1CharMsg Char array with corresponding chars from buffer. Sensor1CharMsg[i] = char(buf[i]); } // Null terminate the char array // This needs to be done otherwise problems will occur // when the incoming messages has less digits than the one before. Sensor1CharMsg[buflen] = '\0'; // Convert Sensor1CharMsg Char array to integer Sensor1Data = atof(Sensor1CharMsg); Serial.println(Sensor1Data); //Flash to indicate message received. digitalWrite(13, 1); delay(200); digitalWrite(13, 0); delay(200); //Reset counter for success check_Sensor1Data = 0; } else { // Timeout for Sensor1Data check_Sensor1Data = check_Sensor1Data + 1; if (check_Sensor1Data > 100) Sensor1Data = 0; } TimeChangeRule *tcr; time_t localTime = CE.toLocal(t, &tcr); lcd.setCursor(0, 0); if (hour(localTime) < 10) lcd.print("0"); lcd.print(hour(localTime)); lcd.print(":"); if (minute(localTime) < 10) lcd.print("0"); lcd.print(minute(localTime)); lcd.print(":"); if (second(localTime) < 10) lcd.print("0"); lcd.print(second(localTime)); lcd.setCursor(8, 0); lcd.print(" "); lcd.setCursor(10, 0); if (day(t) < 10) lcd.print("0"); lcd.print(day(t)); lcd.print("."); if (month(t) < 10) lcd.print("0"); lcd.print(month(t)); lcd.print("."); lcd.print(year(t)); lcd.setCursor(0, 1); if (hour(t) < 10) lcd.print("0"); lcd.print(hour(t)); lcd.print(":"); if (minute(t) < 10) lcd.print("0"); lcd.print(minute(t)); lcd.print(":"); if (second(t) < 10) lcd.print("0"); lcd.print(second(t)); lcd.print(" (UTC)"); lcd.setCursor(0, 2); lcd.print("Innen "); float c = RTC.temperature() / 4.; c = c - 3; lcd.print(c); lcd.setCursor(13, 2); lcd.print("\337C"); lcd.setCursor(0, 3); lcd.print("Aussen "); lcd.print(Sensor1Data); lcd.setCursor(13, 3); lcd.print("\337C"); } //print date and time to Serial void printDateTime(time_t t) { printDate(t); Serial << ' '; printTime(t); } //print time to Serial void printTime(time_t t) { printI00(hour(t), ':'); printI00(minute(t), ':'); printI00(second(t), ' '); } //print date to Serial void printDate(time_t t) { printI00(day(t), 0); Serial << monthShortStr(month(t)) << _DEC(year(t)); } //Print an integer in "00" format (with leading zero), //followed by a delimiter character to Serial. //Input value assumed to be between 0 and 99. void printI00(int val, char delim) { if (val < 10) Serial << '0'; Serial << _DEC(val); if (delim > 0) Serial << delim; return; }