Logic Machine Forum
Script to get the system time and load it to the logic machine. - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Visualization (https://forum.logicmachine.net/forumdisplay.php?fid=9)
+--- Thread: Script to get the system time and load it to the logic machine. (/showthread.php?tid=2207)



Script to get the system time and load it to the logic machine. - Carlos Padilla - 26.08.2019

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.


RE: Script to get the system time and load it to the logic machine. - admin - 26.08.2019

Does your LM have internet access? You should set correct gateway and DNS settings. Then enable NTP client.


RE: Script to get the system time and load it to the logic machine. - Carlos Padilla - 26.08.2019

No, they will not have internet access. Everything will be done through a local network.


RE: Script to get the system time and load it to the logic machine. - Daniel - 27.08.2019

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)



RE: Script to get the system time and load it to the logic machine. - Carlos Padilla - 02.09.2019

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.


RE: Script to get the system time and load it to the logic machine. - admin - 06.09.2019

.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>



RE: Script to get the system time and load it to the logic machine. - Carlos Padilla - 23.09.2019

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


RE: Script to get the system time and load it to the logic machine. - admin - 24.09.2019

Include it via iframe. You can adjust button style by adding CSS directly to .lp file.


RE: Script to get the system time and load it to the logic machine. - Carlos Padilla - 15.11.2019

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.