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 that you accept these cookies being set.

NTP Server
#1
Hi,

I have a project that will be using multiple LM's. Is it possible to select 1 LM as the time master and configure it as a NTP Server to server the other LM's? The LM's will be on an isolated network with no internet access. I had a look at the settings but was not sure if this is possible.

Reply
#2
The Local server status is the NTP server you asking for. Enable it and in the other LMs put IP of the one with server enabled.
------------------------------
Ctrl+F5
Reply
#3
Keep in mind that you still need an accurate clock source. One solution is a GPS receiver with USB or RS232 interface if it's possible to get GPS coverage in your installation.
Reply
#4
Thanks the the replies, ill give the local server status a try, and look at installing a device to provide accurate time to the master LM
Reply
#5
Hallo,
It's possible create a script for read the time from a ntp server  when "wiser" it's restarted?

Best regards
Fabio Rusconi
Reply
#6
You don’t need a script for that, when the NTP is enabled under the system settings it should sync time automatically, you need to be sure the controller has access to the internet and port 123 is not blocked by a firewall.
Reply
#7
Thank you.

Best regards

Fabio
Reply
#8
(19.12.2020, 06:03)Erwin van der Zwart Wrote: You don’t need a script for that, when the NTP is enabled under the system settings it should sync time automatically, you need to be sure the controller has access to the internet and port 123 is not blocked by a firewall.
Is the same on LM5 where find  function to enable NTP?

Tank's
Reply
#9
System config > Services > NTP client/server. It's enabled by default, but requires valid network gateway and DNS settings to work.
Reply
#10
(28.10.2020, 08:20)admin Wrote: Keep in mind that you still need an accurate clock source. One solution is a GPS receiver with USB or RS232 interface if it's possible to get GPS coverage in your installation.

I have one of this,
https://www.electrokit.com/gps-mottagare...AZEALw_wcB

Is it possible to connect this to usb, and get time and date? 
I have a LM5 with no internet connection and want to sunrise/sunset function.
Reply
#11
Connect it to LM and post what you get in System config > Status > System log.
Reply
#12
Sep 23 11:40:42 LM_Vasbykyrka kern.info kernel: [11761.757200] cdc_acm 1-1:1.0: ttyACM0: USB ACM device
Sep 23 11:40:42 LM_Vasbykyrka kern.info kernel: [11761.753581] usb 1-1: Manufacturer: u-blox AG - www.u-blox.com
Sep 23 11:40:42 LM_Vasbykyrka kern.info kernel: [11761.753569] usb 1-1: Product: u-blox 7 - GPS/GNSS Receiver
Sep 23 11:40:42 LM_Vasbykyrka kern.info kernel: [11761.753557] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
Sep 23 11:40:42 LM_Vasbykyrka kern.info kernel: [11761.753528] usb 1-1: New USB device found, idVendor=1546, idProduct=01a7, bcdDevice= 1.00
Sep 23 11:40:42 LM_Vasbykyrka kern.info kernel: [11761.591438] usb 1-1: new full-speed USB device number 2 using

That what it says.
Reply
#13
Run this as a resident script and post what you get in LM Logs tab:
Code:
require('serial')
port = serial.open('/dev/ttyACM0')
port:flush()
buf = {}

while true do
  char = port:read(1, 1)

  if char then
    if char == '\r' or char == '\n' then
      if #buf > 0 then
        line = table.concat(buf)
        log(line)
        buf = {}
      end
    else
      buf[ #buf + 1 ] = char
    end
  end
end
Reply
#14
Hi,

test 25.09.2025 14:04:25
* string: $GPRMC,120428.00,V,,,,,,,250925,,,N*79
test 25.09.2025 14:04:25
* string: $GPVTG,,,,,,,,,N*30
test 25.09.2025 14:04:25
* string: $GPGGA,120428.00,,,,,0,00,99.99,,,,,,*6B
test 25.09.2025 14:04:25
* string: $GPGSA,A,1,,,,,,,,,,,,,99.99,99.99,99.99*30
test 25.09.2025 14:04:25
* string: $GPGSV,5,1,19,01,,,23,02,,,20,03,,,24,04,,,24*72
test 25.09.2025 14:04:25
* string: $GPGSV,5,2,19,05,,,22,06,,,25,08,,,22,15,,,23*7F
test 25.09.2025 14:04:25
* string: $GPGSV,5,3,19,16,,,22,18,,,25,19,,,22,20,,,22*74
test 25.09.2025 14:04:25
* string: $GPGSV,5,4,19,21,,,22,24,,,22,27,,,21,28,,,22*79
test 25.09.2025 14:04:25
* string: $GPGSV,5,5,19,30,,,23,31,,,17,32,,,24*70
test 25.09.2025 14:04:25
* string: $GPGLL,,,,,120428.00,V,N*47
Reply
#15
The communication is working but there's no GPS signal detected. Try moving the receiver closer to a window and run the script again after some 30 minutes.
Reply
#16
Hi,
Just testing it again and think the signal is right.

test 01.10.2025 13:36:35
* string: $GPRMC,113635.00,A,72184,N,29390,E,0.263,,011025,,,A*7D

There you have it. 11:36:35 2 hours wrong but think you can convert it, and then you have "011025" 1st october 2025.

How can I correct time and date from gps reciver to logicmachine?
Reply
#17
Create a scheduled script that runs once per day during the night when there are no other scheduled scripts or tasks.
The supplied time is in UTC so make sure that LM has correct timezone set for the automatic conversion to work.
For testing purposes you can comment out os.sleep. It is needed so the script is not triggered again if the time is shifted.

Code:
os.sleep(30)

require('serial')
port = serial.open('/dev/ttyACM0')
if not port then
  log('port not found')
  return
end
port:flush()

function settime(line)
  local parts = line:split(',')
  if parts[1] ~= '$GPRMC' then
    return
  end

  local hour, min, sec = string.match(parts[2] or '', '^(%d%d)(%d%d)(%d%d)%.')
  local day, month, year = string.match(parts[10] or '', '^(%d%d)(%d%d)(%d%d)$')

  if not hour or not day then
    return
  end

  local cmd = string.format('date -u -s "20%s-%s-%s %s:%s:%s"; hwclock -w',
    year, month, day, hour, min, sec)

  os.execute(cmd)
  return true
end

buf = {}
lines = 0

while true do
  char = port:read(1, 1)

  if char then
    if char == '\r' or char == '\n' then
      if #buf > 0 then
        line = table.concat(buf)
        lines = lines + 1

        if settime(line) then
          log('time updated')
          break
        elseif lines > 20 then
          log('could not update time')
          break
        end

        buf = {}
      end
    else
      buf[ #buf + 1 ] = char
    end
  end
end
Reply
#18
Thanks, works perfect!
Reply


Forum Jump: