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.

Multiple event-scripts in 1 script
#8
Hi,

Try this:

Code:
function utf8tounicode(utf8str)
    assert(type(utf8str) == "string")
    local res, seq, val = {}, 0, nil
    for i = 1, #utf8str do
        local c = string.byte(utf8str, i)
        if seq == 0 then
            table.insert(res, val)
            seq = c < 0x80 and 1 or c < 0xE0 and 2 or c < 0xF0 and 3 or
                  c < 0xF8 and 4 or c < 0xFC and 5 or c < 0xFE and 6 or
                  log("invalid UTF-8 character sequence")
            val = bit.band(c, 2^(8-seq) - 1)
        else
            val = bit.bor(bit.lshift(val, 6), bit.band(c, 0x3F))
        end
        seq = seq - 1
    end
    table.insert(res, val)
      resoct = {}
      reshtml = {}
      for i , object in ipairs(res) do
        table.insert(resoct, '0' .. string.format("%o", object))
        table.insert(reshtml, '&#' .. object .. ';')
        end
      return {res,table.concat(res),resoct,table.concat(resoct),reshtml,table.concat(reshtml)}
end

-- Perform action only on value true
if event.getvalue() == true then
  
  -- Load lib
  require('ssl.https')
  require('socket.url')
    
  -- Set parameters
  APIUser = 'YOUR_API_USERTOKEN'
  APIPassw = 'YOUR_API_PASSWORD'
  APIId = 'YOUR_API_ID'
  Sender = '123456789'
  PhoneNumber = '987654321'
  Unicodetable = utf8tounicode(Eventname)
  SMSText = socket.url.escape('value of ' ..  grp.find(event.dst).name .. ' is true')
  
  -- Convert SMS text to unicode
  Unicodetable = utf8tounicode(SMSText)
  SMSText = Unicodetable[4]
  
  -- Build URL
  url = "https://api.clickatell.com/http/sendmsg?user="..APIUser.."&password="..APIPassw.."&api_id="..APIId.."&from=+"..Sender.."&to="..PhoneNumber.."&text="..SMSText.."&unicode=1"
  
  -- Send Request
  res, code, headers, status = ssl.https.request(url)

end

BR,

Erwin
Reply


Messages In This Thread
Multiple event-scripts in 1 script - by Mr.D - 24.04.2017, 17:33
RE: Multiple event-scripts in 1 script - by Erwin van der Zwart - 05.05.2017, 09:44

Forum Jump: