Skip to content
Snippets Groups Projects
Commit ec413aa8 authored by Strasser, Andreas's avatar Strasser, Andreas
Browse files

reimplemented ntp time sync

parent 2d3f7bf5
No related branches found
No related tags found
No related merge requests found
...@@ -74,8 +74,6 @@ class NBIoTCOAPRequest : NBIoTRequest ...@@ -74,8 +74,6 @@ class NBIoTCOAPRequest : NBIoTRequest
end end
class NBIoTNTPRequest : NBIoTRequest class NBIoTNTPRequest : NBIoTRequest
def init(callback) def init(callback)
super(self).init(NBIoTRequestType.NTP, callback) super(self).init(NBIoTRequestType.NTP, callback)
end end
...@@ -269,6 +267,46 @@ class NBIoTResetProcedure : NBIoTProcedure ...@@ -269,6 +267,46 @@ class NBIoTResetProcedure : NBIoTProcedure
end end
end end
class NBIoTNTPProcedure : NBIoTProcedure
var cmd_ntp
def init(ser)
super(self).init(ser)
self.cmd_ntp = NBIoTCommand('AT+QNTP=1,\"0.at.pool.ntp.org\"\r\n', '+QNTP: 0', 10)
end
def set_system_time(rsp)
var rsp_args = string.split(rsp, '\"')
var timestamp = nil
for rsp_arg : rsp_args
timestamp = tasmota.strptime(rsp_arg, "%y/%m/%d,%H:%M:%S")
if timestamp != nil
break
end
end
tasmota.cmd('time ' + str(timestamp['epoch'] + 3600)) # UTC + 1
end
def execute()
if self.cmd_in_process == nil
self.cmd_in_process = self.cmd_ntp
end
var rsp = self.fetch_read_rsp_if_contains_expected_rsp_or_send('+QNTP: 0', 'AT+QNTP=1,\"0.at.pool.ntp.org\"\r\n')
if rsp != nil
self.set_system_time(rsp)
self.done = true
end
self.aborted = self.retries_exceeded()
end
end
# ------------------------------------------------------- # # ------------------------------------------------------- #
# Driver State # # Driver State #
# ------------------------------------------------------- # # ------------------------------------------------------- #
...@@ -344,6 +382,8 @@ class NBIoTDriver ...@@ -344,6 +382,8 @@ class NBIoTDriver
if request.request_type == NBIoTRequestType.DEBUG if request.request_type == NBIoTRequestType.DEBUG
procedure = NBIoTDebugProcedure(self.ser, request) procedure = NBIoTDebugProcedure(self.ser, request)
elif request.request_type == NBIoTRequestType.NTP
procedure = NBIoTNTPProcedure(self.ser)
elif elif
tasmota.log(string.format('NBT: Request with type %i not supported, discarding request', request.request_type), 2) tasmota.log(string.format('NBT: Request with type %i not supported, discarding request', request.request_type), 2)
end end
...@@ -358,7 +398,7 @@ class NBIoTDriver ...@@ -358,7 +398,7 @@ class NBIoTDriver
if self.procedure.is_aborted() if self.procedure.is_aborted()
var cmd = string.replace(self.procedure.cmd_in_process.cmd, '\r\n', '') var cmd = string.replace(self.procedure.cmd_in_process.cmd, '\r\n', '')
tasmota.log(string.format('NBT: Exceeded retries at command %s, discarding request', cmd, 2) tasmota.log(string.format('NBT: Exceeded retries at command %s, discarding request', cmd), 2)
end end
self.finish_procedure(self.procedure.is_done()) self.finish_procedure(self.procedure.is_done())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment