Use of DEVICE_STATE() command

In determining whether a call is on hold or not I’ve determined the DEVICE_STATE() command is probably my best bet.

A few things I’ve tried are:

   exten => s, 1, NoOp(Device state: ${DEVICE_STATE(SIP/Some_User@voip-domain)})
   exten => s, 1, NoOp(Device state: ${DEVICE_STATE(${CHANNEL})})

Either way it just displays “Device state:” to the console, with the DEVICE_STATE command doing nothing. Is there a better (more correct?) way to use this command? Thanks.

DEVICE_STATE needs a / for a supported technology, e.g. SIP/abcdef01234567890.

Your first example has no / and a bogus @. Your second has a bogus -.

My first example uses “SIP/Some_User@voip-domain,” where, yes, I have obscured the actually sensitive details of the SIP/device URI of my test phone. That said the supplied SIP URI was 100% correct and represent a device that had an active call going on. In the second one I’m trying to pass in the standard channel variable ${CHANNEL}, so I don’t know what “bogus -” means.

So if a valid SIP URI cannot be used, and the channel identifier cannot be used, what does one pass to DEVICE_STATE? Also, does some module need to be loaded for DEVICE_STATE to work?

Thanks.

I incorrectly said that you had missed the SIP/.

For SIP, DEVICE_STATE requires a section name in sip.conf (or users.conf). It does not use a SIP URI. In particular, you cannot request device state on a domain name, used literally.

SIP channel names differ from SIP device names in that they have “-” followed by a serial number, after the device name. This distinguishes between different channels terminating on the same device. (Historically, this was the address of the private data structure, rather than a serial number.)

From your other threads, it looks like you want information about the channel, not the device.

Thanks. In looking closer, another issue I have is that DEVICE_STATE does not show up if I do “core show functions” in the CLI. How do I go about adding this function in?

make menuselect.
Enable it. If that fails, add any missing dependencies, and re-run ./configure and make menuselect.
make
make install.

I cannot find any source/project to make menuselect. Also, in looking at the docs this looks like a build/install time activity. Am I going to jeopardize my already built test system by using this utility?

Thanks again, it would have taken me some time to even find out about menuselect.

Other possibilities, are that you are using an obsolete version, before it was introduced, or, you have auto loading disabled and haven’t loaded the relevant module.

I’m running 1.8.15. You mention modules. I can very easily copy in the relevant .so file into my modules directory, update modules.conf and reload everything. What module would I be looking for…app_devicestate or something?

Thanks.

Asterisk module, not kernel module. Like kernel modules, they need to have been built in the same environment as the rest of the program.

Correct. Which Asterisk module would I want to add?

The obvious one: func_devstate.so

Perfect. Turned out this was the very simply solution to my problem. Now at least I’m getting a state “INVALID” instead of nothing. Should just be tweaking from here. Thanks again.