Asterisk + Cisco SPA5XX, SPA3XX - DND with server notification

Recently, the company changed IP-phones. Cisco SPA504G and cisco SPA303 came to replace gigasets . I am not a specialist in telephony, so the dnd (Do not Disturb) mode was new to me. The novelty quickly took root in the company. But here's the problem: when switching modes, the phone does not notify the server in any way. A call to an inaccessible phone ended with a busy status. The caller had only to guess whether the subscriber was talking on the phone right now or if he wasn’t there. I decided to fix this problem.

There is already a similar post on the hub , but it does not take into account the features of the cisco phone. In order for the server to be able to check the activity of dnd on the phone, I used the work of the user muon. Add the following content to the dialplan (do not forget to include this content where necessary):

[dnd_on-off]
exten => *75,1,Answer
exten => *75,n,Set(STATE=RINGING)
exten => *75,n,Set(DEVICE_STATE(Custom:DND${CALLERID(number)})=${STATE})
exten => *75,n,Hangup
exten => *76,1,Answer
exten => *76,n,Set(STATE=NOT_INUSE)
exten => *76,n,Set(DEVICE_STATE(Custom:DND${CALLERID(number)})=${STATE})
exten => *76,n,Hangup

To set the phone (on the server) in dnd mode, dial * 76 to remove * 75 . Thus, checking the value of the variable on the server, ${DEVICE_STATE(Custom:DND<Номер абонента>)}we will know what state the phone is in.

At this stage, it is not very convenient, because we do not have any indication on the phone ( problem 1 ). And also the user’s perplexity: “I used to set and remove dnd mode with the click of a button, but now I need to type some strange combinations.” ( Problem 2 ). We proceed further.

Solution 1:
In the phone’s web admin area, in Admin login, Advanced mode , on the Regional tab, there is a section Vertical Service Activation Codes. We find the DND Act Code and DND Deact Code parameters , set the values * 76 and * 75, respectively. Now when you dial these service codes on the phone, dnd mode will be turned on and off (on the phone). But bad luck, the phone again does not notify the server.

To solve this problem, you need to make the phone dial these codes. We are looking for the Vertical Service Announcement Codes section. We find the Service Annc Base Number parameter , write * 7 (this is the prefix of the number that the phone will call when dialing any service code), the Service Annc Extension Codes parameter : DDT: 6; DDF: 5 (this is the number suffix, depending on the operation,DDT- installation of dnd, DDF- removal of dnd). Next, go to the Phone tab and in the Supplementary Services section, set the Service Annc Serv parameter to yes . Thanks to this parameter, the phone will now dial the number by suffix and prefix as we indicated. Hooray, problem 1 solved.

Solution 2 :
The phone has the ability to reassign buttons, use this. Here I had to complicate the process of removing and setting dnd a bit. Previously, this was done by pressing one button, now one button will be responsible for the installation, another for removal. I could not solve this problem, although here(last post) they write that it is possible to assign two actions alternately to one programmable key, but it didn’t work for me. Who knows how to do this, write in the comments, I will be grateful.

On the Phone tab , in the Programmable Softkeys section, create two programmable buttons.
PKS1 : fnc = sd; ext = * 75; nme = dnd
PKS2 : fnc = sd; ext = * 76; nme = -dnd
I assigned the former dnd button PKS2(removing dnd), and the one to the left of it (I don’t remember what for the function was on it, still no one used it) PKS1. To do this, in the Idle Key List parameter write psk1 | 7; psk2 | 8;to the appropriate place. Remember to enable the programmable keys, the Programmable Softkey Enable parameter , yes . Click Submit All Changes , wait until the phone reboots and you can use it.

I did not write a check for dnd with an incoming call in the dialplan - until my hands reached. In the above post from a habr it is already implemented. To indicate the status of phones, we use software on the computer based on AMI requests.

PS It
became immediately interesting who how many times a day puts this mode, for what time, etc. Maybe someone will be interested. In MySQL, for this purpose I created a table:

CREATE TABLE `dnd` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `number` varchar(3) NOT NULL,
  `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `action` tinyint(1) NOT NULL,
  PRIMARY KEY (`id`)
)

and changed the content

[dnd_on-off]
exten => *75,1,Answer
exten => *75,n,Set(STATE=RINGING)
exten => *75,n,Set(DEVICE_STATE(Custom:DND${CALLERID(number)})=${STATE})
exten => *75,n,MYSQL(Connect connid localhost user password database)
exten => *75,n,MYSQL(Query resultid ${connid} INSERT INTO dnd (number, action) VALUES ("${CALLERID(number)}", false))
exten => *75,n,MYSQL(Disconnect ${connid})
exten => *75,n,Hangup
exten => *76,1,Answer
exten => *76,n,Set(STATE=NOT_INUSE)
exten => *76,n,Set(DEVICE_STATE(Custom:DND${CALLERID(number)})=${STATE})
exten => *76,n,MYSQL(Connect connid localhost user password database)
exten => *76,n,MYSQL(Query resultid ${connid} INSERT INTO dnd (number, action) VALUES ("${CALLERID(number)}", true))
exten => *76,n,MYSQL(Disconnect ${connid})
exten => *76,n,Hangup


That's all, thanks for your attention.

UPD

It turned out to do everything on one button, for this it was necessary to update the firmware to version 7.5.5.
PKS1 : fnc = sd; ext = * 75; nme = dnd; ext2 = * 76; nme2 = -dnd

True, there is an annoying trifle. If you put the phone on dnd and reboot, then the button is in state 1 (put dnd), although dnd is already on.

Also popular now: