Last active
November 25, 2021 20:54
-
-
Save dkeza/9d24e3ba392e0fb5ba9016e513ebd890 to your computer and use it in GitHub Desktop.
Fix wrong date time on Raspberry Pi 3 in LibreELEC (Krypton) v8.0.1 MR (Kodi), when connected over WiFi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
## Python 2.7 script | |
## Use it as workaround for Kodi LibreELEC wrong date time bug, when used on Raspberry Pi 3 over WiFi. | |
## Log in into LibreELEC over SSH, create this script as executable, | |
## | |
## $ nano fixtime.py | |
## $ chmod +x fixtime.py | |
## | |
## and call it from autostart.sh | |
## | |
## $ nano /storage/.config/autostart.sh | |
## | |
## Add delay 10 sec in autostart.sh: | |
## | |
## (sleep 10; | |
## /storage/./fixtime.py | |
## ) & | |
import urllib2 | |
import sys | |
import subprocess | |
from datetime import datetime, timedelta | |
## Returns date (GMT) from Google HTTP response header in this format | |
## (2017, 5, 25, 9, 40, 23, 0, 1, 0) | |
d = urllib2.urlopen('http://www.google.com/').info().getdate('Date') | |
## Create python datetime type | |
dp = datetime(d[0], d[1], d[2], d[3], d[4], d[5], d[6]) | |
## Add 2 hours for CET time zone | |
df = dp + timedelta(hours=2) | |
## Create tuple, to get datetime parts | |
t = df.timetuple() | |
## Convert to format needed for date command in terminal window on BusyBox in LibreELEC | |
## [YYYY.]MM.DD-hh:mm[:ss] | |
s = str(t.tm_year) + '.' + str(t.tm_mon).zfill(2) + '.' + str(t.tm_mday).zfill(2) + '-' +str(t.tm_hour).zfill(2) +':'+str(t.tm_min).zfill(2) + ':' + str(t.tm_sec).zfill(2) | |
## Print it in terminal window for visual check | |
print s | |
## Call OS date command with our new date | |
subprocess.check_output(['date', '--set', s]) | |
sys.exit(0) |
You saved my day, this bug was driving me crazy.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ethernet - OK
WLAN - changed to DHCP now works
Original issue may well have been that broken WLAN did not pick up ntp server
But script is now running