LogicMachine Forum
NTP Server - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: NTP Server (/showthread.php?tid=2941)



NTP Server - Diggerz - 28.10.2020

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.




RE: NTP Server - Daniel - 28.10.2020

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.


RE: NTP Server - admin - 28.10.2020

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.


RE: NTP Server - Diggerz - 30.10.2020

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


RE: NTP Server - fabiorusco - 17.12.2020

Hallo,
It's possible create a script for read the time from a ntp server  when "wiser" it's restarted?

Best regards
Fabio Rusconi


RE: NTP Server - Erwin van der Zwart - 19.12.2020

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.


RE: NTP Server - fabiorusco - 19.12.2020

Thank you.

Best regards

Fabio


RE: NTP Server - Frank68 - 07.08.2025

(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


RE: NTP Server - admin - 07.08.2025

System config > Services > NTP client/server. It's enabled by default, but requires valid network gateway and DNS settings to work.


RE: NTP Server - ceddix - 17.09.2025

(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-usb-dfrobot-tel0137?gad_source=1&gad_campaignid=17338847491&gbraid=0AAAAAD_OrGMA3KBzdISif1Ed7i3rT_Iz0&gclid=Cj0KCQjwuKnGBhD5ARIsAD19RsYPS3PrAVEPT8leWbkZMnDYrWDueUqXFKBCxDrt1LPalIQcWo2yAAsaAjAZEALw_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.


RE: NTP Server - admin - 23.09.2025

Connect it to LM and post what you get in System config > Status > System log.


RE: NTP Server - ceddix - 24.09.2025

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.


RE: NTP Server - admin - 24.09.2025

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



RE: NTP Server - ceddix - 25.09.2025

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


RE: NTP Server - admin - 25.09.2025

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.


RE: NTP Server - ceddix - 01.10.2025

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?


RE: NTP Server - admin - 01.10.2025

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



RE: NTP Server - ceddix - 01.10.2025

Thanks, works perfect!