WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Pi hangs if nortc removed from cmdline.txt  (Read 2533 times)

Offline mxguy31

  • Newbie
  • *
  • Posts: 9
Pi hangs if nortc removed from cmdline.txt
« on: September 07, 2017, 06:14:23 PM »
Hey guys,

I have an RTC module, it contains a pcf2127 chip. Under raspbian it will recognize the rtc and set the clock from it, then update from ntp (typically within 15 minutes of boot). I followed the following steps to use this RTC with PiCore:

Add 'tz=EST+5EDT,M3.2.0/2,M11.1.0/2' to /mnt/mmcblk0p1/cmdline.txt (to set my timezone)
Installed i2c-tools.tcz
installed rtc-4.9.22-picore-v7.tcz
Added the following at the end of /mnt/mmcblk0p1/config.txt 'dtoverlay=i2c-rtc,pcf2127'

rebooted

Verified rtc module can be seen with i2cdetect -y 1 (It shows up - UU)

Quote
tc@thermostat:~$ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- 18 19 1a -- -- -- -- --
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- UU -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

tested with hwclock -r, and I get the time

Quote
tc@thermostat:~$ hwclock -r
Thu Sep  7 22:06:55 2017  0.000000 seconds

tested the time with date, it shows the actual time taking into account timezone
Quote
tc@thermostat:~$ date
Thu Sep  7 18:07:26 EDT 2017

Now here is my problem... When I reboot with the pi isolated from the internet the time gets set to unix epoc (Jan 1970). If I remove 'nortc' from cmdline.txt the system will hang on boot. It only shows the 4 raspberries on the screen... I can not ssh into the pi. I am considering writing a quick script to set the time to the hardware clock after boot however I feel like this functionality should work as is. Am I missing anything?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11675
Re: Pi hangs if nortc removed from cmdline.txt
« Reply #1 on: September 07, 2017, 09:12:36 PM »
Hi mxguy31
The following is sometimes suggest for  bootlocal.sh  to force it to wait for the network to be up before
executing the next command:
Code: [Select]
SEC=60
while [ $SEC -gt 0 ] ; do
   ifconfig | grep -q "Bcast" && break || sleep 1
   echo -ne "Waiting for IP $((SEC--))  \r"     
done
You should be able to adapt it to test for no connection and then set the time.

Offline mxguy31

  • Newbie
  • *
  • Posts: 9
Re: Pi hangs if nortc removed from cmdline.txt
« Reply #2 on: September 08, 2017, 08:16:58 PM »
I haven't written a good bash script in years, this will be a good starting point to shake up my memory. I was hoping that the kernel would take care of it and that I had just missed something simple, my backup solution was exactly what you have proposed. Thanks, I will post my script here when it is done and tested. I am sure others would like to have the same functionality.

Offline mxguy31

  • Newbie
  • *
  • Posts: 9
Re: Pi hangs if nortc removed from cmdline.txt
« Reply #3 on: September 10, 2017, 08:34:08 PM »
I did some digging around and came across an elegant solution. The version of ntpd that comes with piCore is not fully functional (as far as I can tell). Once I discovered this I installed ntp.tcz from the repository. I have been watching it for a day or so now, messing with the time and seeing it come back in sync on it's own. Here is the full information to help anyone else.

After installing ntp.tcz, I added the following to the end of /opt/bootlocal.sh:
Quote
hwclock -su
/usr/local/bin/ntpd

and add the following to /opt/.filetool.lst
Quote
/var/lib/ntp

Don't forget 'filetool.sh -b'

What this does is sets the system clock from the RTC on boot. Then starts the ntp daemon. The ntp daemon will keep the RTC in sync as it follows the ntp servers. By adding /var/lib/ntp to the backup list the offsets will be stored between reboots. The clock is set if the pi is isolated from the net or not.