1 2 Previous Next 21 Replies Latest reply on Aug 22, 2014 7:46 PM by Piol

    What is the best way to set the timezone / date on the Galileo?

    glue

      Having a little trouble, I SSL in then try to set the date:

      date +%Y%m%d -s "20131230"

      then type "date" and it returns

      Sat Aug 13 12:30:09 UTC 2005

        • 1. Re: What is the best way to set the timezone / date on the Galileo?
          glue

          figured it out, kinda a strange format (MMDDhhmmYYYY.ss) so 12/31/2013 at 12:49am equals

          date 1231004913

          • 2. Re: What is the best way to set the timezone / date on the Galileo?
            AlexT_Intel

            That's probably because both SPI and SD images use busybox and it has slightly specific accepted date/time formats.

             

            You should be able to use the ones listed here (look for the date command description, there's no direct link to it unfortunately): http://busybox.net/downloads/BusyBox.html, which is a help page for the latest BusyBox version. It may differ slightly from what's available in Galileo Linux, due to older version being in the image, but I believe not much.

            1 of 1 people found this helpful
            • 3. Re: What is the best way to set the timezone / date on the Galileo?
              scruss

              If you have networking enabled, and can ssh into a remote Linux box which has the correct time:

               

              date -u `ssh user@remotehost date -u '+%m%d%H%M%Y.%S'`

               

              will set your Galileo's time from the remote machine. The sync won't be perfect, but ±1 second or so.

              • 4. Re: What is the best way to set the timezone / date on the Galileo?
                LeFelix

                Is there no way setting it automatically via Google or a time server (my NAS does that every night)?

                That would be a very easy way if you have internet connected to the board.

                • 5. Re: What is the best way to set the timezone / date on the Galileo?
                  rmm200

                  I installed a ntp client on my board. www.ntp.org - download source and build it. Time synchs every time it connects to the internet through WiFi.

                  I originally wanted to use a coin cell to maintain the RTC - but why bother when the time is always right anyway.

                  1 of 1 people found this helpful
                  • 6. Re: What is the best way to set the timezone / date on the Galileo?
                    AlexT_Intel

                    And those without SDK on the board or cross-toolchain on the big brother may use the package repo I announced here a while ago. It has ntp and accompanying packages.

                    • 7. Re: What is the best way to set the timezone / date on the Galileo?
                      DanW

                      Regarding the timezone, setting the TZ variable works. For example, I'm in Eastern Standard timezone, so I set the TZ variable in my .profile:

                       

                      root@galileo:/etc/init.d# cat ~/.profile

                      TZ='EST5EDT'

                      export TZ

                       

                      HTH,

                       

                      Dan.

                      • 8. Re: What is the best way to set the timezone / date on the Galileo?
                        Chris_F

                        And for folks from 'downunder' like me, the following TZ variable works for Sydney, Australia:

                         

                        TZ=AEST-10:00AEDT-11:00,M10.1.0/02:00:00,M4.1.0/03:00:00

                         

                        Where:

                        • AEST-10:00 - Australian Eastern Standard Time (10 hours ahead of UTC)
                        • AEDT-11:00 - Australian Eastern Daylight Time (11 hours ahead of UTC)
                        • M10.1.0/02:00:00 - starts Oct, 1st Sunday, at 2:00 AM (AEST)
                        • M4.1.0/03:00:00 - ends Apr, 1st Sunday, at 3:00 AM (AEDT)

                         

                        Chris.

                        • 9. Re: What is the best way to set the timezone / date on the Galileo?
                          rgb

                          Some Questions

                          Would you happen to know how to set the time zone for Vietnam? It doesn't seem to like Asia/Ho_Chi_Minh and I haven't found a simple code like is used in Australia or the US.

                          I would also like to know how to get rid of a sketch so one doesn't run automatically on startup.

                          Next, regarding setting the date, is there a reason you didn't use rdate to set the system date and hwclock to set the hardware date instead of installing another program?  I am trying to remember how to run programs automatically at start, then will try it.

                          Here is a program I kluged together to use the system commands to display information on an LCD screen.The way I came up with to get rid of the end of line character (at least that is what I think it is) that is displayed I know is a kluge. Do you know of a better way?

                          Thanks

                          rgb

                          /*

                            LCD_Functions

                          Program to display different information about the Galileo based on button that was pushed

                          ------------------------------------------------------

                          Note: Ethernet cable must be plugged in prior to starting Galileo or it won't get an address

                          Note: Need to put electrical tape on LCD or shorts against Ethernet port connector

                          Note: Needs updated Liquid Crystal Library

                            https://github.com/mikalhart/galileo-LiquidCrystal/releases/

                            Download and put in Sketches/library directory

                          ------------------------------------------

                          Based on sketches from

                          http://www.arduino.cc/en/Tutorial/LiquidCrystal

                          and http://www.cyberciti.biz/faq/how-to-find-out-the-ip-address-assigned-to-eth0-and-display-ip-only/

                          and https://communities.intel.com/thread/45335

                          and button test by Mark Bramwell, July 2010

                          ---------------------------------------------------

                          The circuit:

                          * LCD RS pin to digital pin 12

                          * LCD Enable pin to digital pin 11

                          * LCD D4 pin to digital pin 5

                          * LCD D5 pin to digital pin 4

                          * LCD D6 pin to digital pin 3

                          * LCD D7 pin to digital pin 2

                          * LCD R/W pin to ground

                          * 10K resistor:

                          * ends to +5V and ground

                          * wiper to LCD VO pin (pin 3)

                          */

                           

                          // include the library code:

                          #include <LiquidCrystal.h>

                          // initialize the library with the numbers of the interface pins

                          LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

                          char FileBuffer[16]; //set up space to read in files

                          // define values used by the panel and buttons

                          int lcd_key     = 0;

                          int adc_key_in  = 0;

                          #define btnRIGHT  0

                          #define btnUP     1

                          #define btnDOWN   2

                          #define btnLEFT   3

                          #define btnSELECT 4

                          #define btnNONE   5

                          // define variable used for temp

                          char scale[4];

                          char raw[4];

                          char offset[4];

                          int raw_i;

                          int scale_i;

                          int offset_i;

                          int temp;

                           

                          void setup() {

                            // initialize serial communications:

                            //Serial.begin(9600);

                            // Start the telnet server on Galileo

                             system("telnetd -l /bin/sh");

                            // set up the LCD's number of columns and rows:

                            lcd.begin(16, 2);

                            // clear the screen

                            lcd.clear();

                          // Print a message to the LCD.

                            lcd.setCursor(0, 0);

                            lcd.print("Welcome to VGU");

                            lcd.setCursor(0, 1);

                            lcd.print("Galileo Status");

                            delay(5000);

                            lcd.clear(); //clear the screen

                          }

                           

                          void loop()

                          {

                            //delay(5000);  

                            lcd_key = read_LCD_buttons();  // read the buttons

                            switch (lcd_key)               // depending on which button was pushed, we perform an action

                            {

                             case btnRIGHT:

                               {

                              GetName();

                           

                               break;

                               }

                             case btnLEFT:

                               {

                               GetIP();

                               break;

                               }

                             case btnUP:

                               {

                               getADCTemp();

                               break;

                               }

                             case btnDOWN:

                               {

                               GetTime();

                               break;

                               }

                             case btnSELECT:

                               {

                               SetTime();

                               break;

                               }

                               case btnNONE:

                               {

                                //lcd.clear(); //clear the screen

                                lcd.setCursor(0, 0);

                                lcd.print("L:IP, Up:Temp");

                                lcd.setCursor(0, 1);

                                lcd.print("Dn:Time,R:Name");

                                lcd.print(" ");

                                delay(500);

                               break;

                               }

                             }

                          }

                           

                          // read the buttons

                          int read_LCD_buttons()

                          {

                          adc_key_in = analogRead(0);      // read the value from the sensor

                          // my buttons when read are centered at these valies: 0, 144, 329, 504, 741

                          // we add approx 50 to those values and check to see if we are close

                          if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result

                          if (adc_key_in < 50)   return btnRIGHT;

                          if (adc_key_in < 195)  return btnUP;

                          if (adc_key_in < 380)  return btnDOWN;

                          if (adc_key_in < 555)  return btnLEFT;

                          if (adc_key_in < 790)  return btnSELECT; 

                          return btnNONE;  // when all others fail, return this...

                          }

                           

                          //Get the IP address from the system

                          void GetIP()

                          {

                            // Call ifconfig, pipe through grep to get ipaddress and redirect to file in /home/root

                               system("ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'>/home/root/ip.txt");

                               FILE *fp;

                               fp=fopen("/home/root/ip.txt","r");

                               fgets(FileBuffer, 16, fp);

                               fclose(fp);

                               lcd.clear(); //clear the screen

                               lcd.setCursor(0, 1);

                               lcd.print(FileBuffer);

                               lcd.rightToLeft(); // Get rid of end of file character

                               lcd.print(" ");

                               lcd.print(" ");

                               lcd.leftToRight();

                               delay(5000);

                          }

                           

                          // Get the system date

                          void GetName()

                          {

                               FILE *fp;

                               fp=fopen("/etc/hostname","r");

                               fgets(FileBuffer, 16, fp);

                               fclose(fp);

                               lcd.clear(); //clear the screen

                               lcd.setCursor(0, 1);

                               lcd.print(FileBuffer);

                               lcd.rightToLeft(); // Get rid of end of file character

                               lcd.print(" ");

                               lcd.print(" ");

                               lcd.leftToRight();

                               delay(5000);

                          }

                           

                          // Get the system time and date

                          void GetTime()

                          {

                            //Get Date

                             system("date '+DATE: %m/%d/%y' > /home/root/date.txt");

                               FILE *fp;

                               fp=fopen("/home/root/date.txt","r");

                               fgets(FileBuffer, 16, fp);

                               fclose(fp);

                               lcd.clear(); //clear the screen

                               lcd.setCursor(0, 0);

                               lcd.print(FileBuffer);

                               lcd.rightToLeft(); // Get rid of end of file character

                               lcd.print(" ");

                               lcd.print(" ");

                               lcd.leftToRight();

                            //Get Time

                             system("date '+%H:%M:%S' > /home/root/date.txt");

                               fp=fopen("/home/root/date.txt","r");

                               fgets(FileBuffer, 16, fp);

                               fclose(fp);

                               lcd.setCursor(0, 1);

                               lcd.print(FileBuffer);

                                    lcd.rightToLeft(); // Get rid of end of file character

                               lcd.print(" ");

                               lcd.print(" ");

                               lcd.leftToRight();

                               delay(5000);

                          }

                           

                          // Set the system time

                          void SetTime()

                          {

                             lcd.clear(); //clear the screen

                             lcd.setCursor(0,0);

                             lcd.write("Setting Time");

                             lcd.setCursor(0,1);

                             lcd.write("Please Wait");

                             system("rdate -s time.nist.gov"); // set system time

                             system("hwclock -w"); // set hardware clock to system time

                             delay(5000);

                          }

                           

                           

                          // Get temp from on-board sensor

                          int getADCTemp(){

                                FILE *fp_raw;

                          //read the values from scale, raw and offset files.

                                fp_raw = fopen("/sys/bus/iio/devices/iio:device0/in_temp0_raw", "r");    

                                fgets(raw, 4, fp_raw);                                                   

                          //we need all three values, because the formula for

                          //calulating the actual temperature in milli-degrees Celcius

                          //is: TEMP = (RAW + OFFSET) * SCALE

                                fclose(fp_raw);                                                         

                                FILE *fp_scale;

                                fp_scale = fopen("/sys/bus/iio/devices/iio:device0/in_temp0_scale", "r");

                                fgets(scale, 4, fp_scale);

                               

                                fclose(fp_scale);

                                      FILE *fp_offset;

                                fp_offset = fopen("/sys/bus/iio/devices/iio:device0/in_temp0_offset", "r");

                                fgets(offset, 4, fp_offset);

                                fclose(fp_offset);

                               

                                raw_i = atoi(raw);         //we have the values now, but they are in ASCII form-                                                     

                                scale_i = atoi(scale);     //we need them as integers so we can use them for calculations.

                                offset_i = atoi(offset);

                              

                                int temp = (raw_i + offset_i) * scale_i;  //Calculate temperature in milli-degrees celcius

                                temp /= 1000;                         //divide by 1000 to convert to degrees celcius

                                //return temp;

                               //Serial.print(temp); //Check results

                               lcd.clear(); //clear the screen

                               lcd.setCursor(0, 1);

                               lcd.write("Temp is:");

                               lcd.setCursor(9, 1);

                               lcd.print(temp);

                               lcd.print((char)223);

                               lcd.print("C");

                               lcd.print(" ");

                               delay(5000);

                               }

                          • 10. Re: What is the best way to set the timezone / date on the Galileo?
                            Chris_F

                            I believe the international 3-character code for Vietnam is 'VNM' and there is no daylight saving.  Therefore, I would suggest the following TZ value is what is appropriate for 7 hours ahead of UTC:

                             

                            TZ=VNM-07:00

                             

                            With no daylight saving in Vietnam there is no need to specify a daylight saving time zone value or the starting and ending dates and times.

                             

                            Regards,

                            Chris

                            • 11. Re: What is the best way to set the timezone / date on the Galileo?
                              rgb

                              Hi Chris

                              Thanks, VNM-07:00 worked, and I think I know I figured out how to stop the sketch from loading so can now start working the other way around of using Yocto to control the Arduino pins, instead of an Arduino sketch to run system commands.. In any case, thanks again and Happy Saint Patrick's day

                              rgb

                              • 12. Re: What is the best way to set the timezone / date on the Galileo?
                                rgb

                                Hi Chris

                                I found a partial answer to how to set the timezone.

                                I added an export line right after the export path line in /etc/profile and now when I run date from the console, the time zone is correct.

                                Some strange things.

                                After reading through the scripts in init.d and extensive searching on the Internet, I tried replacing the /etc/localtime file with /usr/share/zoneinfo/Asia/Ho_Chi_Minh from another Linux system, but it didn't work even though the /etc/init.d/rcS script should have read it. Also strange is that the board shows the correct time when I run date +%H:%M:%S from the console (using SSH ) but when I run system("date '+%H:%M:%S' > /home/root/date.txt"); in the sketch I sent you earlier, it comes back with UTC time.

                                In any case I hope someone is collecting all of the things users are discovering and will but them in a FAQ file.

                                Such as to change the hostname of the system you need to edit /etc/hostname.

                                Another option would be to develop a program like raspi-config on the raspberry pi to set the configurations.

                                thanks

                                rgb

                                • 13. Re: What is the best way to set the timezone / date on the Galileo?
                                  AlexT_Intel

                                  > but when I run system("date '+%H:%M:%S' > /home/root/date.txt"); in the sketch I sent you earlier, it comes back with UTC time.

                                  That's probably because you don't have a shell that way and it doesn't read the /etc/profile to set the TZ.

                                   

                                  In general, as far as I've found out, you can only use the POSIX formats they call "first" and "second" here: TZ Variable - The GNU C Library

                                   

                                  I personally just took the value from a "big brother" PC with openSUSE. Surprisingly I couldn't find the ready-made database of possible valuues for that format (unlike for the current most common one, with region/city names), though I haven't searched longer than 15 minutes and it's probably because you can put up such a TZ value string quite easily using information from Google and format description.

                                  • 14. Re: What is the best way to set the timezone / date on the Galileo?
                                    rgb

                                    Hi Alex

                                    Thanks for the response and sorry to bother you with what is probably not all that important, but if I use the Galileo with students, they are sure to ask why it gives the wrong time. Actually I spent way longer than 15 minutes and couldn't find a list of Time Zone Variables for locations outside of the North America, Australia/New Zealand and parts of Europe. I would suggest that a table be added to the getting started guide.

                                    If the system calls aren't using a shell, how are shell commands being execuated and is there any way to set environment variables? Can you send me a link to how the system command works?  I assumed it interfaced with the shell, but maybe as a different user. I tried using the system command to set the TZ, but that didn't work either.

                                    I guess I can just convert the string to an integer and subtract the difference and then change the date based on the result to get the correct time and date, but there should be a better way,

                                    Thanks

                                    rgb

                                    1 2 Previous Next