LINX

cancel
Showing results for 
Search instead for 
Did you mean: 

Time Stamp in Raspberry Pi 4

Hi everyone.
I ask you if you have ever tried to work with Time Stamp on Raspberry Py.
Attached images of the front panel, block diagram and project.
As you can see, once the vi is downloaded to the Raspberry, the current time appears correctly, but the date / Time string appears 3 hours ahead.
I have tried all possible settings, but could not fix it.
If anyone has the solution, I would be very grateful if you share it.

Thank you very much

0 Kudos
Message 1 of 8
(394 Views)

You need to make sure that the timezone is set to the same than your computer. LabVIEW timestamps are internally always in UTC but get by default translated to local time when displayed or converted to strings according to the rules of the specific platform.

 

When you run your VI from within the project the compiled diagram (and the Time to String node) executes on your RaspberryPi but the frontpanel (and your time indicator) runs on your development PC.

Rolf Kalbermatter
Averna BV
0 Kudos
Message 2 of 8
(345 Views)

Thank you very much rolfk for the prompt reply.
I have set the time the same way on my Pi and on my PC, but I still notice 3 hours difference when I connect "Get Date / Time in secons" and "Format Date / Time String" between them, and run the Vi inside My pi.
Also, when I generate a file containing date and time, for example .csv, it also shows the time 3hs ahead.
I have solved it by doing a sub I saw that it subtracts those three hours apart, but I think it is not entirely correct, that it should be solved by system, which I do not know how to do.

0 Kudos
Message 3 of 8
(285 Views)

The problem might be actually that the Linux environment in which LabVIEW is running is actually its own virtual machine. it is a seperate Linux kernel running in a chroot environment. While it does use some of the infrastructure such as devices and such from the host system, it is really its own computer inside a computer. As such configuring the timezone in the host system is likely not affecting the timezone seen in the chroot environment.

 

So you may actually have to get down on your command line on the Raspi and change into the chroot environment to adjust the timezone there.

 

sudo schroot -r -c lv       // get into LabVIEW chroot environment
timedatectl                 // printout current time settings
timedatectl list-timezones  // show all avalable timezones
timedatectl set-timezone <your timezone>
timedatectl                 // to check
quit                        // leave chroot

Rolf Kalbermatter
Averna BV
0 Kudos
Message 4 of 8
(269 Views)

I have encountered the situation where the timezone in the LabVIEW environment does not match the timezone of the Pi OS and this post has been really helpful to understand what is going on here.  I believe that this last post is getting to the root issue:

 


@rolfk wrote:

The problem might be actually that the Linux environment in which LabVIEW is running is actually its own virtual machine. it is a seperate Linux kernel running in a chroot environment. While it does use some of the infrastructure such as devices and such from the host system, it is really its own computer inside a computer. As such configuring the timezone in the host system is likely not affecting the timezone seen in the chroot environment.

By following the suggestion I was able to get into the LabVIEW chroot environment but the timedatectl command is not available in this environment.  The date command is available and returns the time in UTC even when the host timezone is set to EST.

 

Timezone ComparisonTimezone Comparison

 

With the date command it appears that you should be able to change the timezone by using an argument with the date command, https://unix.stackexchange.com/questions/48101/how-can-i-have-date-output-the-time-from-a-different-....  Though I was not able to get this to work.  It could be that I don't have the syntax correct but I believe it is because there is no timezone information in the LabVIEW environment.  From my research the timezone information should be at /usr/share/zoneinfo and this directory does not exist on the LabVIEW environment while it does on the host environment.

 

ZoneinfoZoneinfo

 

If you agree with my assessment here what is the proper way to get the timezone information to the LabVIEW environment?  Do we just copy the zoneinfo folder from the host OS or is there something we should install to get the timedatectl command available in this environment?

0 Kudos
Message 5 of 8
(190 Views)

@DavidWilt wrote:

 

If you agree with my assessment here what is the proper way to get the timezone information to the LabVIEW environment?  Do we just copy the zoneinfo folder from the host OS or is there something we should install to get the timedatectl command available in this environment?


Inside the LabVIEW chroot environment do following:

opkg update
opkg list tz*

Either do a full install of all timezones

opkg install tzdata

 or if you only want to add support for your area, select the one you need and execute

opkg install tzdata-<your area>

 

After this you should be able to create a symlink to your timezone

ln -s /etc/timezone /usr/share/zoneinfo/europe/paris

 

with the part "europe/paris" set to whatever your timezone is.

Rolf Kalbermatter
Averna BV
Message 6 of 8
(124 Views)

Thank you for your feedback.  I also found that timedatectl is part of systemd so running this may also allow for timezone configuration.

 

> apt-get install systemd

 

I have not gotten around to testing this all out yet but once I do I will report back.

0 Kudos
Message 7 of 8
(113 Views)

I was able to get the LabVIEW time to return matching a specific time zone by performing the following.

 

1) The timezones must be installed as previously suggested


@rolfk wrote:
Inside the LabVIEW chroot environment do following:
opkg update
opkg list tz*

Either do a full install of all timezones

opkg install tzdata

 or if you only want to add support for your area, select the one you need and execute

opkg install tzdata-<your area>

2)  To get the date command to return your local timezone you must update the localtime file with your time zone.  This should be done with a symlink and the -f option will be required because the file will localtime will already exist.

ln -sf /usr/share/zoneinfo/EST /etc/localtime

At this point the date command will return the time based on your timezone setting but LabVIEW will still return the time in UTC.

 

3)  Update the hardware clock to utilize your local timezone instead of UTC time.  The command hwclock is not recognized so the file must be edited manually and can be accomplished by running the following:

sed -i 's/UTC=yes/UTC=no/' /etc/default/rcS

The -i option is required to overwrite the file rcS.  You can confirm that the file was modified by using cat to display the file.  After modifying this file a reboot of the Pi is required to have LabVIEW return the time in the time zone specified in localtime.

 

Note: It was previously suggested to update the /etc/timezone file.  I was not able to see any changes in time based on updating this file.  I am not sure if there is a more proper way to achieve what I have outlined here but this accomplishes the goal of having LabVIEW return date and time in the timezone of your preference.

0 Kudos
Message 8 of 8
(61 Views)