This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

gateway on reactor
#13
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.

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
Reply


Messages In This Thread
gateway on reactor - by Frank68 - 02.05.2024, 12:11
RE: gateway on reactor - by admin - 02.05.2024, 12:14
RE: gateway on reactor - by Frank68 - 02.05.2024, 12:21
RE: gateway on reactor - by admin - 02.05.2024, 12:23
RE: gateway on reactor - by Frank68 - 02.05.2024, 12:33
RE: gateway on reactor - by admin - 02.05.2024, 12:34
RE: gateway on reactor - by Frank68 - 02.05.2024, 12:37
RE: gateway on reactor - by Frank68 - 06.05.2024, 14:18
RE: gateway on reactor - by admin - 07.05.2024, 07:49
RE: gateway on reactor - by Frank68 - 07.05.2024, 10:58
RE: gateway on reactor - by Frank68 - 08.05.2024, 08:36
RE: gateway on reactor - by lamgia99 - 12.02.2025, 04:07
RE: gateway on reactor - by admin - 12.02.2025, 10:43
RE: gateway on reactor - by lamgia99 - 13.02.2025, 07:35
RE: gateway on reactor - by admin - 13.02.2025, 07:52

Forum Jump: