Http request - obtain device name , description from device ID

Hi,

While I can get the device name using something like this with luup.

local name = luup.attr_get ('name', lul_device)
print(name)

I can’t seem to find the command that gives me that via an external http request (I couldn’t see anything in here → http://wiki.micasaverde.com/index.php/Luup_Requests#device)

What are people using ?

Write your own handler. It’s easy to do and you could send whatever you want.

Oh yes, thanks @therealdb I forgot about that…

http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_register_handler

@therealdb

I’m obviously close, but no cigar yet, when you can please could you help me with the following so I know where I’ve gone wrong.

function lh_devicename (lul_device)
	local name = luup.attr_get ('name', lul_device)
	local html = "</html><head>" ..
                     "</head>" ..
                     "<body>" ..
                     tostring(name) ..
                     "</body></html>"
	return html, "text/html"
end

luup.register_handler("lh_devicename","DeviceName")

When I try to call it with the device number variable -

192.168.102.107:3480/data_request?id=lr_DeviceName&31
192.168.102.107:3480/data_request?id=lr_DeviceName&lul_device=31

It returns

nil

I’ve checked the function works ‘as is’ print(lh_devicename (31)) so the issue I assume must be with how the variable is being passed ?

your code is not correct. try this:

function lh_devicename (lul_request, lul_parameters, lul_outputformat)
	local lul_device =  tonumber(lul_parameters["device"], 10)
	local name = luup.attr_get ('name', lul_device)
	local html = "</html><head>" ..
                     "</head>" ..
                     "<body>" ..
                     tostring(name) ..
                     "</body></html>"
	return html, "text/html"
end

luup.register_handler("lh_devicename","DeviceName")

and call it via:

http://192.168.102.107:3480/data_request?id=lr_DeviceName&device=31

Great, that’s it !

Many thanks @therealdb