Problem with timekeeping when Pi doesn't have internet access

I’m having a weird problem with time I wil explain the best i can. I have mycodo installed on a Pi 4 2gb. It was set up to monitor humidity and temperature with a waveshare bme280 and occasionally it would turn on a fan to vent humidity if needed via PID. I have installed just the regular bosch bme 280 dependency’s. At the time it was connected to the internet and has always performed nicely timestamps were proper. Now i have moved it to my shop to perform the same thing but this time its only connected to a router that is just a plain network no internet for monitoring purposes. With mycodo updated I was reading forums on how to set time and date. So i would set the time, and in turn mycodo would mirror the time and date. I have set up a synchronous graph to show history of what its like in the shop when i’m not in there. When i come back the next day however, it seemed to have lagged behind. For example would say 10:00 April 15 2021 when i set the time, then in the morning say around the same time, the graph shows a time stamp of 22:00 for the last measurement taken . I originally thought that it was crashing in the middle of the night and not recording but today i monitored the live and it is updating just under the wrong timestamp. it is 11:44 here right now and the daemon on the front page is saying its 2:08, i made sure the pi is showing the correct time. If i delete the inputs for the bme280 delete the graphs and do it again, by restarting it will be ok. What am I doing wrong???

1 Like

Hope this answers questions

Hey Chris. So the Pi doesn’t have a real time clock (RTC), but that’s fine when it’s connected to the internet and can query an NTP server. However, when not connected to the internet, you should have an RTC connected to it. When the Pi reboots for whatever reason, it may come back up with a wildly different time from what it actually is. More so if there’s been a power outage and it was completely without power for an extended period. I’ve used a few RTCs and for precise timekeeping, the DS3231 is great. Here are a few product links: Amazon, Adafruit.

Thank you I will buy and let you know.

1 Like

Hi again!

So I have installed a ds3231 rtc. Very interesting for sure and fun learning. But I’m having the same problem. When I take the internet out, it seems to lag behind still. The pic is very fresh install of the ds3231 so I haven’t seen it lag much but you can see from the pic the hwclock is installed but mycodo is running just a little behind, the chart and indicators are doing the same. What am I doing wrong?

Can you explain what you mean by this? The time at the top-left of the UI is the same as your RTC. Is your Pi time the same as the RTC (command date)?

Ok. I solved it. Let me explain in detail. If you notice the timestamps of the measurement indicators they were stuck at timestamp13:29:49 and were not updating/refreshing. The daemon time was showing a time of 13:44. The chart wasn’t updating and was also stuck at 13:29:40 so I knew that mycodo wasn’t recognizing that I had installed the RTC. So like I said the install was fresh, so I couldn’t really prove that it was lagging behind. So in this picture20210502_165857|666x500 you can see the live timestamp stuck at the time 13:29:49, and the daemon time is now 16:57. This was mirroring the PI’s RTC time so I knew the daemon was obviously getting time from the pi RTC. I Un installed the input for the bme280 and the cpu/gpu. Then re installed them and boom, now they are updating correctly and at the intervals I have set them too. Does this make sense now?

Not quite. The only thing that references the RTC is linux, and this is to set the system time. All other processes reference the system time. Also, there’s nothing about Mycodo that would change the measurement storage time by deleting and adding an Input. So, you’re just making me more confused about what the issue is.

Why was the timestamps in the 2 pictures that should be updating with the system stuck at 13:29:49 when mycodo/systems time is 16:57?

Could be a high Input Period or a high Widget refresh Period.

I was having this same problem when I didnt have the RTC installed. Default values for refresh times. What I was doing was just deleting the inputs for the bme280 then re install and it would “catch up” for a bit, then stall and the time would get behind and get crazy. Then I contacted you. You said this would happen and to install the RTC. I didn’t delete the inputs this time and installed the RTC. That brings us to today. So I decided after seeing the same thing where the timestamp was lagging, to un install, then re install the input. Boom that worked. Now they are in sync nothing is getting skewed. All values were default.

Your initial issue appeared to be that your Pi time was not correct, as could be seen in the first photo with your computer’s time different from the time indicated by the UI. I’m not sure what the cause of the additional issue you’re describing, but it very well could be related to your original time issue.

My apologies I get our communication error now. I was simply trying to say that yes, you were correct and that a RTC did in fact correct the issues with the exception that it was still registering oddly. I guess I was just trying to say if you do install a RTC, my inputs had to be redone as well for what ever reason in order for it to register and be in sync properly. Like the old did you turn it off and on again you know? I don’t know why this worked like that, it’s just how I got it to register in sync with the RTC after it was installed in the OS. Love your program it is so much fun to tinker with and is always expanding my imagination. You are a genius. Thank you for your time and solution. Stay safe.

1 Like