12.02.2025, 10:43
1. Replace AT:read() function in user.sms with the following code.
2. Restart the SMS script.
3. Post what you have in Logs when this issue happens again.
2. Restart the SMS script.
3. Post what you have in Logs when this issue happens again.
Code:
function AT:read(timeout)
local char, err, timeout, deftimeout, line
-- default timeout is 1 second, converted to 0.1 sec ticks
timeout = tonumber(timeout) or 1
timeout = timeout * 10
deftimeout = timeout
-- read until got one line or timeout occured
while timeout > 0 do
-- read 1 char
char, err = self.port:read(1, 0.1)
-- got data
if char then
-- got LF, end of line
if char == '\n' then
-- convert to string and empty buffer
line = table.concat(self.buffer)
self.buffer = {}
line = line:trim()
-- return only lines with data
if #line > 0 then
log('read line', line)
return line
-- reset timeout
else
timeout = deftimeout
end
-- ignore CR
elseif char ~= '\r' then
table.insert(self.buffer, char)
end
-- read timeout
elseif err == 'timeout' then
timeout = timeout - 1
-- other error
else
break
end
end
log('read timeout', self.buffer)
return nil, err
end