OpenSprinkler Forums Hardware Questions OpenSprinkler Beagle (OSBo) NOOB needs help with RTC service

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #22715

    iDoug
    Participant

    Am having a problem getting the hardware real time clock (RTC) to work. Also, the BeagleBone Black does not set it’s clock on start up. According to the Adafruit link to use the service that sets the RTC, I need to use the command “systemctl”, but am getting the error “command not found”. As Adafruit is using Angstrom and OpenSprinkler is using Ubuntu, am assuming there is a different way to start this service.

    How do I get the “rtc-ds1307.service” to work? Should I change everything to be a Cron job?

    #25856

    Ray
    Keymaster

    I thought the OSBo image is configured to use RTC . I could be wrong since the RTC part has not been thoroughly tested. Note that the RTC initially needs to be set with the current time. Otherwise it will always go back to 2000 Jan 1. Once set, the clock will start running and it should keep up with current time.

    #25857

    iDoug
    Participant

    I can set system time:

    ntpdate -b -s -u pool.ntp.org 

    Set the hardware clock from the current system time.

    sudo hwclock -w 

    Reading system time.

    date

    Reading hardware clock

    sudo hwclock -r

    Everything but enabling and starting the service.

    When I run:

    which systemctl

    there is no response. I am guessing systemctl is not a part of Ubuntu in the OSBo image.

    It does appear that systemctl is NOT a part of Ubuntu. Several people have told me that “upstart” has replaced it.
    http://upstart.ubuntu.com/cookbook/

    Anyone know a conversion from systemctl to upstart?

    #25858

    Ray
    Keymaster

    You are right, systemctl is not part of Ubuntu. I haven’t done much research on this and I am tempted to think you can create a init.d or use rc.local script to perform what you were able to do manually. If you check the Adafruit tutorial on RTC for Raspberry Pi:
    http://learn.adafruit.com/adding-a-real-time-clock-to-raspberry-pi/set-rtc-time
    towards the end there are descriptions about adding a few lines in rc.local to read from RTC automatically on startup. I will check if this can be done on the Bone with Ubuntu.

    #25859

    iDoug
    Participant

    Here is my addition to the /etc/rc.local file:

    #	Get date-time from Internet (Write to BeagleBone Black BBB).
    ntpdate -b -s -u pool.ntp.org
    # Write date-time to the RTC on OpenSprinkler OSBo.
    sudo hwclock -w

    # Write the date-time from the OSBo to BBB.
    # (Just in case the Internet is not available and the battery
    # is working.)
    echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
    sudo hwclock -s

    exit 0

    Please, let me know if you see any potential issues. This does seem to work, even on a OSBo that does not have the date-time initially.

    #25860

    Ray
    Keymaster

    The script looks fine to me. Glad to hear that you tried it and it seems to be working.

    #25861

    nayr
    Participant

    Messing about it seems there’s 2 RTC’s on the OSBo, there is a built on one that I am not sure the details on but when you load the OpenSprinkler one it comes up as /dev/rtc1, as a result you will have to manually tell hwclock to use the OSBo RTC with the –rtc /dev/rtc1 switch.

    [32426.321034] rtc-ds1307 1-0068: SET TIME!
    [32426.339351] rtc-ds1307 1-0068: rtc core: registered ds1307 as rtc1
    [32426.362582] rtc-ds1307 1-0068: 56 bytes nvram
    [32426.376331] i2c i2c-1: new_device: Instantiated device ds1307 at 0x68

    here is my /etc/rc.local, it tries to set time via internet and if that fails it loads time from RTC.

    echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
    ntpdate -b -s -u pool.ntp.org
    if [ $? -ne 0 ];then
    echo Setting system time from OSBo RTC
    hwclock --rtc /dev/rtc1 -s
    hwclock --rtc /dev/rtc0 -w
    else
    echo Updating Internet time on OSBo RTC
    hwclock --rtc /dev/rtc1 -w
    fi

    I went ahead and created us beagle users a setup page on the wiki: http://rayshobby.net/mediawiki/index.php?title=Set_Up_BBB

    #25862

    Ray
    Keymaster

    Cool. Thanks for the tip and the contribution to the Wiki.

    #25863

    nayr
    Participant

    well today about an hour before my watering schedule went off I went out and yanked power to the beagle and removed ethernet; then 50mins later I plugged the beagle back in leaving ethernet disconnected and the sprinklers turned on right on time.

    I’d say the RTC works just fine; my only suggestion is look at replacing the battery with a supercap.. a big supercap should keep time for at least a week and unlike a battery it will handle all temperature extremes and will still be running strong in 10 years.. it wont last the winter w/out power but do you really want to start in spring with a weak battery? A Supercap is also cheaper than a brand name lithium CR battery.

    Edit, another tip: add: allow-hotplug eth0 to your /etc/network/interfaces so you dont have to reboot when u plug the network back in 🙂

    #39355

    noski
    Participant

    I have tried the instruction in the wiki and all the commands worked, but when I disconnected from the internet and rebooted, the time doesn’t get set properly.

    ubuntu@arm:~$ date
    Fri Jul 17 21:58:17 EST 2015
    ubuntu@arm:~$ sudo hwclock --rtc /dev/rtc1 -r
    [sudo] password for ubuntu:
    Sat 18 Jul 2015 08:05:48 PM EST  -0.714392 seconds

    Where do I see the output from the echo commands in /etc/rc.local to confirm what it is doing?

    #39372

    Mike
    Participant

    I found them in one of the /var/log files. I’m not in front of my setup right now but I think it was in /var/log/boot

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.

OpenSprinkler Forums Hardware Questions OpenSprinkler Beagle (OSBo) NOOB needs help with RTC service