Start a new topic

Auto clock sync after power-on

Having had surprisingly many power outages in the past few weeks I've noticed that the OpenEVSE won't resync the time after the power returns. Whether this is because it syncs at a much later time and I'm too impatient, I don't know.


If (as long as time sync is set to "automatic" the charger resynchronised it's time every day at 12:05am, it would mean that five minutes after power-up (when it'll have gone back to midnight at whatever date it says it is, I can't remember) it'll resynchronise. Perhaps this would even go so far as to render the backup battery redundant?


1 person likes this idea

The current sync uses the browser clock, so it can only happen if you log into the station. We are working on Network Time sync which will sync automatically and make the clock chip and backup battery unnecessary.

Wow, I hadn't even considered it was done through the browser, even though I've seen that before (Dedicated Micros and I think Hikvision CCTV recorders have this option alongside NTP).

I might look at sending a RAPI event from my Domoticz server (which amongst other things monitors a UPS) to send a $S1 time sync every 24 hours and also following a period where the mains input voltage has dropped to zero.

Of course I could just buy a battery but where's the fun in that? :)

Okay, here we go. This has been tested on a Raspberry Pi 4 running the latest Raspbian, I'd expect it to work on any other Linux-based OS.


Create evseclock.sh in your home folder or whatever, containing the following:-

  

#!/bin/bash

# =========================================================
# OpenEVSE clock sync script
# =========================================================
 
# Settings
 EVSE_IP="192.168.***.***"                # OpenEVSE IP Address
 EVSE_USERNAME="admin"                  # OpenEVSE Username
 EVSE_PASSWORD="*****"            # OpenEVSE Password
 
 # Create URL
 EVSEURL="http://$EVSE_IP/r?json=1&rapi=\$S1%20`date +"%y%%20%m%%20%d%%20%H%%20%M%%20%S"`"
 echo "$EVSEURL"

 # Run the RAPI command
 curl --digest --user "$EVSE_USERNAME:$EVSE_PASSWORD" "$EVSEURL" 

Edit permissions with chmod 755 evseclock.sh 


Finally put the following in your crontab using sudo crontab -e, change the time (in this case every 5 minutes) and file path to suit:-

*/5 * * * * /home/pi/evseclock.sh >/dev/null 2>&1

 

The echo "$EVSEURL" line can be removed from the script, it was in there for testing.
(I can't edit the above post)

Martin, this looks to be a very good workaround until NTP is implemented.  I will commission the above code this week.  


Have you run into any issue with it on your site in the past two months?


Al

Only that a brief power outage can cause OpenEVSE to drop off the network and not reconnect. The outage will not have caused the wireless access point to drop as it's UPS protected. The EVSE loses its clock though, so doesn't start charging when you expect it to. Power-cycling the EVSE once more seems to sort it back out.


No issue with the script running, though. If required multiple variants of the above script could be added to the crontab, for example dropping the charge current to 6A during the day and bumping back up at night, disabling the EVSE altogether during office hours, whatever floats your boat. Replace S1%20`date +"%y%%20%m%%20%d%%20%H%%20%M%%20%S"` with your command of choice.

Thanks for the add'l info :)

Yes, I have seen the problem you mentioned above: momentary power loss causes the unit's wifi to drop and stay dropped until a longer power cycle.

I know this is old but since NTP is not working, does anyone know why the current script doesn't work?

I can tell it doesn't work because my when my system time(Linuxx) changes the minute, a refresh of the OpenEVSE browser shows the previous minute for about 30 seconds. So, when my system time changes I immediately send run the script and then refresh the web page but the time isn't updated. I look at the developer console and see the S1 command being sent and it has the updated minute value but the OpenEVSE time is not updated.


Thanks.

@doug The old time system uses a DS3231 RTC time chip with battery plugged into the OpenEVSE controller via i2c. The RAPI commands set and read the time on the chip. If you try to do so today, there is no DS3231 chip the to receive the set commands.


1 person likes this

What programmatic mechanism is available to set the time since the previous mechanism has been eliminated via hardware elimination? 


NTP doesn't work and the time drifts or worst the time gets zero'ed out if there's a power glitch/cycle on the OpenEVSE device and the only way I've found to set it is to connect over Wifi and run the Manual time set option.

@Doug

 
I have just tested NTP on 5.1.2, 5.1.3, 5.1.4 and 5.1.5 with pool.ntp.org and time.google.com. I have rebooted the module with the reset button on each and recycled power leaving off for at least 10 seconds. Every time the time is acquired perfectly.


Is it possible your internet/firewall is blocking NTP to the internet? If so, maybe you can run a NTP server on a computer on your local network.


If you want to add a hardware DS3231 RTC chip and battery they are available here. It would connect to the OpenEVSE controller on the I2C port https://www.adafruit.com/product/3013

I just installed openevse_wifi-v1.bin which is 5.15 and this is what I'm greeted with. Notice the time?

image


and I changed the time server from pool.ntp.org to time.google.com and still no updated time.

My home computers all update over ntp via the same Wifi access points so I can't see how that could be blocking.

image


@Doug Can you confirm your station is connected to your home WiFi? Here are my screenshots same firmware version...



Login or Signup to post a comment