Go Down

Topic: Let arduino ring phones via SIP (Read 11983 times) previous topic - next topic

Poej

Hi berndq,
I saw in your code that you deliberately disable the SD card (link to the further info is a dead one  :smiley-eek:
Is there a specific reason why you do this?
I would plan to use the SD card to store numbers to be dialed?
Thanks for ur feedback.

berndq

Hi Poej,

just tested the link: The arduino IDE (1.6.1) does not pass the entire link to the web browser -> "The requested topic does not exist.". Copy/pasting the text into the browser shows the discussion.

I experienced unstable arduino operations and the info from user SkullKill from Sun Oct 28, 2012 6:26 am solved my problem: "did some research, and found that if i am not using the SD card, i need to explicitly disable it"

qualidat

Thanks teddybt,

I integrated your fix. Attached is the latest code which has also a memory leak fixed.
Please re-check the source code, it cannot compiled with IDE 1.6.x :-((

Error: "unable to find a register to spill in class 'NO_REGS'"

derniwi

#18
Aug 20, 2017, 06:45 pm Last Edit: Aug 20, 2017, 07:22 pm by derniwi
Hi Bernd,

using the current Arduino IDE 1.8.3 I also get the NO_REGS error. Seems to be a problem with PSTR macro.

I try to use your script for as an additional door bell. If someone rings the door bell, the phones should also ring. Currenty I compile it with the IDE 1.5.8 which does not produce the error.

I also add a public function to SIPRinger.h:
  boolean isBusy();

And also to SIPRinger.cpp:
boolean SIPRinger::isBusy()
{
  if ((m_state == SIP_STATE_INIT) || (m_state == SIP_STATE_DONE))
  {
    return false;
  }
  else
  {
    return true;
  }
}

In the main sktech I call sipRinger.ring() only if the sipRinger.isBusy() returns false. So I do not get in trouble if the phones are still ringing while th next ring() method should be called.

Also I do not find a solution for handling if a call is answered. The method returns after the state has set to SIP_STATE_DONE, but the call is still active from my phone. So I think the method part
          else if ((strstr(m_recBuf, "SIP/2.0 200 OK") != NULL))
          {
            m_state = SIP_STATE_READ_ENTIRE_REPLY_THEN_DISCONNECT;
#ifdef SIP_LOG_STATUS
            Serial.print(F("Call answered: "));
            Serial.println(m_recBuf);
#endif
          }
should be extended to handle the call and send a hang up (BYE command?).

Do you have any hints?

Regards
Nils

berndq

#19
Aug 30, 2017, 07:14 pm Last Edit: Aug 30, 2017, 07:19 pm by berndq
If you search the web for the error message, this seems to be a gcc bug and it seems to be fixed in some arduino IDEs.  I have know idea what to do to solve this.

I have abandoned to project because for me it does not work reliably, I never found out why. So my plans are to move this to a more powerful platform where there is reliable SIP support.

I also have not looked inside the code for a long time, so regarding your questions: I thought the ring() can be called without the caller having to check for the internal state of the sipringer, but this seems not the case. Why not extend the ring() to check your busy method, so your main sketch does not have to?

In the beginning i did not expect someone to answer the phone so I did not test this scenario. IIRC I added this later, but I am not sure, there a sever versions in the topic thread, have you used the latest one?

edit: Handling of answered calls: see post #11,#12,#13

What I did to learn the SIP sequence is: install a network sniffer and some SIP client (there are free ones) and trace what they do when you place a call and try to mimic what you want the arduino to do and see what the sniffer catches.

hope this helps

br

netdream

#20
Dec 31, 2017, 09:04 am Last Edit: Dec 31, 2017, 09:25 am by netdream
Hello
I am using a cut down version of the sketch to test a connection to a sip server that I have downloaded for test purposes. I seem to have a problem with authentication with the server but I am not clear the reason why. I am using  a Mizu Sip server for testing with.

I have enclosed my sketch and some wireshark traces. When I have no authentication set at the server end I am able to make the called party sip phone ring but when I enable authentication I see an authentication failure.

Any help greatly appreciated.

Nds

netdream

Wireshark trace enclosed - They  will need to be renamed with the .pcapng extension

netdream

I can only seem to get the sip called party to ring if I use UDP and not TCP - If I use TCP I see the invit sent but I dont see a response from the server.

Thanks again

berndq

You may try to install a another SIP client and compare the wireshark logs.

netdream

I did take a wireshark of a working client connection to my test sip server and the flow is more in line with what I expected, in that I see as a first flow the sip registration being sent from the client.

I have enclosed a few screenshots of the flows I see with the working client and also the Arduino sipringer.

When I set TCP as true I see a preample of TCP traffic between the Arduino and sip server  but no sip registration request.

When I set TCP as false I see as the first data packet a sip invite but again no sip registration.

berndq - Would you be able to confirm that I should  see a sip registration request when using the sip ringer code.

In using the library I did need to modify it to allow for the use of an Ethernet shield 2, and I also modified the user credentials and IP.
I am an Arduino beginner and may have broken something in making those changes ?

netdream

I have been doing more traces and I see that I get a better result when I return back to the original sip.ino file enclosed at the start of this topic. When I use this sketch and using the enclosed sipdialer library I am able to see a registration requet hit the sever, but it fails to register.
I have enclosed the serial output below.


Configuring Ethernet using DHCP...
DHCP succesfull: IP=192.168.240.237.
connecting to SIP server...
UDP initialized
REGISTER sip:192.168.240.216 SIP/2.0
Call-ID: 82dbcb945be55064382340188c4e7f46@0:0:0:0:0:0:0:0
CSeq: 1 REGISTER
From: "320" <sip:320@192.168.240.216>;tag=12ee6250
To: "320" <sip:320@192.168.240.216>
Via: SIP/2.0/UDP 192.168.240.237:5060;branch=z9hG4bK-343035-2bf4386c05f7697fc0ae10dc75cd1b35
Content-Length: 0

Received UDP packet of size 343
<SIP/2.0 100 Trying
<Via: SIP/2.0/UDP 192.168.240.237:5060;branch=z9hG4bK-343035-2bf4386c05f7697fc0ae10dc75cd1b35
<From: "320" <sip:320@192.168.240.216>;tag=12ee6250
<To: "320" <sip:320@192.168.240.216>
<Call-ID: 82dbcb945be55064382340188c4e7f46@0:0:0:0:0:0:0:0
<CSeq: 1 REGISTER
<X-TType: pre
<Server: MizuVoIPServer 8.6
<Content-Length: 0
SIPSTATE=3
<
REGISTER sip:192.168.240.216 SIP/2.0
Call-ID: 82dbcb945be55064382340188c4e7f46@0:0:0:0:0:0:0:0
CSeq: 2 REGISTER
From: "320" <sip:320@192.168.240.216>;tag=12ee6250
To: "320" <sip:320@192.168.240.216>
Via: SIP/2.0/UDP 192.168.240.237:5060;branch=z9hG4bK-343035-2bf4386c05f7697fc0ae10dc75cd1b35
Authorization: Digest username="320", realm="", nonce="", uri="sip:192.168.240.216", response=""
Content-Length: 0

Received UDP packet of size 343
<SIP/2.0 100 Trying
<Via: SIP/2.0/UDP 192.168.240.237:5060;branch=z9hG4bK-343035-2bf4386c05f7697fc0ae10dc75cd1b35
<From: "320" <sip:320@192.168.240.216>;tag=12ee6250
<To: "320" <sip:320@192.168.240.216>
<Call-ID: 82dbcb945be55064382340188c4e7f46@0:0:0:0:0:0:0:0
<CSeq: 2 REGISTER
<X-TType: pre
<Server: MizuVoIPServer 8.6
<Content-Length: 0
<
INVITE sip:321@192.168.240.216 SIP/2.0
Call-ID: 83bf5da9b2a6ec37a7615c7ccbc5d52c@0:0:0:0:0:0:0:0
CSeq: 1 INVITE
From: "320" <sip:320@192.168.240.216>;tag=6b454ff0
To: <sip:321@192.168.240.216>
Max-Forwards: 70
Via: SIP/2.0/UDP 192.168.240.237:5060branch=z9hG4bK-343035-f500251c6a8d2b02e9ec003be80d0c64
Contact: <sip:320@192.168.240.216>
User-Agent: arduino
Content-Type: application/sdp
Content-Length: 0

Received UDP packet of size 334
<SIP/2.0 100 Trying
<Via: SIP/2.0/UDP 192.168.240.237:5060branch=z9hG4bK-343035-f500251c6a8d2b02e9ec003be80d0c64
<From: "320" <sip:320@192.168.240.216>;tag=6b454ff0
<To: <sip:321@192.168.240.216>
<Call-ID: 83bf5da9b2a6ec37a7615c7ccbc5d52c@0:0:0:0:0:0:0:0
<CSeq: 1 INVITE
<X-TType: pre
<Server: MizuVoIPServer 8.6
<Content-Length: 0
SIPSTATE=7
<
INVITE sip:321@192.168.240.216 SIP/2.0
Call-ID: 83bf5da9b2a6ec37a7615c7ccbc5d52c@0:0:0:0:0:0:0:0
CSeq: 2 INVITE
From: "320" <sip:320@192.168.240.216>;tag=6b454ff0
To: <sip:321@192.168.240.216>
Max-Forwards: 70
Via: SIP/2.0/UDP 192.168.240.237:5060branch=z9hG4bK-343035-f500251c6a8d2b02e9ec003be80d0c64
Contact: <sip:320@192.168.240.216>
User-Agent: arduino
Content-Type: application/sdp
Authorization: Digest username="320", realm="", nonce="", uri="sip:321@192.168.240.216", response=""
Content-Length: 0

Received UDP packet of size 581
<SIP/2.0 401 Unauthorized
<Via: SIP/2.0/UDP 192.168.240.237:5060;branch=z9hG4bK-343035-2bf4386c05f7697fc0ae10dc75cd1b35
<From: "320" <sip:320@192.168.240.216>;tag=12ee6250
<To: "320" <sip:320@192.168.240.216>;tag=a176950610817922
<Contact: <sip:320@192.168.240.216:5060>
<Call-ID: 82dbcb945be55064382340188c4e7f46@0:0:0:0:0:0:0:0
<CSeq: 2 REGISTER
<Warning: 399 192.168.240.237 "Digest authorization required"
<WWW-Authenticate: Digest realm="192.168.240.216", nonce="584345937901899755a192b168b240b237", stale=FALSE, algorithm=MD5
<Server: MizuVoIPServer 8.6
<Content-Length: 0
<
Received UDP packet of size 334
<SIP/2.0 100 Trying
RINGING...
<Via: SIP/2.0/UDP 192.168.240.237:5060branch=z9hG4bK-343035-f500251c6a8d2b02e9ec003be80d0c64
<From: "320" <sip:320@192.168.240.216>;tag=6b454ff0
<To: <sip:321@192.168.240.216>
<Call-ID: 83bf5da9b2a6ec37a7615c7ccbc5d52c@0:0:0:0:0:0:0:0
<CSeq: 2 INVITE
<X-TType: pre
<Server: MizuVoIPServer 8.6
<Content-Length: 0
<
1
Received UDP packet of size 572
<SIP/2.0 401 Unauthorized
<Via: SIP/2.0/UDP 192.168.240.237:5060branch=z9hG4bK-343035-f500251c6a8d2b02e9ec003be80d0c64
<From: "320" <sip:320@192.168.240.216>;tag=6b454ff0
<To: <sip:321@192.168.240.216>;tag=a110461303146793
<Contact: <sip:321@192.168.240.216:5060>
<Call-ID: 83bf5da9b2a6ec37a7615c7ccbc5d52c@0:0:0:0:0:0:0:0
<CSeq: 2 INVITE
<Warning: 399 192.168.240.237 "Digest authorization required"
<WWW-Authenticate: Digest realm="192.168.240.216", nonce="584350006581399754a192b168b240b237", stale=FALSE, algorithm=MD5
<Server: MizuVoIPServer 8.6
<Content-Length: 0
<
2
Received UDP packet of size 529
<SIP/2.0 407 Proxy Authentication Required
<Via: SIP/2.0/UDP 192.168.240.237:5060branch=z9hG4bK-343035-f500251c6a8d2b02e9ec003be80d0c64
<From: "320" <sip:320@192.168.240.216>;tag=6b454ff0
<To: <sip:321@192.168.240.216>;tag=a110461303146793
<Contact: <sip:321@192.168.240.216:5060>
<Call-ID: 83bf5da9b2a6ec37a7615c7ccbc5d52c@0:0:0:0:0:0:0:0
<CSeq: 2 INVITE
<Proxy-Authenticate: Digest realm="192.168.240.216", nonce="584350006581399754a192b168b240b237", stale=FALSE, algorithm=MD5
<Server: MizuVoIPServer 8.6
<Content-Length: 0
<
3
Received UDP packet of size 510
<SIP/2.0 401 Unauthorized
<Via: SIP/2.0/UDP 192.168.240.237:5060branch=z9hG4bK-343035-f500251c6a8d2b02e9ec003be80d0c64
<From: "320" <sip:320@192.168.240.216>;tag=6b454ff0
<To: <sip:321@192.168.240.216>;tag=a110461303146793
<Contact: <sip:321@192.168.240.216:5060>
<Call-ID: 83bf5da9b2a6ec37a7615c7ccbc5d52c@0:0:0:0:0:0:0:0
<CSeq: 2 INVITE
<WWW-Authenticate: Digest realm="192.168.240.216", nonce="584350006581399754a192b168b240b237", stale=FALSE, algorithm=MD5
<Server: MizuVoIPServer 8.6
<Content-Length: 0
<
4
5
6
7
8
9
10
11
12
13
14
15
CANCEL sip:321@192.168.240.216 SIP/2.0
Call-ID: 83bf5da9b2a6ec37a7615c7ccbc5d52c@0:0:0:0:0:0:0:0
CSeq: 2 CANCEL
From: "320" <sip:320@192.168.240.216>;tag=6b454ff0
To: <sip:321@192.168.240.216>
Via: SIP/2.0/UDP 192.168.240.237:5060;branch=z9hG4bK-343035-f500251c6a8d2b02e9ec003be80d0c64
Content-Length: 0

Received UDP packet of size 595
<SIP/2.0 200 Cancelling...
<Via: SIP/2.0/UDP 192.168.240.237:5060;branch=z9hG4bK-343035-f500251c6a8d2b02e9ec003be80d0c64
<From: "320" <sip:320@192.168.240.216>;tag=6b454ff0
<To: <sip:321@192.168.240.216>;tag=a110461303146793
<Contact: <sip:321@192.168.240.216:5060>
<Call-ID: 83bf5da9b2a6ec37a7615c7ccbc5d52c@0:0:0:0:0:0:0:0
<CSeq: 2 CANCEL
<Server: MizuVoIPServer 8.6
<Allow: ACK,BYE,CANCEL,INVITE,REGISTER,UPDATE,MESSAGE,INFO,OPTIONS,SUBSCRIBE,NOTIFY,REFER,COMET,PUBLISH,PING,DO
<Allow-Events: presence,refer,telephone-event,keep-alive,dialog
<Supported: privacy,replaces
<Content-Length: 0
<
Received UDP packet of size 454
<SIP/2.0 487 Request Terminated
<Via: SIP/2.0/UDP 192.168.240.237:5060;branch=z9hG4bK-343035-f500251c6a8d2b02e9ec003be80d0c64
<From: "320" <sip:320@192.168.240.216>;tag=6b454ff0
<To: <sip:321@192.168.240.216>;tag=a110461303146793
<Contact: <sip:321@192.168.240.216:5060>
<Call-ID: 83bf5da9b2a6ec37a7615c7ccbc5d52c@0:0:0:0:0:0:0:0
<CSeq: 2 INVITE
<Server: MizuVoIPServer 8.6
<Warning: 399 192.168.240.237 "Cancel received (0x15) (7)"
<Content-Length: 0
<



Should I not be sending something in the nonce field ?

netdream

So I think I understand the problem ??

I think when connecting to my test sip server the arduino sip client determines that it already has the nonce data header but infact it doesnt.

I can see the SIPSTATE = 3 from the serial monitor (as shown below ) - the second registration attempt sends no nonce data field either.

I assume that this is because the first packet sent back from my server is a SIP trying msg that holds no realm or nonce data. The nonce data is only returns when the sp 401 Unauthorized msg is sent from my server.

Does this make sense ?

Anyone able to explain how I can fix this ?


Configuring Ethernet using DHCP...
DHCP succesfull: IP=192.168.240.237.
connecting to SIP server...
UDP initialized
Server TCP Port Connected:
REGISTER sip:192.168.240.216 SIP/2.0
Call-ID: 82dbcb945be55064382340188c4e7f46@0:0:0:0:0:0:0:0
CSeq: 1 REGISTER
From: "320" <sip:320@192.168.240.216>;tag=12ee6250
To: "320" <sip:320@192.168.240.216>
Via: SIP/2.0/UDP 192.168.240.237:5060;branch=z9hG4bK-343035-2bf4386c05f7697fc0ae10dc75cd1b35
Content-Length: 0

Received UDP packet of size 343
<SIP/2.0 100 Trying
<Via: SIP/2.0/UDP 192.168.240.237:5060;branch=z9hG4bK-343035-2bf4386c05f7697fc0ae10dc75cd1b35
<From: "320" <sip:320@192.168.240.216>;tag=12ee6250
<To: "320" <sip:320@192.168.240.216>
<Call-ID: 82dbcb945be55064382340188c4e7f46@0:0:0:0:0:0:0:0
<CSeq: 1 REGISTER
<X-TType: pre
<Server: MizuVoIPServer 8.6
<Content-Length: 0
SIPSTATE=3
<
REGISTER sip:192.168.240.216 SIP/2.0
Call-ID: 82dbcb945be55064382340188c4e7f46@0:0:0:0:0:0:0:0
CSeq: 2 REGISTER
From: "320" <sip:320@192.168.240.216>;tag=12ee6250
To: "320" <sip:320@192.168.240.216>
Via: SIP/2.0/UDP 192.168.240.237:5060;branch=z9hG4bK-343035-2bf4386c05f7697fc0ae10dc75cd1b35
Authorization: Digest username="320", realm="", nonce="", uri="sip:192.168.240.216", response=""
Content-Length: 0

Received UDP packet of size 581
<SIP/2.0 401 Unauthorized
<Via: SIP/2.0/UDP 192.168.240.237:5060;branch=z9hG4bK-343035-2bf4386c05f7697fc0ae10dc75cd1b35
<From: "320" <sip:320@192.168.240.216>;tag=12ee6250
<To: "320" <sip:320@192.168.240.216>;tag=a117603458521452
<Contact: <sip:320@192.168.240.216:5060>
<Call-ID: 82dbcb945be55064382340188c4e7f46@0:0:0:0:0:0:0:0
<CSeq: 1 REGISTER
<Warning: 399 192.168.240.237 "Digest authorization required"
<WWW-Authenticate: Digest realm="192.168.240.216", nonce="640008593301799739a192b168b240b237", stale=FALSE, algorithm=MD5
<Server: MizuVoIPServer 8.6
<Content-Length: 0
<

netdream

And the library !

berndq

Hi,

I am not sure if SIP register is required or not. Maybe I find some time next week to implement it.

About to nonce calculations, this is specified here: https://en.wikipedia.org/wiki/Digest_access_authentication

netdream

Helllo berndq

Thanks for the reference reading - My head is busting with confusion ! I should stick to networking !

I believe the problem I see with the registration process is that the ardiuno never sends the nonce data that is has collected as part of the original sip registation request . The part of the code that I believe i should be looking at is below.

If I set the sipState=2 the arduino doesn't continue with the sip register request , nor do I see any futher data flow on the serial monitor, but I do see the correct nonce data being displayed.



  if(sipState==2){
         // unauthorized register reply
         if(strstr(sipRecBuf, "WWW-Authenticate")!=NULL){
           parseParameter(nonce,"nonce=",sipRecBuf);
           parseParameter(realm,"realm=",sipRecBuf);

           compute_response(nonce, sipUser, realm, sipPwd, "REGISTER", sipUri);
         }
         else if(strstr(sipRecBuf, "Content-Length: 0")!=NULL){
                       sipState=2;
          //CHANGIN FROM ORIGINAL  value SipState=3 to SipState=2 causes the sketch to stop but shows nonce data
           
           Serial.print("SipState=");
           Serial.println(sipState);
//sipState=3;
         //LEAVE SIP STATE AS 2 to show nonce data  
         }
           
       }      


==

Serial Monitor Output below

>>>

Configuring Ethernet using DHCP...
5c39640df
<Server: MizuVoIPServer 8.6
<Content-Length: 0
SipState=2
<
f0682c0cf1ea3b475036a62
RESP=3408b9fbf49d40f3c75500e5c39640df
<Server: MizuVoIPServer 8.6
<Content-Length: 0
SipState=2
<
f0682c0cf1ea3b475036a62
RESP=3408b9fbf49d40f3c75500e5c39640df
<Server: MizuVoIPServer 8.6
<Content-Length: 0
SipState=2
<
Configuring Ethernet using DHCP...
DHCP succesfull: IP=192.168.240.237.
connecting to SIP server...
UDP initialized
Server TCP Port Connected:
Current sipState is :
1
REGISTER sip:192.168.240.216 SIP/2.0
Call-ID: 82dbcb945be55064382340188c4e7f46@0:0:0:0:0:0:0:0
CSeq: 1 REGISTER
From: "locext320" <sip:locext320@192.168.240.216>;tag=12ee6250
To: "locext320" <sip:locext320@192.168.240.216>
Via: SIP/2.0/UDP 192.168.240.237:5060;branch=z9hG4bK-343035-2bf4386c05f7697fc0ae10dc75cd1b35
Content-Length: 0

Received UDP packet of size 367
<SIP/2.0 100 Trying
<Via: SIP/2.0/UDP 192.168.240.237:5060;branch=z9hG4bK-343035-2bf4386c05f7697fc0ae10dc75cd1b35
<From: "locext320" <sip:locext320@192.168.240.216>;tag=12ee6250
<To: "locext320" <sip:locext320@192.168.240.216>
<Call-ID: 82dbcb945be55064382340188c4e7f46@0:0:0:0:0:0:0:0
<CSeq: 1 REGISTER
<X-TType: pre
<Server: MizuVoIPServer 8.6
<Content-Length: 0
SipState=2
<
Received UDP packet of size 610
<SIP/2.0 401 Unauthorized
<Via: SIP/2.0/UDP 192.168.240.237:5060;branch=z9hG4bK-343035-2bf4386c05f7697fc0ae10dc75cd1b35
<From: "locext320" <sip:locext320@192.168.240.216>;tag=12ee6250
<To: "locext320" <sip:locext320@192.168.240.216>;tag=a110576230797747
<Contact: <sip:locext320@192.168.240.216:5060>
<Call-ID: 82dbcb945be55064382340188c4e7f46@0:0:0:0:0:0:0:0
<CSeq: 1 REGISTER
<Warning: 399 192.168.240.237 "Digest authorization required"
<WWW-Authenticate: Digest realm="192.168.240.216", nonce="16693062815099760a192b168b240b237", stale=FALSE, algorithm=MD5
##nonce=16693062815099760a192b168b240b237
##realm=192.168.240.216
locext320:192.168.240.216:secret
HA1:adeec2257faa2210eeed93e8cb0d43a8
REGISTER:sip:192.168.240.216
HA2:a9e2e5a4af0682c0cf1ea3b475036a62
RESPSEED=adeec2257faa2210eeed93e8cb0d43a8:16693062815099760a192b168b240b237:a9e2e5a4af0682c0cf1ea3b475036a62
RESP=3408b9fbf49d40f3c75500e5c39640df
<Server: MizuVoIPServer 8.6
<Content-Length: 0
SipState=2
<



==

If I leave the code with SipState=3 - I see two sip registration attempts and neither  showing nonce data. The sketch then continues on to send a SIP Invite.


So my question is
Why does the sipState get set to '3' and then no sip registration sent with nonce data ?

I don't really understand where in the code SipState is determining a value of 3....

Thanks for the support

nds

Go Up