示例#1
0
String RRTime::getStatus(){
  if(timeStatus() == timeNotSet){
    return F("Not set");
  }
  if(timeStatus() == timeNeedsSync){
    return F("Needs sync");
  }
  if(timeStatus() == timeNotSet){
    return F("Ok");
  }
  
}
示例#2
0
void SyncTime_setup() 
{
  Udp.begin(LOCALPORT);
  setSyncProvider(getNtpTime);
  while(timeStatus()== timeNotSet)   
     ; // wait until the time is set by the sync provider
}
示例#3
0
void Clock::init(){
  delay(1000); // Give RTC time to start up
  if(timeStatus()!= timeSet)
    Serial.println("Unable to sync with the RTC");
  else
    Serial.println("RTC has set the system time"); 
}
示例#4
0
文件: godob.cpp 项目: mmoller2k/godob
void godob::printdate(void)
{
  char ch;
  // Warning!
  if(timeStatus() != timeSet) {
    LCD->setCursor(0, 1);
    LCD->print(F("RTC ERROR: SYNC!"));
  }
  else{
    tmElements_t tm;
    breakTime(now(), tm);
    // Display abbreviated Day-of-Week in the lower left corner
    LCD->setCursor(0, 1);
    if(!Connected){
      ch = '_';
    }
    else if(reqPending){
      ch = '+';
    }
    else{
      ch = '*';
    }
    LCD->write(ch);
    LCD->write(' ');
    LCD->print(dayShortStr(tm.Wday));
    LCD->print(" ");
    print2digits(tm.Day);
    LCD->print("/");
    print2digits(tm.Month);
    LCD->print("/");
    LCD->print(tm.Year+1970);
  }  
}
示例#5
0
文件: godob.cpp 项目: mmoller2k/godob
void godob::begin(void)
{
  RTC = new DS1302RTC(pin_tCE, pin_tIO, pin_tCLK);
  LCD = new LiquidCrystal(pin_dRS,pin_dE,pin_d4,pin_d5,pin_d6,pin_d7);
  BTN = new Buttons(0);
  ENCAz = new Encoder(0x42);
  ENCAlt = new Encoder(0x40);
  AST = new Astro();
  
  Serial.print("00000000,00000000#"); /* let stellarium know we are here */

  Connected = false;
  stars = 0;
  reqPending=false;

  dstat = ds_time;
  // Setup LCD to 16x2 characters
  LCD->begin(16, 2);

  digitalWrite(pin_BL, HIGH);
  pinMode(pin_BL, OUTPUT);

  // Check clock oscillation  
  LCD->clear();
  if (RTC->haltRTC()){
    LCD->print("Clock stopped!");
    delay ( 1000 );
  }

#if 0  
  // Check write-protection
  LCD->setCursor(0,1);
  if (RTC->writeEN())
    LCD->print("Write allowed.");
  else
    LCD->print("Write protected.");

  delay ( 1000 );
#endif
  
  // Setup Time library  
  LCD->clear();
  setSyncProvider(RTC->get); // the function to get the time from the RTC
  //setSyncInterval(300);
  if(timeStatus() != timeSet){
    LCD->print("RTC Sync FAIL!");
    delay ( 1000 );
  }

  LCD->print("Godob 1.0");
  LCDBrightness(0);
  delay(1000);
  LCD->clear();
  ENCAlt->reverse(0);
  ENCAlt->reset();
  ENCAz->reverse(1);
  ENCAz->reset();
}
示例#6
0
void loop() {
  delay(250);
  if (now() != prevDisplay) { // update the display only if time has changed
    if (timeStatus() != timeNotSet) {
      DayWeekNumber(year(), month(), day(), weekday());
      digitalClockDisplayLCD();
      prevDisplay = now();
    }
  }
}
示例#7
0
void rtcStatus()
{
	timeStatus_t rtcSta = timeStatus();
  
	if(rtcSta == timeSet)
		Serial.println("Time's clock has been set.");
	else if (rtcSta == timeNotSet)
		Serial.println("Time's clock has not been set.");
	else if (rtcSta == timeNeedsSync)
		Serial.println("Time's clock is set, but the sync has failed.");
	else
		Serial.println("error");
}
示例#8
0
WatchCore::WatchCore() : display(cs, dc, rst), buttonTime(0), currentMenu(nullptr), currentMenuItem(0), currentMode(Time) {
    /* Tell the Time library to get time from Teensy's RTC. */
    setSyncProvider([]() { return time_t(Teensy3Clock.get()); });

    modes[Time]         = new ClockMode(*this);
    modes[Tempurature]  = new TempuratureMode(*this);
    modes[Timer]        = new TimerMode(*this);
    modes[Stopwatch]    = new StopwatchMode(*this);
    modes[Test]         = new TestMode(*this);

    Serial.begin(9600);

    Wire.begin();

    Serial.println("init");
    Serial.flush();

    display.begin();

    /* Set up the trackball inputs. */
    pinMode(TRACKBALL_BTN, INPUT);
    pinMode(TRACKBALL_LFT, INPUT);
    pinMode(TRACKBALL_RGT, INPUT);
    pinMode(TRACKBALL_UP,  INPUT);
    pinMode(TRACKBALL_DWN, INPUT);

    /* And the trackball LEDs. */
    pinMode(TRACKBALL_WHT, OUTPUT);
    pinMode(TRACKBALL_GRN, OUTPUT);
    pinMode(TRACKBALL_RED, OUTPUT);
    pinMode(TRACKBALL_BLU, OUTPUT);

    /* The buzzer needs to be set up too. */
    pinMode(BUZZER_PIN, OUTPUT);

    /* The flashlight LED needs to be set up too. */
    pinMode(LIGHT_PIN, OUTPUT);

    /* Debug info on whether or not the RTC works. */
    if (timeStatus() != timeSet)
        Serial.println("Unable to sync with the RTC");
    else
        Serial.println("RTC has set the system time");

    /* Get the initial values of the trackball hall effect sensors. */
    lftLast = digitalRead(TRACKBALL_LFT);
    rgtLast = digitalRead(TRACKBALL_RGT);
    upLast  = digitalRead(TRACKBALL_UP);
    dwnLast = digitalRead(TRACKBALL_DWN);
}
void Clock::update()
{
	if (timeStatus() == timeSet)
	{
		currentTime = now(); // store the current time in time variable t
	}
	else
	{
		// Saturday 1st January 2000 12:00:00 AM UTC
		currentTime = DEFAULT_TIME;
	}

	currentTime = getLocalTime(currentTime, settings.TZ, settings.IS_DST);
}
示例#10
0
void diagnosis() {
    Serial.println("Waiting for DCF77 time ... ");

    int rising_edge = 0;
    int falling_edge = 0;
    int previous_rising_edge;
    bool was_high = false;

    while (timeStatus() == timeNotSet) {
        const uint8_t sensor_value = digitalRead(filtered_dcf77_pin);
        if (sensor_value) {
             if (!was_high) {
                rising_edge = millis();
                was_high = true;
            }
        } else {
            if (was_high) {
                falling_edge = millis();
                Serial.print("Cycle, Pulse: ");

                const int cycle = rising_edge - previous_rising_edge;
                if (cycle < 1000) {
                    Serial.print(' ');
                }
                Serial.print(cycle);
                Serial.print(',');
                Serial.print(' ');

                const int pulse = falling_edge - rising_edge;
                if (pulse < 100) {
                    Serial.print(' ');
                }
                Serial.print(pulse);
                previous_rising_edge = rising_edge;
                was_high = false;

                Serial.print(' ');
                Serial.print(pulse < 180? '.': 'X');

                Serial.print(' ');
                Serial.print(cycle <1800? ' ': 'm');

                Serial.println();
             }
        }
    }

    Serial.println();
}
示例#11
0
void SetTime() 
{ 
  // set time with timestamp transmitted from local PC 
   
  while (Serial.available()){ Serial.read();} //clear read buffer 
   
  TimeisSet = false;     
 
  //send command to PowerShell requesting timestamp be echoed back 
  Serial.println(F("PSCmd:'T'+[math]::round((New-TimeSpan (get-date('1 Jan 1970')) (get-date)).TotalSeconds,0)")); 
         
  delay(250); 
       
  //read timestamp from serial port       
  if(Serial.available() >= 11 ) 
  {        
    do 
    {  
      c = Serial.read();  
      if( c == 'T' )  
      {        
        pctime = 0; 
        for(int i=0; i < 11 -1; i++) 
        {    
          c = Serial.read();         
          if( c >= '0' && c <= '9') 
          {    
            pctime = (10 * pctime) + (c - '0');     
          } 
        } 
      }   
    } while (Serial.available());        
  } 
 
  setTime(pctime);        
  if (timeStatus() == timeSet) 
  { 
    TimeisSet = true; 
  } 
 
  while (Serial.available()){ Serial.read();}   //clear read buffer 
   
  if(TimeisSet) 
  {        
    Serial.print(hour()); Serial.print(":"); 
    if(minute() < 10){Serial.print('0');}Serial.print(minute()); Serial.print(":"); 
    if(second() < 10){Serial.print('0');}Serial.println(second()); 
  } 
} 
void setup() {

	Serial.begin(9600); 
	setupEthernet(); 

	setSyncInterval(NTP_TIME_SYNC_INTERVAL);
	setSyncProvider(getNtpTime);

	if(timeStatus()== timeNotSet)
	{
		Serial.println("Sync failed during start");
	}
	else
	{
		Serial.println("Sync successfully during start");
	}
}
示例#13
0
void setAquariaTime() {

    // first check to see if the RTC is already set
    if (RTC.get == 0) {
        // it's not so initialize the RTC with info
        // from the compiler 
        getDate(__DATE__) && getTime(__TIME__);
        RTC.write(tm);
    }
    // it is so lets...
    setSyncProvider(RTC.get); // ...set the system time
    // and check to see if it worked
    if (timeStatus() != timeSet)
        Serial.println("Unable to sync with the RTC");
    else
        Serial.println("RTC has set the system time");
    setSyncInterval(60000); // sync system time with RTC every hour
}
示例#14
0
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
  switch(type) {
      case WStype_DISCONNECTED:
          //USE_SERIAL.printf("[%u] Disconnected!\n", num);
          wsConcount--;
          sprintf(str,"ws disconnect count=%d",wsConcount);
          if (useMQTT) mqtt.publish(mqttpub,str);
          break;
      case WStype_CONNECTED:
          {
              IPAddress ip = webSocket.remoteIP(num);
              sprintf(str,"[%u] connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload);
              //USE_SERIAL.println();
              // send message to client
              sprintf(str,"Connection #%d.", num);
              webSocket.sendTXT(num, str);
              sprintf(str, "name=%s", nodename);
              webSocket.sendTXT(num, str);
              //webSocket.sendTXT(num, mqttpub);
              //webSocket.sendTXT(num, mqttsub);
              if (timeStatus() == timeSet) webSocket.sendTXT(num, "Time is set.");
              else webSocket.sendTXT(num, "Time not set.");
              //mqtt.publish(mqttpub, str);
              //wsSendlabels();
              newWScon = num + 1;
              wsConcount++;
              sprintf(str,"ws connect count=%u new=%u",wsConcount,newWScon);
              if (useMQTT) mqtt.publish(mqttpub,str);
          }
          break;
      case WStype_TEXT:
          payload[length] = '\0'; // null terminate
          handleMsg((char *)payload);

          break;
      case WStype_BIN:
         // USE_SERIAL.printf("[%u] get binary lenght: %u\n", num, length);
          hexdump(payload, length);

          // send message to client
          // webSocket.sendBIN(num, payload, lenght);
          break;
  }
}
示例#15
0
void setup()
{
	fsmState = EDIT_TIME_MODE;

	// initialize thermometer
	sensor.begin();
	sensor.setWaitForConversion(true);
	sensor.getAddress(devAddr, 0);
	sensor.requestTemperatures();
	tempInCelsius = (int) (sensor.getTempC(devAddr)*10);

	// initialize buttons
	buttonA.setClickTicks(250);
	buttonA.setPressTicks(600);
	buttonA.attachLongPressStart(longPressA);
	buttonA.attachClick(singleClickA);
	buttonA.attachDoubleClick(doubleClickA);

	buttonB.setClickTicks(250);
	buttonB.setPressTicks(600);
	buttonB.attachClick(singleClickB);
	buttonB.attachDoubleClick(doubleClickB);
	buttonB.attachLongPressStart(longPressB);

	// initialize serial
	Serial.begin(115200);

	// initialize rtc
	
	setSyncProvider(RTC.get);
	setSyncInterval(1);
	if(timeStatus()!= timeSet) 
	{
		Serial.println("Unable to sync with the RTC");
		fsmState = ERROR_MODE;
	} else
	{
		Serial.println("RTC has set the system time"); 
	}
	
	// default alarm settings, 08:30, disabled
	pinMode(ALARM_PIN, INPUT_PULLUP);
}
示例#16
0
void mqttData() { // send mqtt messages as required
  if (!mqtt.connected()) return; // bail out if there's no mqtt connection

  if (timeStatus() == timeSet) mqttSendTime(now());

  if (hasRGB) return; // feature disabled if we're an rgb controller

  if (hasTout) mqtt.publish(mqttpub, tmpChr);


  if (hasVout) {
    mqtt.publish(mqttpub, voltsChr);
    if (rawadc) mqtt.publish(mqttpub, adcChr);
  }

  if (hasRSSI) mqtt.publish(mqttpub, rssiChr);

  if (hasIout) {
    mqtt.publish(mqttpub, amps0Chr);
    sprintf(str,"raw0=%d", raw0);
    if (rawadc) mqtt.publish(mqttpub, str);

    mqtt.publish(mqttpub, amps1Chr);
    sprintf(str,"raw1=%d", raw1);
    if (rawadc) mqtt.publish(mqttpub, str);

    mqtt.publish(mqttpub, voltsChr);
    sprintf(str,"raw2=%d", raw2);
    if (rawadc) mqtt.publish(mqttpub, str);
  }

  if (hasVout) {
    mqtt.publish(mqttpub, voltsChr);
    if (rawadc) mqtt.publish(mqttpub, adcChr);
  }

  if (hasRSSI) mqtt.publish(mqttpub, rssiChr);
  if (hasSpeed) doSpeedout();
}
示例#17
0
void wsData() { // send some websockets data if client is connected
  if (wsConcount<=0) return;

  // if (newWScon>0 && hasRGB) wsSwitchstatus(); // update switch status once for rgb controllers
  //else if (!hasRGB) wsSwitchstatus(); // regular updates for other node types
  wsSwitchstatus();

  if (timeStatus() == timeSet) wsSendTime("time=%d",now()); // send time to ws client

  if (hasRGB) return; // stop here if we're an rgb controller

  if (hasVout) { // send bat/vcc string
    wsSend(voltsChr);
    if (rawadc) wsSend(adcChr);
  }

  if (hasRSSI) wsSend(rssiChr); // send rssi info
  if (hasSpeed) doSpeedout();

  if (hasTout) wsSend(tmpChr); // send temperature

  if (hasIout) { // send readings from ADC
    sprintf(str,"raw0=%d", raw0);
    wsSend(amps0Chr);
    if (rawadc) wsSend(str);
    memset(str,0,sizeof(str));
    sprintf(str,"raw1=%d", raw1);
    wsSend(amps1Chr);
    if (rawadc) wsSend(str);
    memset(str,0,sizeof(str));
    sprintf(str,"raw2=%d", raw2);
    wsSend(voltsChr);
    if (rawadc) wsSend(str);
    memset(str,0,sizeof(str));
  }
}
示例#18
0
void setup()
{

    tmElements_t currentTime;

    currentTime.Second = 0;
    currentTime.Minute = 35;
    currentTime.Hour =18;
    currentTime.Wday = 5;
    currentTime.Day = 17;
    currentTime.Month = 4;
    currentTime.Year = 44;

    // RTC.set(makeTime(currentTime));

    Serial.begin(9600);
    Serial.println("TerraMonitor starting ...");
    Wire.begin(); 

    // analogReference(INTERNAL);

    Serial.print("EEPROM HumidityController size occupied (in bytes) : ");
    Serial.println(EEPROM_HUMIDITY_CONTROLLER_SIZE);

    setSyncProvider(RTC.get);   // the function to get the time from the RTC    
    if(timeStatus()!= timeSet) 
        Serial.println("Unable to sync with the RTC");
    else
        Serial.println("RTC has set the system time");

    /* Controller Alarm init */
    humidityController.initAlarms();
    lightController.initAlarms();

    /* read the sensor every s */
    lowSensor.setInterval(5000);
    highSensor.setInterval(5000);
    /* read the sensor every 10s */
    humidTempSensor.setInterval(10000); 
    /* run temp controller every s */
    tempController.setInterval(1000);

    /* add the thread to the controller */
    controller.add(&lowSensor);
    controller.add(&highSensor);
    controller.add(&humidTempSensor);
    controller.add(&tempController);
    
    Timer1.initialize(100000);
    Timer1.attachInterrupt(timerCallback);

    // Alarms
    //Alarm.alarmRepeat(12,00,0, MorningAlarm);  // 8:30am every day
    // Alarm.alarmRepeat(14,48,0, MorningAlarm);  // 8:30am every day
    //Alarm.alarmRepeat(17,30,0, MorningAlarm);  // 8:30am every day
    //Alarm.alarmRepeat(22,15,0, MorningAlarm);  // 8:30am every day

    humidityController.disableAllAlarms();
    humidityController.setAlarm(0, 12, 0, 0, 30);
    humidityController.setAlarm(1, 14, 0, 0, 15);
    humidityController.setAlarm(2, 16, 0, 0, 15);
    humidityController.setAlarm(3, 20, 0, 0, 15);
    humidityController.setAlarm(4, 22, 15, 0, 20);

    // humidityController.setAlarm(4, 16, 10, 0, 10);

    lightController.setStartTime(11,30,0);
    lightController.setStopTime(23,30,0);

    tempController.setMaxUpperTemp(29);
    tempController.setMinDayLowerTemp(21);
    tempController.setMinNightLowerTemp(20);
    tempController.setMinNightUpperTemp(21);

    // extractFan.startFan();
    // sideFan.startFan();
    // frontFan.startFan();

    lcd.init();                      // initialize the lcd 
 
    // Print a message to the LCD.
    lcd.backlight();

}