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.
#1
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.
Reply
#2
Does your LM have internet access? You should set correct gateway and DNS settings. Then enable NTP client.
Reply
#3
No, they will not have internet access. Everything will be done through a local network.
Reply
#4
You could do it from visu with such script
Code:
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, date.day, time.hour, time.minute, time.second)
os.execute(cmd)
Reply
#5
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.
Reply
#6
.lp example:
Code:
<?
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))
    io.readproc(cmd)
  end
end
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Set date/time from client</title>
</head>
<body>
  <? print(os.date()) ?>
  <br>
  <form method="post">
    <input type="hidden" name="dt">
    <input type="button" value="Set date/time">
  </form>
<script>
document.querySelector('input[type=button]').addEventListener('click', function() {
  var d = new Date();
  var dt = [
    d.getFullYear(),
    d.getMonth() + 1,
    d.getDate(),
    d.getHours(),
    d.getMinutes(),
    d.getSeconds()
  ].join(',');

  document.querySelector('input[type=hidden]').value = dt;
  document.querySelector('form').submit();
});
</script>
</body>
</html>
Reply
#7
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
Reply
#8
Include it via iframe. You can adjust button style by adding CSS directly to .lp file.
Reply


Forum Jump: