LINX

cancel
Showing results for 
Search instead for 
Did you mean: 

Time Stamp in Raspberry Pi 4

Solved!
Go to solution

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 30
(712 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 30
(663 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 30
(603 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 30
(587 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 30
(508 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 30
(442 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 30
(431 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 30
(379 Views)

David thank you very much for the work you did.
Regarding point 1, I have installed all the zones.
Regarding point 2, instead of putting EST I have put UTC, because that is my time zone.
Regarding point 3, I think I have been able to modify the rcS.
And reboot.
But I still have the same result, of which I attach an image, and you can see that the time Labview delivers is 3 hours late.
I also attach an image of the raspi-config output where you can see the time zone of my country, which is UTC-03.
I appeal to your knowledge and those of the Forum in general to see if the problem can be solved.

Thanks a lot

Download All
0 Kudos
Message 9 of 30
(129 Views)


@Choke Looking at your Labview.png I can see that the timezone on the LabVIEW chroot is not set to the timezone you want.  If you have this set properly the date command would return the timezone you want.  This is the first thing to figure out.

 

You have stated that you did what I have outlined above but what is not clear here is if you did this all in the LabVIEW chroot.  If you did this in the LabVIEW chroot then something was not done properly.

 

Here is what it looks like in the directory if you have the timezone installed properly.

LabVIEW chroot timezones.jpg

 

Here is what is looks like if you have a localtime setup to a timezone file properly.  Note that localtime is not a directory as it is a file.  I have accidentally copied over a directory to this location before and if you do this the timezone will not properly be displayed.  The timezone file is not a text file so if you use cat to display it the text will be unreadable.

LabVIEW chroot localtime.jpg

 

I would review this as this is what you need to get the date command to return the proper timezone.  Once you get this to work you can then move on to step 3 to get LabVIEW time to use the timezone.

 

Once you get the configuration of the LabVIEW chroot done properly you can use the code here to experiment with changing the different timezones on the RPi, https://github.com/wiltdavi/Simple-Pi-WebVI-WebSockets.  Note: This code requires the Chroot SSH trick and Run ‘sudo’ Command Without Entering a Password in Linux to be configured on the RPi for all the functionality to work properly.

0 Kudos
Message 10 of 30
(117 Views)