base_url = 'http://192.168.1.??/api/<yourAPIkeyhere>'
io = require('io')
http = require('socket.http')
ltn12 = require('ltn12')
function hueit(device, operation)
-- Sends commands to Philips Hue bridge
-- device is the device specific url i.e. /lights/1/state
-- operation is the message body i.e. {"on":true, "sat":255, "bri":255,"hue":10000}
-- for details see http://www.developers.meethue.com/documentation/getting-started
local url = base_url .. '/lights/1/state'
print(url)
local req_body = '{"on":true}'
local headers = {
["Content-Type"] = "application/x-www-form-urlencoded";
["Content-Length"] = #req_body;
}
client, code, headers, status = http.request{url=url, headers=headers, source=ltn12.source.string(req_body), method='PUT'}
print(status)
return
end
hueit()
This has worked well for me when it comes to the Philips Hue API.