Jump to content
Sign in to follow this  
Galactic

How to set time on pcDuino*3B

Recommended Posts

Hello pcduino users,

On my pcduinoV2, at reboot, the time was automatically set, but on pcduino 3B, there is not this functionnality.

I have install the ntpdate package, but when I run it, it's fail :

root@ubuntu:/home/hubert# ntpdate ntp.ubuntu.com
ntpdate: relocation error: ntpdate: symbol CRYPTO_memcmp, version OPENSSL_1.0.0 not defined in file libcrypto.so.1.0.0 with link time reference

What can I do to run this command?

 

Regards.

Share this post


Link to post
Share on other sites

Hello,

I have writing a java program to set date and time on my pcDuino 3B :

package time;

import java.io.IOException;
import java.net.InetAddress;
 
import org.apache.commons.net.ntp.NTPUDPClient;
import org.apache.commons.net.ntp.NtpV3Packet;
import org.apache.commons.net.ntp.TimeInfo;

public class Time {
 
    public static void main(String[] args) {
        try {
            String time_SERVER = "ntp.ubuntu.com";
            String ntpDateTime;
            InetAddress inetAddress;
            TimeInfo timeInfo;
            NTPUDPClient timeClient = new NTPUDPClient();
            inetAddress = InetAddress.getByName(time_SERVER);
            if(inetAddress != null){                        
                timeInfo = timeClient.getTime(inetAddress);
                if (timeInfo != null){
                    NtpV3Packet message = timeInfo.getMessage();
                    long serverTime = message.getTransmitTimeStamp().getTime();
                    long temps = serverTime/1000; // conversion en secondes pour la commande système
                    ProcessBuilder pb = new ProcessBuilder("date", "--set=@" + temps);
                    try {
                        //inherit IO
                        pb.inheritIO();
                        Process process = pb.start();
                        process.waitFor();
                    } catch (InterruptedException ex){

                    }
                }
            }        
        } catch (IOException e) {
        }
    }
}

And I put the time.jar in /usr/local/lib with commons-net-3.5.jar

After write the shell script /etc/init.d/time

#!/bin/sh
     
### BEGIN INIT INFO
# Provides:          skeleton
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Example initscript
# Description:       This file should be used to construct scripts to be
#                    placed in /etc/init.d.
### END INIT INFO

    DAEMON="/opt/jdk1.7.0_60/bin/java"
    DAEMON_OPT="-jar /usr/local/lib/time.jar"  # fichier à exécuter
    NAME="time.jar" # progtam name
    PIDFILE=/var/run/$NAME.pid
     
    PATH="/sbin:/bin:/usr/sbin:/usr/bin"
    export JAVA_HOME=/opt/jdk1.7.0_60
    export PATH=${PATH}:${JAVA_HOME}/bin:${JAVA_HOME}/jre/bin
    
    test -e $DAEMON || exit 0
     
    . /lib/init/vars.sh
    . /lib/lsb/init-functions
     
    start_d () {
            log_daemon_msg "Start $NAME Daemon"
	    start-stop-daemon --make-pidfile --start --quiet --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_OPT
    }
     
    stop_d () {
            log_daemon_msg "Stop $NAME Daemon"
            rm -f $PIDFILE
    }
     
    case "$1" in
     
            start)
                    start_d
                    ;;
                    
	    stop)
		    stop_d
		    ;;
     
            restart)
                    d_stop
                    d_start
                    ;;
     
            status)
                    status_of_proc "$daemon_NAME" "$DAEMON" "system-wide $daemon_NAME" && exit 0 || exit $?
                    ;;
            *)
                    echo "Usage: /etc/init.d/$daemon_NAME {start|stop|force-stop|restart|reload|force-reload|status}"
                    exit 1
                    ;;
    esac
    exit 0

with rights :

root@ubuntu:/home/hubert# chown root /etc/init.d/time 
root@ubuntu:/home/hubert# chgrp root /etc/init.d/time
root@ubuntu:/home/hubert# chmod u+x /etc/init.d/time 

make the symbolics links :

root@ubuntu:/home/hubert# update-rc.d  time  defaults

It's run.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×