arnonym / ha-plugins

Home-Assistant SIP Gateway
Apache License 2.0
171 stars 22 forks source link

Watchdog seems to work on ha-sip-next, but not on ha-sip #81

Closed catohagen closed 8 months ago

catohagen commented 8 months ago

I dont know if this should be reported as a bug, but with running ha-sip-next (slug 8cd50eef-ha-sip-next) and do a manual call from developer tools/services like this :

service: hassio.addon_stdin
data:
  addon: 8cd50eef_ha-sip-next
  input:
    command: dial
    number: sip:port_01@192.168.1.160:5060
    ring_timeout: 30
    sip_account: 1

it rings until timeout, but if I manually answer it after a few rings like this :

service: hassio.addon_stdin
data:
  addon: 8cd50eef_ha-sip-next
  input:
    command: answer
    number: sip:port_01@192.168.1.160:5060
    post_action: hangup

it stops ringing, but the addon resets itself, the log shows ha-sip-next just started. Here is the log i catched before it resets the addon :

| 01:32:48.928211 [1] Registering call with id sip:port_01@192.168.1.160:5060
| 01:32:48.928241 [ ] Add to state: sip:port_01@192.168.1.160:5060
| 01:32:48.934527 [1] Calling
| 01:32:48.994896 [1] Early
| 01:32:56.160646 [ ] Got "answer" command for sip:port_01@192.168.1.160:5060
| 01:32:56.160741 [1] Trigger answer of call (if not established already)
| 01:32:56.160763 [1] Call will be answered now.
01:32:56.160               call.cpp  pjsua_call_answer2(id, param.p_opt, prm.statusCode, param.p_reason, param.p_msg_data) error: Invalid operation (PJ_EINVALIDOP) (status=70013) [../src/pjsua2/call.cpp:723]
Traceback (most recent call last):
  File "/ha-sip/main.py", line 113, in <module>
    main()
  File "/ha-sip/main.py", line 108, in main
    c.handle_events()
  File "/ha-sip/call.py", line 149, in handle_events
    self.answer(call_prm)
  File "/root/.local/lib/python3.11/site-packages/pjsua2-2.14-py3.11-linux-x86_64.egg/pjsua2.py", line 5848, in answer
    return _pjsua2.Call_answer(self, prm)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pjsua2.Error
s6-rc: info: service legacy-services: stopping
s6-rc: info: service legacy-services successfully stopped
s6-rc: info: service legacy-cont-init: stopping
s6-rc: info: service legacy-cont-init successfully stopped
s6-rc: info: service fix-attrs: stopping
s6-rc: info: service fix-attrs successfully stopped
s6-rc: info: service s6rc-oneshot-runner: stopping
s6-rc: info: service s6rc-oneshot-runner successfully stopped

I was trying to stop a ringing phone, as with the current bridging I do between two analog phones, if calling a phone and then just hang up, the target phone will just keep ringing until timeout...I wanted to stop the ringing, and that do happen now. I trigger the 'answer' command in the 'call_disconnected:' webhook

Very happy how things work now, but maybe there is a bug going on here since the addon restarts itself...

catohagen commented 8 months ago

I think I might found a workaround....as after a crash, sometimes its restarting and sometimes not... so I found that every addon have a binary sensor to tell if its running or not. It needs to be enabled manually

In Settings -> Devices & Services -> Devices (tab) ..search 'ha-sip' or ha-sip-next and click on it Under sensors there are +5 entities not shown, enable binary_sensor.ha_sip_running or binary_sensor.ha_sip_next_running

Now I can have an automation, that triggers on {{ states('binary_sensor.ha_sip_next_running') == 'off' }} and executes

service: hassio.addon_restart
data:
  addon: 8cd50eef_ha-sip-next
arnonym commented 8 months ago

Nice workaround! I really wonder what's going on here, because both versions are exactly the same, except the name. And if this sensor is able to identify a not working ha-sip, why doesn't the watchdog restart the add-on? I see nothing I can do here, except hoping that pjsip gets more stable or I find a bug in my code.