[Home]

Summary:ASTERISK-14231: DEVICE_STATE() always returns 0 (Unknown)
Reporter:Phil Haddad (pmhaddad)Labels:
Date Opened:2009-05-29 15:07:54Date Closed:2011-06-07 14:07:26
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Applications/app_chanisavail
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:
Description:I am trying to determine whether or not a DAHDI channel is on or off the hook. But no matter what I do it always returns unknown or zero for the value. I'm running Asterisk 1.6.0.9. In the CLI I can see that the phone is off or on the hook by doing a dahdi show channel 1.

Here is part of my extensions.conf

exten => s,1,ChanIsAvail(SIP/server&DAHDI/1)
exten => s,n,Read(${AVAILCHAN})
exten => s,n,Set(NEWVAR=${CUT(AVAILCHAN,/,1)})
exten => s,n,GoToIf($["${NewVar}"="DAHDI"]?dahdi
exten => s,n,GoToIf($["${NewVar}"=""]?down
exten => s,n(dahdi),NoOp(My phone state is currently ${DEVICE_STATE(DAHDI/1)})
exten => s,n,Noop(${AVAILSTATUS})
exten => s,n,Dial(DAHDI/1/${MACRO_EXTEN:1})
exten => s,n,Hangup()

Here is what the CLI shows.
Executing [s@macro-test:1] ChanIsAvail("SIP/2190-240bad10", "SIP/server&DAHDI/1") in new stack
== Using SIP RTP CoS mark 5
-- Hungup 'DAHDI/1-1'
-- Executing [s@macro-test:2] Read("SIP/2190-240bad10", "DAHDI/1-1") in new stack
-- User entered nothing.
-- Executing [s@macro-test:3] Set("SIP/2190-240bad10", "NEWVAR=DAHDI") in new stack
-- Executing [s@macro-test:4] GotoIf("SIP/2190-240bad10", "1?dahdi") in new stack
-- Goto (macro-test,s,6)
-- Executing [s@macro-test:6] NoOp("SIP/2190-240bad10", "My phone state is currently UNKNOWN") in new stack
-- Executing [s@macro-test:7] NoOp("SIP/2190-240bad10", "0") in new stack
Comments:By: Tilghman Lesher (tilghman) 2009-05-29 15:47:48

1) ChanIsAvail returns a hangup causecode in AVAILSTATUS, not a device status code.  Since the channel is available, there is no cause for termination, hence 0.

2) DEVICE_STATE() only works with channels that support devicestate.  DAHDI channels do not support devicestate, as you can confirm with the following CLI command:  core show channeltypes.