Module ntp
模块功能:网络授时.
重要提醒!!!!!! 本功能模块采用多个免费公共的NTP服务器来同步时间 并不能保证任何时间任何地点都能百分百同步到正确的时间 所以,如果用户项目中的业务逻辑严格依赖于时间同步功能 则不要使用使用本功能模块,建议使用自己的应用服务器来同步时间 参考 http://ask.openluat.com/article/912 加深对授时功能的理解
Info:
- Copyright: openLuat
- Release: 2017.10.21
- License: MIT
- Author: openLuat
Functions
getServers () | 获取NTP服务器地址列表 |
setServers (st) | 设置NTP服务器地址列表 |
isEnd () | NTP同步标志 |
ntpTime (ts, fnc, fun) | 同步时间,每个NTP服务器尝试3次,超时8秒,适用于被任务函数调用 |
timeSync (ts, fnc, fun) | 自动同步时间任务适合独立执行. |
Functions
- getServers ()
-
获取NTP服务器地址列表
Returns:
-
table,服务器地址列表
Usage:
local addtable = ntp.getServers()
-
- setServers (st)
-
设置NTP服务器地址列表
Parameters:
- st
tab类型,服务器地址列表
Returns:
-
无
Usage:
ntp.getServers({"1edu.ntp.org.cn","cn.ntp.org.cn"})
- st
- isEnd ()
-
NTP同步标志
Returns:
-
boole,NTP的同步状态true为成功,fasle为失败
Usage:
local sta = ntp.isEnd()
-
- ntpTime (ts, fnc, fun)
-
同步时间,每个NTP服务器尝试3次,超时8秒,适用于被任务函数调用
Parameters:
- ts
每隔ts小时同步1次
- fnc
同步成功后回调函数
- fun
同步成功前回调函数
Returns:
-
无
Usage:
ntp.ntpTime() -- 只同步1次
ntp.ntpTime(1) -- 1小时同步1次
ntp.ntpTime(nil,fnc) -- 只同步1次,同步成功后执行fnc()
ntp.ntpTime(24,fnc) -- 24小时同步1次,同步成功后执行fnc()
- ts
- timeSync (ts, fnc, fun)
-
自动同步时间任务适合独立执行. 重要提醒!!!!!! 本功能模块采用多个免费公共的NTP服务器来同步时间 并不能保证任何时间任何地点都能百分百同步到正确的时间 所以,如果用户项目中的业务逻辑严格依赖于时间同步功能 则不要使用使用本功能模块,建议使用自己的应用服务器来同步时间
Parameters:
- ts
每隔ts小时同步1次
- fnc
同步成功后回调函数
- fun
同步成功前回调函数
Returns:
-
无
Usage:
ntp.timeSync() -- 只同步1次
ntp.timeSync(1) -- 1小时同步1次
ntp.timeSync(nil,fnc) -- 只同步1次,同步成功后执行fnc()
ntp.timeSync(24,fnc) -- 24小时同步1次,同步成功后执行fnc()
- ts