This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

Script to get the system time and load it to the logic machine.
Hello colleagues, my questions is if it is possible by script to get the time that the browser has and load it to the logic machine, something like clicking the "get from system" button that is in the "utilities / date and time" tab ". The above because I will have a logic machine and in case the date is out of order, the client can update the date without having to enter the integrator or administrator mode. Thank you and I am attentive to your comments.
Does your LM have internet access? You should set correct gateway and DNS settings. Then enable NTP client.
No, they will not have internet access. Everything will be done through a local network.
You could do it from visu with such script
date = grp.getvalue('date_object')
time = grp.getvalue('time_object')

cmd = string.format("date -s '%d-%d-%d %d:%d:%d'", date.year, date.month,, time.hour, time.minute, time.second)
Hi Daniel, thanks for answering and for the script. This Script would be useful if the user enters the date and time manually so that the logic machine will be loaded with the script and the time, but will there be any way instead of the time And date manually, does the logic machine do the equivalent of the "get from system" button, but by means of a script do you place it? So that the user does not have to type the time and date manually, but instead takes the time of the device where he is viewing. Thank you and I am attentive to your comments.
.lp example:
local dt = getvar('dt')

if dt then
  c = dt:split(',')
  if #c == 6 then
    cmd = string.format("date -s '%d-%d-%d %d:%d:%d'", unpack(c))
<!DOCTYPE html>
<html lang="en">
  <meta charset="UTF-8">
  <title>Set date/time from client</title>
  <? print( ?>
  <form method="post">
    <input type="hidden" name="dt">
    <input type="button" value="Set date/time">
document.querySelector('input[type=button]').addEventListener('click', function() {
  var d = new Date();
  var dt = [
    d.getMonth() + 1,

  document.querySelector('input[type=hidden]').value = dt;
Hi admin, thanks for replying. I understand that it is an LP file and I know how I should upload it, the problem is that I do not understand how I associate the button that I am going to use with the LP file? . Thanks and I'm attentive
Include it via iframe. You can adjust button style by adding CSS directly to .lp file.
Partners, thanks for your collaboration! I made a mix, using the LP file and also the code that Daniel sent me, because I had to synchronize the time and date of several logic machines through Http request. Thank you.

Forum Jump: