Go Down

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

berndq

Apr 18, 2014, 07:21 pm Last Edit: Feb 05, 2015, 08:04 pm by berndq
I just managed to hack some code which makes my arduino connect to a SIP server (Fritzbox) and send SIP REGISTER/INVITE to let phones ring. Now working on CANCEL to stop the ringing ;-)

That's all I need, I guess audio would be too much for an arduino. If someone is interested in the code, let me know...

-edit-
Latest code version at the end of the thread.

djb_rh

I'm interested.  My plan to do the same was to just hack up some worthless SIP phones I have laying around to trigger the redial button using an Arduino output.  That's still probably cheaper than adding a network interface to the Arduino, but it's less than elegant.

--Donnie

berndq

Here is my current working code. It can now connect with UDP or TCP to the SIP server and let phones ring. But there are still issues:

  • CANCEL to stop the ringing does not work. It is rejected by my SIP server with a leg/transaction does not exist error, however I could not yet spot my faulty parameters.

  • Currently the code uses an incorrectly (to my current knowlegde) formated Via, otherwise the phone will not ring.

  • Using UDP gives lots of unathorized and declined messages from the SIP server, but the phone rings nevertheless.



To stop the ringing you have to reject the call from the called phone or wait for some timeout.

I have a network capture of a UDP session with a working cancel, but this is quite complicated, I will try to implement this on my arduino as soon as I find some time. If I have working code, I could then strip it down to what is really required.

A mega is required because of code size.

These libraries are required:

See the first line of setup() to configure SIP server IP and port, SIP user, SIP pwd and the phone nr. to dial.

hugo007

Hello friends.
About a year ago I had been playing the asterisk and arduino.I haven't looked to your code but it is very simple interface the asterisk with the arduino and a ethernet shield.Imagination is your limit.
Here is all the info very well explained.
http://www.nerdybynature.com/category/asterisk/

Debian,Mint,Ubuntu
Arduino Mega 2560
Arduino Nano
Arduino Duemilanove
MAC OS Montain Lion
Raspberry PI Model B

berndq

Hi HugoPT,

thanks for the link! Unfortunately I have neither astersik not a web server available. The SIP server is the AVM FritzBox (a DSL router with SIP functionality). My goal is to make the arduino talk SIP directly to the SIP server.

Bernd

berndq

#5
Apr 26, 2014, 09:57 pm Last Edit: Feb 05, 2015, 08:07 pm by berndq
Got it working now.

Attached is code that can dial a tel. nr., the called phone rings and after 10 secs. the call is canceled.

What is still missing:
  • Error handling
  • Refactoring into some reusable code/lib
  • The SIP Via header needs to be constructed with a syntax error, otherwise it does not work. I have currently no idea what the problem is.


See setup() for configuration.


edit
Latest code version at the end of the thread

EricExperiment



http://www.nerdybynature.com/category/asterisk/



Interesting idea berndq.  I think for the sake of being able to reproduce something similar, I actually like HugoPT's idea of a generic Asterisk server.  I'm not sure what the AVM FritzBox is, but it seems like a difficult to find piece of kit.  However, a normal Asterisk server running on a RPi is something anyone can reproduce (google Incredible PBX).

Hugo, what were you running your Asterisk server on?

berndq

The FritzBox is a multi-purpose DSL router made by AVM and is very popular in and around Germany. (http://www.avm.de/en/Produkte/FRITZBox/index.html). It has built in PBX/DECT/SIP functionality. From a SIP point of view, the code should work with any SIP server, not just the FritBox.

berndq

#8
Jun 19, 2014, 08:22 pm Last Edit: Feb 05, 2015, 08:06 pm by berndq
Latest code version, refactored to an arduino library.

edit
Latest code version at the end of the thread

nothinghere

I am very much interested, but I cannot seem to find any code attached to your last post...?

berndq

It is the post dated Jun 19, 2014. There is a paperclip and next to it the filename "sip.zip". Klick on the file  name to download.

teddybt

#11
Jan 16, 2015, 02:28 pm Last Edit: Jan 17, 2015, 09:13 pm by teddybt
Hi,

I used you SIP Ringer to ring a Phone when a button is pressed. But sadly this only works once.

Code: [Select]

void loop() {


  // update() must be called regularyly to actively maintain the calls progress.
  sipRinger.update();
  buttonState = digitalRead(buttonPin);
  if (buttonState == LOW) {
      sipRinger.ring();
   
  }
 
}


Edit: It works when the call is not answered
Edit2: never mind, I fixed it myself

berndq

Would you mind to share your fix?

teddybt

Sure,
in the SIPRinger.cpp I added the recognition of an answered call, to stop the tcpClient and set the status to SIP_STATE_DONE:

Code: [Select]


        else if(m_state==SIP_STATE_TRYING){
          if((strstr(m_recBuf, "SIP/2.0 486 Busy Here")!=NULL)||(strstr(m_recBuf, "SIP/2.0 603 Decline")!=NULL)){
            m_state=SIP_STATE_READ_ENTIRE_REPLY_THEN_DISCONNECT;
#ifdef SIP_LOG_STATUS
            Serial.print(F("Call failed: "));
            Serial.println(m_recBuf);
#endif
          }
  if((strstr(m_recBuf, "SIP/2.0 200 OK")!=NULL)){
#ifdef SIP_LOG_STATUS
            Serial.print(F("Call answered?: "));
#endif  
if(strstr(m_recBuf, "Content-Length: 0")!=NULL){  
#ifdef SIP_LOG_STATUS           
            Serial.println(m_recBuf);
#endif  
}

if(m_useTcp==true){
m_tcpClient.stop();
}
m_state=SIP_STATE_DONE;
#ifdef SIP_LOG_STATUS           
Serial.print(F("Done. free RAM="));
Serial.println(freeRam());
Serial.flush();
#endif           
  }         
        }


berndq

Thanks teddybt,

I integrated your fix. Attached is the latest code which has also a memory leak fixed.

Go Up