OpenSprinkler Forums Hardware Questions OpenSprinkler Beagle (OSBo) Getting date to update from RTC on OSBo.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #41409

    noski
    Participant

    My OSBo is not connected to the interent. I had troubles getting the date and time to be set correctly. I assumed this would automatically work but I was wrong. You have to do some extra configuration yourself to get this working.
    After some searching I found the existing wiki article here (http://rayshobby.net/mediawiki/index.php?title=Set_Up_BBB). Unfortunately it wasn’t straight forward and I had some issues. There are a few posts from others having problems also, so I would like to share my learnings in getting a working solution.

    Issue 1:
    The command:
    sudo echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
    returns error:
    -bash: /sys/class/i2c-adapter/i2c-1/new_device: Permission denied

    Cause:
    This command needs to be executed as the root user.

    Solution:
    Switch to the root user first.
    sudo su
    Then run the command.
    sudo echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device

    Note: this command can only be run successfully once per system session.
    If you try to execute the command again, you will get the error:
    echo: write error: Invalid argument
    This is ok, it just acknowledges that it has already been run successfully.

    Issue 2:
    You have added the commands to rc.local but it isn’t working.

    Cause:
    The rc.local script terminates because the ntpdate command fails and the rc.local script has the -e flag on the first line.

    This is probably best explained in this link:
    http://askubuntu.com/questions/239600/why-doesnt-rc-local-run-all-my-commands-and-what-can-i-do-about-it

    Solution:
    Put the commands in a separate script and call that script from rc.local.

    I created script:
    /home/ubuntu/update_date.sh
    and set the permissions:
    chmod 775 update_date.sh

    contents:

    #!/bin/bash
    
    #below based on instructions from here:
    #http://rayshobby.net/mediawiki/index.php?title=Set_Up_BBB
    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
    #end Set_Up_BBB
    
    exit 0
    

    and then in rc.local:

    #!/bin/sh -e
    #
    # rc.local
    #
    # This script is executed at the end of each multiuser runlevel.
    # Make sure that the script will "exit 0" on success or any other
    # value on error.
    #
    # In order to enable or disable this script just change the execution
    # bits.
    #
    # By default this script does nothing.
    
    #update the system time from Internet or RTC
    /home/ubuntu/update_date.sh > /tmp/rc_local__update_date.log 2>&1
    
    exit 0
    

    You can check to see that the system date got updated correctly:

    ubuntu@arm:~$ cat /tmp/rc_local__update_date.log
    Error resolving pool.ntp.org: Name or service not known (-2)
    Setting system time from OSBo RTC

    Hopefully Ray will update the Wiki accordingly and until then this post helps instead.

    #41544

    Ray
    Keymaster

    Thanks for posting the solution. Will update the Wiki asap. Unfortunately we’ve stopped selling OSBo, due to the rather small demand. We do still sell bare OSBo PCBs for anyone interested.

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

OpenSprinkler Forums Hardware Questions OpenSprinkler Beagle (OSBo) Getting date to update from RTC on OSBo.