Hello
Current time of post at my location 21:31:xx
Im using the following function with the time library. Its reads out the time of the rtc and sets the arduino clock.
void setTimeFromRTC() {
//This function reads the current time in UTC saved in the RTC Module and sets the arduino time.
//collect data
Wire.beginTransmission(RTC_ADDRESS);
Wire.write(0x00);
Wire.endTransmission();
Wire.requestFrom(RTC_ADDRESS, 6);
byte rtcSeconds = BcdToDec(Wire.read());
byte rtcMinutes = BcdToDec(Wire.read());
byte rtcHours = BcdToDec(Wire.read());
int rtcYear = BcdToDec(Wire.read());
byte rtcDay = BcdToDec(Wire.read());
byte rtcMonth = BcdToDec(Wire.read());
//set arduino time
setTime(rtcHours, rtcMinutes, rtcSeconds, rtcDay, rtcMonth, rtcYear);
//calculate TIMEZONE and possible DST for selected values and a just time (in seconds)
int adjustValue = DST_calculation(rtcDay, rtcMonth) + TMZ_calculation();
adjustTime(adjustValue * SECS_PER_HOUR);
}
Time is saved in UTC, and i live in UTC+1, so rtcHours is 20 at the moment, and ajust time is 1*3600.
I have validated this, by adding a Serial print in the function, that will print out rtcHours and ajust. It was constantly 20 and 1, so no change in the rtc it self!
The second function is:
void timeService() {
bool updated = false;
bool needsCycle = false;
byte AMPM_value = 0;
if (oldTimeStamp != now()) {
oldTimeStamp = now();
updated = 1;
if (needsTS == true) {
DEBUG_PORT.print("need: ");
DEBUG_PORT.println(needsTS);
if (exTSvalid == true) {
exTimeSyncSet();
setTimeFromRTC();
}
else {
setTimeFromRTC();
}
needsTS = false;
}
if (oldMinute != minute()) {
needsTS = true;
byte oldMTT = oldMinute / 10;
byte currentMTT = minute() / 10;
if (cycletime == 1 && oldMTT != currentMTT) {
needsCycle = true;
}
if (cycletime == 2) {
needsCycle = true;
}
oldMinute = minute();
}
if( oldHour != hour()){
if (cycletime == 3 ) {
needsCycle = true;
}
oldHour = hour();
}
if (isAmPmMode == 2) {
AMPM_value = 12;
}
}
if (needsCycle == true && display_time_true == 1) {
cycleHandler();
}
if (updated == 1 && display_time_true == 1) {
bulbHandler();
DEBUG_PORT.print("ST: ");
DEBUG_PORT.print(now());
DEBUG_PORT.print(" H: ");
DEBUG_PORT.print(hour());
DEBUG_PORT.print(" M: ");
DEBUG_PORT.print(minute());
DEBUG_PORT.print(" S: ");
DEBUG_PORT.println(second());
formatOutput(hour() - AMPM_value, minute(), second(), bulbOne, bulbTwo);
setOutputs(register_output_1, register_output_2);
}
}
Every minute, the clock will snychronize to a GPS reciever. To validate whats happening, i added serial output.
The Problem i have can be seen in the Serial log:
Ignore the cordinates, they're fake.
ST: 948230999 H: 21 M: 29 S: 59
ST: 948231000 H: 21 M: 30 S: 0
need: 1
GPS-:
2017-01-18 20:30:022000-01-01 00:00:10
407411110
-739897220
GPS-END
ST: 948231001 H: 20 M: 30 S: 1
ST: 948231002 H: 21 M: 30 S: 2
at 21:29:59 the time is normal, then the gps kicks in, sending 20:30:02 (UTC)
after that, the hour() weirdly becomes 20 for one second!, as you can see, the timestamp is the same in the hours section, only the second changed.
Any ideas why this is happening?