Skip to content

Commit

Permalink
change order on boot to prevent log entries with wrong timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
elschnorro77 committed Mar 25, 2024
1 parent 3c4ec2a commit 5579322
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@ def main():
else:
debug = False # flag to enable debug mode (HDMI output enabled and no rebooting)

# check if wittypi or other RTC is connected and if RTC time is valid
wittypi_status = check_wittypi(settings, False)
if ('rtc_time_is_valid' in wittypi_status) and ('rtc_time_local' in wittypi_status) and wittypi_status['rtc_time_is_valid'] and (wittypi_status['rtc_time_local'] is not None):
#set systemtime from RTC
logger.info('Writing RTC time ' + wittypi_status['rtc_time_local'].strftime("%a %d %b %Y %H:%M:%S") + ' to system...')
rtc_to_system()
continue_wittypi_schedule()
if wittypi_status['is_rtc_connected'] and not wittypi_status['service_active']:
#add event to shutdown Pi from WittyPi button
add_halt_pin_event(halt_pin_event_detected)

if debuglevel > 20:
# stop HDMI power (save energy)
logger.info('HoneyPi '+ get_rpiscripts_version() + ' Started on ' + get_pi_model() + ' as User ' + whoami() + ', Debuglevel: "' + logging.getLevelName(debuglevel) + '", Debuglevel logfile: "' + logging.getLevelName(debuglevel_logfile)+'"')
Expand All @@ -285,26 +296,9 @@ def main():

q = Queue() # TODO check is this used anywhere?

# TODO add description what is done here and why
if settings['display']['enabled']:
tOLed = threading.Thread(target=oled, args=())
tOLed.start()

# remove commands to set RTC time to internet from wittypi syncTime.sh
remove_wittypi_internet_timesync()

# check if wittypi or other RTC is connected and if RTC time is valid
wittypi_status = check_wittypi(settings)
if ('rtc_time_is_valid' in wittypi_status) and ('rtc_time_local' in wittypi_status) and wittypi_status['rtc_time_is_valid'] and (wittypi_status['rtc_time_local'] is not None):
#set systemtime from RTC
logger.info('Writing RTC time ' + wittypi_status['rtc_time_local'].strftime("%a %d %b %Y %H:%M:%S") + ' to system...')
rtc_to_system()
continue_wittypi_schedule()
if wittypi_status['is_rtc_connected'] and not wittypi_status['service_active']:
#add event to shutdown Pi from WittyPi button
add_halt_pin_event(halt_pin_event_detected)


# check if GPS is configured and start background thread to sync time to GPS if required.
gpsSensors = get_sensors(settings, 99)
for (sensorIndex, gpsSensor) in enumerate(gpsSensors):
Expand Down Expand Up @@ -359,6 +353,11 @@ def main():
# register button press event
GPIO.add_event_detect(GPIO_BTN, GPIO.BOTH, callback=button_pressed, bouncetime=bouncetime)

# TODO add description what is done here and why
if settings['display']['enabled']:
tOLed = threading.Thread(target=oled, args=())
tOLed.start()

# blink with LED on startup
tblink = threading.Thread(target=blink_led, args = (GPIO_LED,))
tblink.start()
Expand Down

0 comments on commit 5579322

Please sign in to comment.