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

improved driver

parent f0c9a621
No related branches found
No related tags found
No related merge requests found
......@@ -235,7 +235,9 @@ class NBIoTResetProcedure : NBIoTProcedure
def execute()
if self.cmd_in_process == nil
self.cmd_in_process = self.cmd_reset
elif self.cmd_in_process == self.cmd_reset && self.read_rsp_contains_expected_rsp_or_send()
end
if self.cmd_in_process == self.cmd_reset && self.read_rsp_contains_expected_rsp_or_send()
self.cmd_in_process = self.cmd_at
elif self.cmd_in_process == self.cmd_at
self.done = self.read_rsp_contains_expected_rsp_or_send()
......@@ -259,7 +261,9 @@ class NBIoTEnablePSMProcedure : NBIoTProcedure
def execute()
if self.cmd_in_process == nil
self.cmd_in_process = self.cmd_register
elif self.cmd_in_process == self.cmd_register && self.read_rsp_contains_expected_rsp_or_send()
end
if self.cmd_in_process == self.cmd_register && self.read_rsp_contains_expected_rsp_or_send()
self.cmd_in_process = self.cmd_enable_psm
elif self.cmd_in_process == self.cmd_enable_psm && self.read_rsp_contains_expected_rsp_or_send()
self.cmd_in_process = self.cmd_enable_sleep
......@@ -287,7 +291,9 @@ class NBIoTDisablePSMProcedure : NBIoTProcedure
def execute()
if self.cmd_in_process == nil
self.cmd_in_process = self.cmd_register
elif self.cmd_in_process == self.cmd_register && self.read_rsp_contains_expected_rsp_or_send()
end
if self.cmd_in_process == self.cmd_register && self.read_rsp_contains_expected_rsp_or_send()
self.cmd_in_process = self.cmd_disable_psm
elif self.cmd_in_process == self.cmd_disable_psm && self.read_rsp_contains_expected_rsp_or_send()
self.cmd_in_process = self.cmd_disable_sleep
......@@ -305,18 +311,20 @@ class NBIoTMQTTConnectProcedure : NBIoTProcedure
super(self).init(ser, request)
var cmd = 'AT+QMTOPEN=0,\"%s\",%s\r\n'
self.cmd_open = NBIoTCommand(string.format(cmd, self.request.host, str(self.request.port)), '+QMTOPEN: 0,0', 10)
self.cmd_open = NBIoTCommand(string.format(cmd, self.request.host, str(self.request.port)), '+QMTOPEN: 0,0', 15)
cmd = 'AT+QMTCONN=0,\"%s\",\"%s\",\"%s\"\r\n'
self.cmd_conn = NBIoTCommand(string.format(cmd, self.request.client, self.request.username, self.request.password),
'+QMTCONN: 0,0,0',
10)
15)
end
def execute()
if self.cmd_in_process == nil
self.cmd_in_process = self.cmd_open
elif self.cmd_in_process == self.cmd_open && self.read_rsp_contains_expected_rsp_or_send()
end
if self.cmd_in_process == self.cmd_open && self.read_rsp_contains_expected_rsp_or_send()
self.cmd_in_process = self.cmd_conn
elif self.cmd_in_process == self.cmd_conn
self.done = self.read_rsp_contains_expected_rsp_or_send()
......@@ -342,7 +350,9 @@ class NBIoTMQTTPublishProcedure : NBIoTProcedure
def execute()
if self.cmd_in_process == nil
self.cmd_in_process = self.cmd_conn
elif self.cmd_in_process == self.cmd_conn && self.read_rsp_contains_expected_rsp_or_send()
end
if self.cmd_in_process == self.cmd_conn && self.read_rsp_contains_expected_rsp_or_send()
self.cmd_in_process = self.cmd_pub
elif self.cmd_in_process == self.cmd_pub
self.done = self.read_rsp_contains_expected_rsp_or_send()
......@@ -490,10 +500,22 @@ class NBIoTDriver
self.state = state
end
def set_psm_pin(value)
tasmota.log(string.format('NBT: Setting PSM_EINT pin to %i', value), 2)
def set_psm_pin_high()
tasmota.log(string.format('NBT: Setting PSM_EINT pin to %i', 1), 2)
gpio.digital_write(self.psm_eint, value)
gpio.digital_write(self.psm_eint, 1)
end
def set_psm_pin_low()
tasmota.log(string.format('NBT: Setting PSM_EINT pin to %i', 0), 2)
gpio.digital_write(self.psm_eint, 0)
end
def wake_up()
self.set_psm_pin_low()
tasmota.set_timer(150, /-> self.set_psm_pin_high())
end
def every_second()
......@@ -502,8 +524,10 @@ class NBIoTDriver
self.next_state(NBIoTDriverState.INIT)
end
elif self.state == NBIoTDriverState.INIT
self.set_psm_pin(1)
self.set_psm_pin_high()
self.next_state(NBIoTDriverState.RESET)
tasmota.set_timer(150, /-> self.wake_up())
elif self.state == NBIoTDriverState.RESET
if self.procedure == nil
self.start_procedure(NBIoTResetProcedure(self.ser))
......@@ -558,6 +582,7 @@ class NBIoTDriver
if procedure != nil
self.start_procedure(procedure)
self.next_state(NBIoTDriverState.BUSY)
self.procedure.execute()
end
end
elif self.state == NBIoTDriverState.BUSY
......@@ -577,7 +602,7 @@ class NBIoTDriver
if self.psm_disabled
self.next_state(NBIoTDriverState.READY)
else
self.set_psm_pin(0)
self.set_psm_pin_low()
self.next_state(NBIoTDriverState.PSM)
end
else
......@@ -599,12 +624,18 @@ var nbiot = module('nbiot')
nbiot.init = def (m)
class nbiot
var _driver
var _started
def init()
self._driver = NBIoTDriver(18, 23, 16)
self._started = false
end
def start()
if !self._started
tasmota.add_driver(self._driver)
end
end
def enable_power_save_mode(callback)
var request = NBIoTRequest(NBIoTRequestType.PSM_ENABLE, callback)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment