08.05.2017, 08:20
(This post was last modified: 08.05.2017, 09:10 by Erwin van der Zwart.)
Hi,
Thanks Admin!
Then your code should be like this:
BR,
Erwin
Thanks Admin!
Then your code should be like this:
Code:
function utf8cps(str)
local codepoints = {}
local len = #str
local i = 1
while i <= len do
local c = str:byte(i, i)
if c > 0 and c <= 127 then
codepoints[ #codepoints + 1 ] = c
i = i + 1
elseif c >= 194 and c <= 223 then
local c2 = str:byte(i + 1, i + 1) or 0
local cp = bit.bor(bit.lshift(c - 0xC0, 6), c2 - 0x80)
codepoints[ #codepoints + 1 ] = cp
i = i + 2
elseif c >= 224 and c <= 239 then
i = i + 3
elseif c >= 240 and c <= 244 then
i = i + 4
end
end
return codepoints
end
function toutf16hex(str)
local cps = utf8cps(str)
local res = {}
for _, cp in ipairs(cps) do
res[ #res + 1 ] = string.format('%04x', cp)
end
return table.concat(res)
end
-- Perform action only on value true
if event.getvalue() == true then
-- Load lib
require('ssl.https')
-- Set parameters
APIUser = 'YOUR_API_USERTOKEN'
APIPassw = 'YOUR_API_PASSWORD'
APIId = 'YOUR_API_ID'
Sender = '123456789'
PhoneNumber = '987654321'
SMSText = 'value of ' .. grp.find(event.dst).name .. ' is true'
-- Convert SMS text to UTF-16BE
SMSText = toutf16hex(SMSText)
-- 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
Erwin