Jump to content


Photo

How to set time on pcDuino*3B


  • Please log in to reply
2 replies to this topic

#1 Galactic

Galactic

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 09 January 2017 - 12:57 PM

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.



#2 price

price

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 13 January 2017 - 05:37 AM

I use this command "date -s 01/13/2017" time will be set 2017-1-13



#3 Galactic

Galactic

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 20 January 2017 - 02:44 PM

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.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users