07.12.2020, 09:12
(This post was last modified: 07.12.2020, 09:13 by gjniewenhuijse.)
I like to connect my Twinkly christmas leds to the LM.
I found a LUA example for Fibaro (see attached Twinkly.LUA), but i can't get the example working.
My code:
my data response from "gestalt" looks right with the correct device information, but the "login" gives as result:
thats looks also right, but my response_data is:
and thats not right i think.
Who can help me?
I found a LUA example for Fibaro (see attached Twinkly.LUA), but i can't get the example working.
My code:
Code:
--[[ documentation
api: https://xled-docs.readthedocs.io/en/latest/rest_api.html
mqtt: https://xled-docs.readthedocs.io/en/latest/msqtt_api.html
--]]
-- init
if not init then
require('socket.http')
require('ltn12')
require('json')
socket.http.TIMEOUT = 5
host = "192.168.x.xx"
authToken = nil
init = true
end
local api = {
base = "/xled/v1/",
endpoints = {
login = "login",
verify = "verify",
mode = "led/mode",
deviceName = "device_name",
reset = "led/reset",
movieConfig = "led/movie/config",
movie = "led/movie/full",
gestalt = "gestalt",
brightness = "led/out/brightness"
}
}
function getTwinklyResponseData(endPoint, body, content_type)
local content_type = content_type or "application/json"
local url = "http://" .. host .. api.base .. api.endpoints[endPoint]
local method = "GET"
if body ~= nil then
method = "POST"
if type(body) == "table" and content_type == "application/json" then
body = json.encode(body)
end
end
local response_body = {}
local payload = body
log('input', url, method, payload)
local res, code, response_headers, status = socket.http.request
{
url = url,
method = method,
headers =
{
["Content-Type"] = content_type,
["X-Auth-Token"] = authToken
},
source = ltn12.source.string(payload),
sink = ltn12.sink.table(response_body)
}
log(res, code, response_headers, status)
log('payload', payload)
log('response_body', response_body)
if res and code == 200 then
return true
else
return false
end
end
log('start')
if getTwinklyResponseData("gestalt") then
getTwinklyResponseData("login",{challenge = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\a"})
end
log('einde')
my data response from "gestalt" looks right with the correct device information, but the "login" gives as result:
Code:
* arg: 1
* number: 1
* arg: 2
* number: 200
* arg: 3
* table:
["server"]
* string: esp-httpd/0.5
["content-type"]
* string: application/json
["connection"]
* string: close
* arg: 4
* string: HTTP/1.1 200 OK
Code:
* arg: 1
* string: response_body
* arg: 2
* table:
[1]
* string: {"code":1106}
Who can help me?