Search code examples
raspberry-pisipvoippjsippjsua2

Pjsip/pjsua timeout errors and resolve errors calling phone numbers after registering with voip.ms from Raspberry Pi


The Goal

I'm trying to make a call to a telephone number. I'd like to be able to make a call from the raspberry pi, and also make a call to my voip.ms phone number and be able to answer or auto-answer and play some generic .wav file.

My current understanding of things

This maybe should be titled "My current misunderstanding of things". I'm new to sip and pjsip, and I think I must be missing some part of the process I don't understand. I was under the impression that, if I register with voip.ms, when I make a call it would route to voip.ms and they would do a lookup on the number/address, and then respond with an address that I would then begin to communicate with.

What I've done so far

Compiled

I've compiled Pjsip on a Raspberry Pi 3B+ properly, for what I can tell. I can include pjsua2.hpp in my c++ applications. I've roughly followed this tutorial

Tested compilation with pjsua binary && demo.cpp

I'm running into identical problems running a modified pjsua2_demo.cpp and the binary included in the pjsip build. For the sake of simplicity, I'll ask about the binary located (for me) at <project-path>/pjproject-2.8/pjsip-apps/bin/pjsua-armv7l-unknown-linux-gnueabihf.

Successfully registered with voip.ms

I have an account and phone number with Voip.ms and can become registered with voip.ms by executing the following script:

call_and_auto_answer.sh

./pjsua2-cpp/pjproject-2.8/pjsip-apps/bin/pjsua-armv7l-unknown-linux-gnueabihf \
    --play-file ~/CantinaBand60.wav \
    --local-port=5060 \
    --auto-answer 200 \
    --auto-play \
    --auto-loop \
    --max-calls 5 \
    --config-file ./sip.cfg

Where the config looks like:

sip.cfg

#
# Logging options:
#
--log-level 5
--app-log-level 4

#
# Account 0:
#
--id sip:<my-subaccount-username>@sip.voip.ms
--registrar sip:<server-location>.voip.ms
--reg-timeout 300
--realm *
--username <my-subaccount-username>
--password <my-subaccount-password>
--use-timer 1

#
# Network settings:
#
--local-port 5060

#
# Media settings:
#
--srtp-keying 0
--auto-play
--auto-loop
--play-file /home/pi/CantinaBand60.wav
--snd-auto-close 1
#using default --clock-rate 16000
#using default --quality 8
#using default --ec-tail 200
#using default --ilbc-mode 30
--rtp-port 4000

#
# User agent:
#
--auto-answer 200
--max-calls 5

#
# SIP extensions:
#
--use-timer 1

When I enter the cli, I see for my account list:

Account list:
  [ 0] <sip:192.168.1.49:5060>: does not register
       Online status: Online
  [ 1] <sip:192.168.1.49:5060;transport=TCP>: does not register
       Online status: Online
 *[ 2] sip:<my-subaccount-username>@sip.voip.ms: 200/OK (expires=285)
       Online status: Online
Buddy list:
 -none-

Voip.ms shows I've registered on their website.

The problem

I'm trying to call my personal cell phone from my pi (I assume using the registered voip.ms phone number), and call my pi from my personal cell phone. While calling out I'm typically getting either 408 Request Timeout errors or 502 gethostbyname errors.

Different destinations, different errors

Depending on the destination for my call from the pi, I get one of two different errors most of the time

Timeout Error

I get an error that says,

18:19:19.757    pjsua_app.c  ....Call 4 is DISCONNECTED [reason=408 (Request Timeout)]
18:19:19.757 pjsua_app_comm  ....
  [DISCONNCTD] To: <destination-sip-address>

where is any of the following:

  • sip:
  • sip:
  • sip:thetestcall@sip2sip.info
  • sip:thetestcall@iptel.org sip:201@ideasip.com

and the phone numbers are formatted like: 3035551234, though I've tried prepending a 1 and a +1 just to check.

Lookup Error

