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.

How to control the KNX bus via SMS and send notices via SMS?
#19
Here's a partially implemented example, you can extend it

First you have to install Lua on your device. Standard Lua version 5.1 or higher will work.

In smsd.conf you have to add this line in general config before [GSM1]:
Code:
eventhandler = /var/spool/sms/handler.lua

Then you have to create /var/spool/sms/handler.lua file with the code below and make it executable (chmod 0755)
Code:
#!/usr/bin/lua

function parseheader(line, message)
  local pos, data, header

  pos = line:find(':')
  if not pos then
    return
  end

  header = line:sub(1, pos - 1)
  data = line:sub(pos + 2)

  if header == 'From' then
    message.from = data
  elseif header == 'Length' then
    message.body = {}
  end
end

function parse(filename)
  local file, cmd, proc, body, message

  -- check that file exists
  file = io.open(filename)
  if not file then
    print('cannot open', filename)
    return
  end
  file:close()

  -- file can contain null bytes, so normal read might fail
  cmd = string.format('cat %s | tr -d \\\\0', filename)
  proc = io.popen(cmd)

  message = {}

  for line in proc:lines() do
    if message.body then
      if #line >= 2 then
        table.insert(message.body, line)
      end
    else
      parseheader(line, message)
    end
  end

  proc:close()

  if message.body then
    message.body = table.concat(message.body)
  end

  print('From', message.from)
  print('Body', message.body)
end

status, filename = arg[ 1 ], arg[ 2 ]

-- validate command line arguments
if type(status) == 'string' or type(filename) == 'string' then
  if status == 'RECEIVED' then
    parse(filename)
  else
    print('Wrong status', status)
  end
end
Reply


Messages In This Thread
RE: How to control the KNX bus via SMS and send notices via SMS? - by admin - 11.09.2015, 06:10

Forum Jump: