Example #1
0
DateTime Cron::getTime(){
	  DateTime now = RTC.now();
	  return now;
}
Example #2
0
void Cron::setTime(DateTime time){
	RTC.adjust(time);
}
Example #3
0
void setup(void)
{
	status.reset();

	/// Discrete & Analog IO
	pinMode(13, OUTPUT);	// Arduino on-board LED
	pinMode(A0, OUTPUT);	// Buzzer

	/// Comm. Channels
	// UART
	Serial.begin(115200); 	Serial.flush();
	Serial.println("Starting up greenOmatic Duemilanove Testbed...");
	Serial.print("Program compiled on ");
	Serial.print(__DATE__);
	Serial.print(" at ");
	Serial.println(__TIME__);
	Serial.println();

	// RF
#ifdef INTERFACE_ASK_RX
	pinMode(RF_RX_PIN, INPUT);
	vw_set_rx_pin(RF_RX_PIN);
    vw_setup(RF_BAUD);
    vw_rx_start  ();
	Serial.print  ("ASK RF Receiver configured on PIN ");
	Serial.print  (RF_RX_PIN);
	Serial.print  (" @ ");
	Serial.print  (RF_BAUD, DEC);
	Serial.println(" baud.");
#endif //INTERFACE_ASK_RX

	// Ethernet
#ifdef INTERFACE_ETHERNET
	Serial.print("Starting Ethernet... ");

#ifdef ETHERNET_DYNAMIC_IP
	int eth_stat = Ethernet.begin(mac);
	if (0 == eth_stat)
	{
		Serial.println(" Problem starting ethernet !");
		status.ethernet_valid = status.ERROR;
	}
	else
	{
		Serial.print("Ethernet started, IP = ");
		Serial.println( Ethernet.localIP() );
		status.ethernet_valid = status.VALID;
	}
#else
	Ethernet.begin(mac, IPaddr);
	Serial.print("Ethernet started, IP = ");
	Serial.println( Ethernet.localIP() );
	status.ethernet_valid = status.VALID;
#endif //ETHERNET_DYNAMIC_IP

#ifdef ETHERNET_WEBSERVER
		server.begin();
#endif //ETHERNET_WEBSERVER

#ifdef ETHERNET_UDPCLIENT
		Udp.begin(localPort);
#endif //ETHERNET_UDPCLIENT

#endif

	/// Peripherals
	// I2C RTC
#ifdef PERIPHERAL_RTCC
	Wire.begin();
	rtc.begin();
	if (rtc.isrunning())
	{
		status.time_valid = status.VALID;
		GetDatetimeString(rtc.now());
	    Serial.print("RTCC configured on I2C.  Time is currently ");
	    Serial.println(currentTime);

#ifdef ETHERNET_UDPCLIENT
		//TODO: Get NTP Time
#else
	    // Compare RTC time to this programs compile time
	    DateTime rtcTime = rtc.now();
	    DateTime compileTime(F(__DATE__), F(__TIME__));

	    // If the compile-time is later (more recent) than the current RTC time, update the RTC
	    if (compileTime.secondstime() > rtcTime.secondstime())
	    {
	    	Serial.println("Program compile-time is later than RTC time; updating RTC.");
	    	rtc.adjust( DateTime(F(__DATE__), F(__TIME__)) );
	    }
#endif //ETHERNET_UDPCLIENT
	}
	else
	{
		status.time_valid = status.ERROR;
		// TODO, can we narrow this down further like with the DS1307RTC library?
	}
#endif

	Serial.println("\nInitialization complete!\n\n");
}
Example #4
0
int main(void)
{
	/// setup
	init();
	setup();

	/// loop control
	for(frame=0; ; ++frame)
	{
		digitalWrite(13, HIGH);

		status.reset();

	    String new_msg = "Loop #";
	    new_msg.concat(frame);

#ifdef PERIPHERAL_RTCC
	    /// check time
		if (status.VALID == status.time_valid)
		{
			GetDatetimeString(rtc.now());
		}

/* 		TODO: port RTC.chipPresent() functionality over to RTClib
	    if ( RTC.read(tm) )
	    {
	    	status.time_valid = status.VALID;
	    }
	    else
	    {
	       if ( RTC.chipPresent() )
	       {
	    	  status.time_valid = status.INVALID;
	 	      Serial.println("The DS1307 is stopped.  Please set the RTC time.");
	 	      Serial.println();
	       }
	       else
	       {
	    	 status.time_valid = status.UNINSTALLED;
	         Serial.println("DS1307 read error!  Please check the circuitry.");
	         Serial.println();
	       }
	     }
*/
#endif

	    /// Check interfaces for received messages
	    // Serial, direct to the Command Line Interface (CLI)
		if(Serial.available() > 0)
		{
			char 	buff_console [8];
			for(uint8_t len_console = 0x00; Serial.available() > 0; len_console++)
			{
				buff_console[len_console] = Serial.read();
				CLI(buff_console, len_console);
			}
		}

#ifdef INTERFACE_ASK_RX
	    // RF (1-wire ASK, aka VirtualWire), print to console
		uint8_t  buff_rf   [VW_MAX_MESSAGE_LEN];
		uint8_t  len_rf  =  VW_MAX_MESSAGE_LEN;
		if(vw_get_message(buff_rf, &len_rf))
		{
#ifdef PERIPHERAL_RTCC
			// Prefix received messages with current date-time on console
			if (status.VALID == status.time_valid)
			{
				Serial.print(currentTime);
			    Serial.write(" | ");
			}
#endif //PERIPHERAL_RTCC
			Serial.print("RF Received :  ");
			for(uint8_t i = 0; i < len_rf; i++)
			{
				Serial.print((char)buff_rf[i]);
			}
			Serial.println();
		}
#endif //INTERFACE_ASK_RX

#ifdef ETHERNET_WEBSERVER
		  EthernetClient client = server.available();
		  if (client) {
		    Serial.println("new http client");
		    // an http request ends with a blank line
		    boolean currentLineIsBlank = true;
		    while (client.connected())
		    {
		      if (client.available())
		      {
		        char c = client.read();
		        Serial.write(c);
		        // if you've gotten to the end of the line (received a newline
		        // character) and the line is blank, the http request has ended,
		        // so you can send a reply
		        if (c == '\n' && currentLineIsBlank)
		        {
		          // send a standard http response header
		          client.println("HTTP/1.1 200 OK");
		          client.println("Content-Type: text/html");
		          client.println("Connection: close");  // the connection will be closed after completion of the response
		          client.println("Refresh: 60");  // refresh the page automatically every 60 sec
		          client.println();
		          client.println("<!DOCTYPE HTML>");
		          client.println("<html>");

#ifdef PERIPHERAL_RTCC
		          client.print("green-O-matic RTC Time : ");
		          client.println(currentTime);
#endif //PERIPHERAL_RTCC

#ifdef INTERFACE_ASK_RX
		          client.println("Most recently received 433MHz ASK Transmission : ");
#endif //INTERFACE_ASK_RX

		          client.println("</html>");
		          break;
		        }
		        if (c == '\n')
		        {
		          // you're starting a new line
		          currentLineIsBlank = true;
		        }
		        else if (c != '\r')
		        {
		          // you've gotten a character on the current line
		          currentLineIsBlank = false;
		        }
		      }
		    }
		    // give the web browser time to receive the data
		    delay(5);
		    // close the connection
		    client.stop();
		    Serial.println("client disconnected");
		  }
#endif //ETHERNET_WEBSERVER

		digitalWrite(13, LOW);

		delay (LOOP_DELAY);
	};
	return 0;
}
Example #5
0
uint8_t ScheduleEntry::ActivateEntry(RTC_DS1307 RTC) {
	// only work with enabled schedules
	static int devices[7] = {1, 0, 13, 12, 11, 10, 9};
	static uint8_t pins = 7;

	time = RTC.now();
	// Serial.println("Contents of entry:");
	// for (int i = 0 ; i < 24; i++) {
	// 	Serial.println(analogValue, DEC);
	// }

	// sprintf(serial_buffer, "ssl: %d timesecond: %d", ssl, time.second());
	// Serial.println(serial_buffer);

	if (en == 1) {
		if (ssc == DASH) {
			if (time.second() > ssu && time.second() < ssl) {
				// sprintf(serial_buffer, "time.second()<%d> > ssu<%d> && time.second()<%d> < ssl<%d>", time.second(), ssu, time.second(), ssl);
				// Serial.println(serial_buffer);
				return 0;
			}
		}
		if (ssl != time.second() && ssl != ASTERISK) {
			// sprintf(serial_buffer, "(ssl<%d> != time.second()<%d> && ssl<%d> != ASTERISK)", ssl, time.second(), ssl);
			// Serial.println(serial_buffer);
			return 0;
		}

		if (mnc == DASH) {
			if (time.minute() > mnu && time.minute() < mnl) {
				// Serial.println("minute1");
				return 0;
			}
		}
		if (mnl != time.minute() && mnl != ASTERISK) {
			// Serial.println("minute2");
			return 0;
		}


		if (hhc == DASH) {
			if (time.hour() > hhu && time.hour() < hhl) {
				// Serial.println("hour");
				return 0;
			}
		}
		if (hhl != time.hour() && hhl != ASTERISK) {
			// Serial.println("hour2");
			return 0;
		}


		if (mdc == DASH) {
			if (time.day() > mdu && time.day() < mdl) {
				// Serial.println("mdu");
				return 0;
			}
		}
		if (mdl != time.day() && mdl != ASTERISK) {
				// Serial.println("mdu2");
			return 0;
		}


		if (wdc == DASH) {
			if (time.dayOfWeek() > wdu && time.dayOfWeek() < wdl) {
				// Serial.println("dayOfWeek");
				return 0;
			}
		}
		if (wdl != time.dayOfWeek() && wdl != ASTERISK) {
				// Serial.println("dayOfWeek2");
			return 0;
		}


		if (moc == DASH) {
			if (time.month() > mou && time.month() < mol) {
				// Serial.println("month");
				return 0;
			}
		}
		if (mol != time.month() && mol != ASTERISK) {
				// Serial.println("month2");
			return 0;
		}


		if (yyc == DASH) {
			if (time.year()-2000 > yyu && time.year()-2000 < yyl) {
				// Serial.println("year");
				return 0;
			}
		}
		if (yyl != time.year()-2000 && yyl != ASTERISK) {
			// Serial.println("year2");
			return 0;
		}

		switch (id) {
			case ASTERISK:
				if (ScheduleEntry::GetDeviseFinalState(ds)) {
					for (uint8_t i = 0; i<pins; i++ ) {
						digitalWrite(devices[i], 1);
					}
				} else {
					for (uint8_t i = 0; i<pins; i++ ) {
						digitalWrite(devices[i], 0);
					}
				}
				break;
			default:
				if (ScheduleEntry::GetDeviseFinalState(ds)) {
					digitalWrite(devices[id], 1);
				} else {
					digitalWrite(devices[id], 0);
				}
				
				break;
		}

		return 1;
	} else {
		return 0;
	}
};