I get an error that says,

19:09:45.435  sip_resolve.c  ....Failed to resolve '<destination-sip-address>'. Err=70018 (gethostbyname() has returned error (PJ_ERESOLVE))
19:09:45.435   tsx0x18520dc  ....Failed to send Request msg INVITE/cseq=10722 (tdta0x185012c)! err=70018 (gethostbyname() has returned error (PJ_ERESOLVE))
19:09:45.435    pjsua_app.c  .......Call 4 is DISCONNECTED [reason=502 (gethostbyname() has returned error (PJ_ERESOLVE))]
19:09:45.435 pjsua_app_comm  .......
  [DISCONNCTD] To: sip:<destination-sip-address>

where is any of the following:

  • sip:
  • sip:
  • sip:abcd1234

Possible Successes

I'm getting what looks like a success while calling:

  • sip:**12340@ideasip.com

It confirms the call and has a bunch of messages, notable including:

19:16:17.550   pjsua_core.c  ....TX 1300 bytes Request msg INVITE/cseq=13899 (tdta0x15c263c) to UDP 208.97.25.11:5060:
...
19:16:17.551    pjsua_app.c  .......Call 4 state changed to CALLING
...
>>> 19:16:17.606   pjsua_core.c  .RX 575 bytes Response msg 100/INVITE/cseq=13899 (rdata0x6d7008a4) from UDP 208.97.25.11:5060:
...
19:16:17.609   pjsua_core.c  .RX 946 bytes Response msg 200/INVITE/cseq=13899 (rdata0x6d7008a4) from UDP 208.97.25.11:5060:
...
19:16:17.609    pjsua_app.c  .....Call 4 state changed to CONNECTING
...
19:16:17.610    pjsua_app.c  .....Call 4 state changed to CONFIRMED
...
19:16:17.676   pjsua_core.c  .RX 594 bytes Response msg 100/INVITE/cseq=13900 (rdata0x6d7008a4) from UDP 208.97.25.11:5060:
...
19:16:17.678   conference.c  ......Port 5 (sip:**12340@ideasip.com) transmitting to port 5 (sip:**12340@ideasip.com)
...
19:16:17.678   conference.c  ......Port 1 (/home/pi/CantinaBand60.wav) transmitting to port 5 (sip:**12340@ideasip.com)
...
19:16:36.931    pjsua_app.c  ......Call 4 is DISCONNECTED [reason=200 (Normal call clearing)]

Same Network

Additionally, if I set up a second pjsip client on the same network, I can call it from pi1 and answer the call on pi2.

Incoming calls

When I register with voip.ms, then try to call my voip.ms phone number from my personal cell phone, the call fails with a message on my iPhone that says, User Busy. This makes me think I'm messing something up with the registration, or that I'm missing some component, like a subscribe or link with that voip.ms account.

Final thoughts

I'm not sure what I'm missing here. I've read through a ton of the pjsip and pjsua docs, and I can't find anything I'm missing. Does anybody have insight into how to make a call to a phone number and allow for incoming calls? This has been quite a few days of solid work.


Solution

  • So I figured out the answer to my question. Here's the skinny:

    Voip.ms registration

    My registration with voip.ms wasn't configured properly. I was given credentials by a coworker, but upon further inspection of the sip endpoint, I found that the DiD number purchased for the account wasn't associated with the subaccount my coworker created for me. So, depending on the recipient's phone carrier, I was given different errors. Additionally, when I was testing inbound calls and receiving the error, User Busy, this was because the account I registered wasn't associated with the phone number.

    To fix this, on voip.ms I associated the DiD number to my subaccount, and then went to my subaccount information and set the callerId number to be my DiD number, though I think you can override this value via pjsip.

    Outbound sip calls

    Secondly, to call a phone number, outbound calls should follow the following format:

    sip:<phoneNumber>@<endpoint>

    So for me, this looked very much like:

    sip:5551234567@newyork.voip.ms