tayler6000 / pyVoIP

Pure python VoIP/SIP/RTP library. Currently supports PCMA, PCMU, and telephone-event
https://pypi.org/project/pyVoIP/
GNU General Public License v3.0
226 stars 98 forks source link

phone.call() function does't work on Fritz!Box #167

Open mattiarainieri opened 1 year ago

mattiarainieri commented 1 year ago

Good Morining, I'm trying to use this library to make a voip call, but when i pass a phone number to the .call() function, nothing happen. Checking the returning call object, the status is "CallState.DIALING". Searching it in call log, there is nothing about it. Event in the modem log isn't reported any issues.

Here's a small snippet of the code

phone = VoIPPhone("fritz.box", 5060, "myusername","mypassword", myIP="192.168.1.20", callCallback=answer)
    phone.start()
    call = phone.call('+39myphonenumber')
    while call.state != CallState.ANSWERED:
        time.sleep(1)
        print(call.state)
    answer(call)
    input('Press enter to disable the phone')
    phone.stop()

I thank anyone for the help

chris-heo commented 1 year ago

I can reproduce this issue, so I did. :)

This was done with an isolated test setup:

Phone 1: MicroSip on a windows machine (internal phone number **620). IP config:

   Verbindungsspezifisches DNS-Suffix: fritz.box
   Verbindungslokale IPv6-Adresse  . : <removed>
   IPv4-Adresse  . . . . . . . . . . : 192.168.178.20
   Subnetzmaske  . . . . . . . . . . : 255.255.255.0
   Standardgateway . . . . . . . . . : 192.168.178.1

Phone 2: pyVoIP on a linux machine running dietpi (internal phone number **621) ip a:

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether <removed> brd ff:ff:ff:ff:ff:ff
    inet 192.168.178.21/24 brd 192.168.178.255 scope global dynamic eth0
       valid_lft 863349sec preferred_lft 863349sec
    inet6 <removed>/64 scope link
       valid_lft forever preferred_lft forever

Python:

Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux

pyVoIP should be v1.6.5 (need to finally confirm)

Running inbound.py works perfectly fine. If I call **621 from my windows machine, I can hear the message. (feel free to extract it from the tcpdump capture and see what I want do do ;))

Running outbound.py though, no ringer - it stays in dialing state according to the prints:

root@DietPi:~/voip# python3 outbound.py
CallState.DIALING
CallState.DIALING
CallState.DIALING
CallState.DIALING
CallState.DIALING
...

I'm not too deep into SIP (yet), IIRC the firstly rejected REGISTER and INVITE should be fine. For the contents - I can't tell anymore :(

In the attached zip file, please find both the test scripts I've used as well as the corresponding tcpdump captures.

Hope this helps for investigations. If you need any further information/testing, let me know.

calltests.zip

FrankMeyerEDV commented 1 year ago

Same problem here, incoming call works with:

we tested:

Who is using outgoing calls successfully? who got rid of the noises?

thanks, Frank

jchatin commented 12 months ago

Hi Frank,

I make outgoing calls successfully but I had to change the code to support SIP Proxy. I will fork the project and provide the code. I also use IVR function with a voice message generated with text 2 speech and it's working.

Only issue is the sound that is scratching, I think that this issue is in the RTP implementation.

FrankMeyerEDV commented 12 months ago

Hi jchatin,

we switched to Asterisk (from FreePBX), now we can make outgoing calls and we can forward calls. Im not sure, but I think the scratching comes from the codec. We tested converting glass clear sound files so 8000 KhZ, 8 Bit, Mono and never got rid of the scratching, even if we played it on PC without pyVoid. Maybe changing to newer Codec would help? but how? G726 or G729

obrain17 commented 9 months ago

Hi all, I also have tried to use phone.call() with my Fritz!Box and was getting the same behaviour and Wireshark logs as mentioned above.

The issue is that authorization has to be different for Register and Invite. I changed the code on the respective positions and now it is working. I also added some handling for busy and decline so both will trigger a CallState.ENDED The changed SIP.py file is attached: SIP.zip

I only tested outgoing and only with my Fritzbox here, nor did I try any audio and codecs. Maybe you can check if it still works with your other Easybell, Auerswald etc. and give me feedback.

I then consider to make a pull-request later.

chris-heo commented 9 months ago

Thanks for the early Christmas present @obrain17! :)

Can confirm it working w/ my spare Fritz!Box 7390 (FRITZ!OS: 06.87). Some actions are still a bit flaky (sometimes silence or hangup on pyvoip-side doesn't reach far end) but this might as well be my code or setup.

Would deeply appreciate if you could create a pull-request.

Thanks again!

fex95 commented 9 months ago

I can confirm that it also works on my Fritzbox 7490 OS 7.57. Unfortunately, the recently released version of VoIP 1.6.6 breaks the compatibility. The last version with which I was able to test it successfully is 1.6.5-rc.1.

Many thanks to @obrain17 for investigating what is wrong and finding a solution.

I hope that the functionality will soon be included in the repo.

alpha14 commented 8 months ago

@jchatin could you publish your changes supporting a SIP proxy in a pull request or on your fork? Thank you !

mattiarainieri commented 7 months ago

@obrain17 I've replaced your SIP.py file in my pyVoIP 1.6.5 version directory but i'm still having a problem making a call. In detail when i use the .call() method FritzBox reports me this in logs: La telefonia via Internet è fallita. Causa: Not Acceptable Here (488) [3 messaggi da 20.02.24 10:35:44]

The Call states is DIALING, but i also receive this warning TODO: Add 500 Error on Receiving SIP Response

obrain17 commented 7 months ago

Probably the destination phone you are calling does not support the codec provided by the caller (see here or list of SIP codes). You might want to try and call another phone connected to your Fritz-Box and check if the error still exists.

If not, it is a problem with your Internet Provider and you might search for a solution in Google, Bing etc. eg. here Not Acceptable Here.

There also might be a resolution by changing some settings in the Fritz-box see here

TODO: Add 500 Error on Receiving SIP Response you can ignore. This is only because error 488 is not known and handled