title: Pjsip/pjsua timeout errors and resolve errors calling phone numbers after registering with voip.ms from Raspberry Pi
body: <h1>The Goal</h1>
  
  <p>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.</p>
  
  <h3>My current understanding of things</h3>
  
  <p>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.</p>
  
  <h1>What I've done so far</h1>
  
  <h3>Compiled</h3>
  
  <p>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 <a href="https://blog.wirelessmoves.com/2017/03/the-raspberry-pi-as-a-sip-client-with-pjsip.html" rel="nofollow noreferrer">this tutorial</a></p>
  
  <h3>Tested compilation with pjsua binary && demo.cpp</h3>
  
  <p>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 <code>&lt;project-path&gt;/pjproject-2.8/pjsip-apps/bin/pjsua-armv7l-unknown-linux-gnueabihf</code>.</p>
  
  <h3>Successfully registered with voip.ms</h3>
  
  <p>I have an account and phone number with Voip.ms and can become registered with voip.ms by executing the following script:</p>
  
  <p><strong>call_and_auto_answer.sh</strong></p>
  
  <pre><code>./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
  </code></pre>
  
  <p>Where the config looks like:</p>
  
  <p><strong>sip.cfg</strong></p>
  
  <pre><code>#
  # Logging options:
  #
  --log-level 5
  --app-log-level 4
  
  #
  # Account 0:
  #
  --id sip:&lt;my-subaccount-username&gt;@sip.voip.ms
  --registrar sip:&lt;server-location&gt;.voip.ms
  --reg-timeout 300
  --realm *
  --username &lt;my-subaccount-username&gt;
  --password &lt;my-subaccount-password&gt;
  --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
  </code></pre>
  
  <p>When I enter the cli, I see for my account list:</p>
  
  <pre><code>Account list:
    [ 0] &lt;sip:192.168.1.49:5060&gt;: does not register
         Online status: Online
    [ 1] &lt;sip:192.168.1.49:5060;transport=TCP&gt;: does not register
         Online status: Online
   *[ 2] sip:&lt;my-subaccount-username&gt;@sip.voip.ms: 200/OK (expires=285)
         Online status: Online
  Buddy list:
   -none-
  </code></pre>
  
  <p>Voip.ms shows I've registered on their website.</p>
  
  <h1>The problem</h1>
  
  <p>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 <code>408 Request Timeout</code> errors or <code>502 gethostbyname</code> errors.</p>
  
  <h2>Different destinations, different errors</h2>
  
  <p>Depending on the destination for my call from the pi, I get one of two different errors most of the time</p>
  
  <h3>Timeout Error</h3>
  
  <p>I get an error that says,</p>
  
  <pre><code>18:19:19.757    pjsua_app.c  ....Call 4 is DISCONNECTED [reason=408 (Request Timeout)]
  18:19:19.757 pjsua_app_comm  ....
    [DISCONNCTD] To: &lt;destination-sip-address&gt;
  </code></pre>
  
  <p>where  is any of the following:</p>
  
  <ul>
  <li>sip:</li>
  <li>sip:</li>
  <li>sip:thetestcall@sip2sip.info</li>
  <li>sip:thetestcall@iptel.org
  sip:201@ideasip.com</li>
  </ul>
  
  <p>and the phone numbers are formatted like: <code>3035551234</code>, though I've tried prepending a <code>1</code> and a <code>+1</code> just to check. </p>
  
  <h3>Lookup Error</h3>
  
  <p>I get an error that says,</p>
  
  <pre><code>19:09:45.435  sip_resolve.c  ....Failed to resolve '&lt;destination-sip-address&gt;'. 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:&lt;destination-sip-address&gt;
  </code></pre>
  
  <p>where  is any of the following:</p>
  
  <ul>
  <li>sip:</li>
  <li>sip:</li>
  <li>sip:abcd1234</li>
  </ul>
  
  <h2>Possible Successes</h2>
  
  <p>I'm getting what looks like a success while calling:</p>
  
  <ul>
  <li>sip:**12340@ideasip.com</li>
  </ul>
  
  <p>It confirms the call and has a bunch of messages, notable including:</p>
  
  <pre><code>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
  ...
  &gt;&gt;&gt; 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)]
  </code></pre>
  
  <h3>Same Network</h3>
  
  <p>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.</p>
  
  <h2>Incoming calls</h2>
  
  <p>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, <code>User Busy</code>. 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.</p>
  
  <h2>Final thoughts</h2>
  
  <p>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.</p>